File Coverage

lib/Smartcat/App/Command/project.pm
Criterion Covered Total %
statement 33 50 66.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 7 8 87.5
pod 3 5 60.0
total 47 72 65.2


line stmt bran cond sub pod time code
1             # ABSTRACT: get project details
2 2     2   1002 use strict;
  2         4  
  2         52  
3 2     2   9 use warnings;
  2         3  
  2         68  
4              
5             package Smartcat::App::Command::project;
6 2     2   8 use Smartcat::App -command;
  2         4  
  2         10  
7              
8             sub opt_spec {
9 2     2 1 26191 my ($self) = @_;
10              
11 2         76 my @opts = $self->SUPER::opt_spec;
12 2         10 push @opts, $self->project_id_opt_spec, [ 'list' => 'Get all projects' ];
13              
14 2         15 return @opts;
15             }
16              
17             sub validate_args {
18 2     2 1 3253 my ( $self, $opt, $args ) = @_;
19              
20 2         22 $self->SUPER::validate_args( $opt, $args );
21             $self->usage_error(
22             "'--list' option cannot be used together with '--project-id'")
23 2 50 33     10273 if ( defined $opt->{list} && defined $opt->{project_id} );
24 2 50       22 $self->validate_project_id( $opt, $args ) unless defined $opt->{list};
25             }
26              
27             sub print_project_details {
28 2     2 0 6 my ( $self, $project ) = @_;
29              
30 2         8 print "Project:\n\t" . $project->name . "\n";
31 2         72 print "Id:\n\t" . $project->id . "\n";
32 2         38 print "Documents:\n";
33             print "\t"
34             . $_->name
35             . "\n\t\tid: $_->{id}\n\t\tstatus: "
36             . $_->status
37             . "\n\t\tlanguage: "
38             . $_->target_language . "\n"
39 2         21 for @{ $project->documents };
  2         6  
40 2         98 print "Target languages:\n";
41 2         21 print "\t" . join( ' ', @{ $project->target_languages } ) . "\n";
  2         7  
42 2         38 print "Status:\n\t" . $project->status . "\n";
43 2         34 print "-" x 80;
44 2         22 print "\n";
45             }
46              
47             sub print_project {
48 0     0 0 0 my ( $self, $project ) = @_;
49              
50 0         0 print "Project:\n\t" . $project->name . "\n";
51 0         0 print "Id:\n\t" . $project->id . "\n";
52 0         0 print "Number of documents:\n";
53 0         0 print "\t" . @{ $project->documents } . "\n";
  0         0  
54 0         0 print "Target languages:\n";
55 0         0 print "\t" . join( ' ', @{ $project->target_languages } ) . "\n";
  0         0  
56 0         0 print "Status:\n\t" . $project->status . "\n";
57 0         0 print "-" x 80;
58 0         0 print "\n";
59             }
60              
61             sub execute {
62 2     2 1 12 my ( $self, $opt, $args ) = @_;
63              
64 2         5 my $api = $self->app->project_api;
65 2 50       13 if ( defined $opt->{list} ) {
66 0         0 my $projects = $api->get_all_projects;
67 0         0 print "Total number of projects:\n\t" . @$projects . "\n";
68 0         0 print "-" x 80;
69 0         0 print "\n";
70 0         0 $self->print_project($_) for @$projects;
71             }
72             else {
73 2         14 $self->print_project_details( $api->get_project );
74             }
75             }
76              
77             1;