File Coverage

lib/Smartcat/App/Command.pm
Criterion Covered Total %
statement 32 44 72.7
branch 9 18 50.0
condition 3 9 33.3
subroutine 9 13 69.2
pod 2 8 25.0
total 55 92 59.7


line stmt bran cond sub pod time code
1 2     2   1339 use strict;
  2         4  
  2         59  
2 2     2   10 use warnings;
  2         3  
  2         174  
3              
4             package Smartcat::App::Command;
5 2     2   13 use App::Cmd::Setup -command;
  2         4  
  2         13  
6              
7 2     2   494 use Cwd qw(abs_path);
  2         4  
  2         111  
8 2     2   47 use File::Basename;
  2         5  
  2         1215  
9              
10             sub opt_spec {
11             return (
12             #[ 'config:s' => 'Config file path' ],
13 2     2 1 16 [ 'token-id:s' => 'Smartcat account id' ],
14             [ 'token:s' => 'API token' ],
15             [ 'log:s' => 'Log file path' ],
16             [ 'base-url:s' => 'Base Smartcat URL' ],
17             [ 'debug' => 'Debug mode' ]
18             );
19             }
20              
21             sub project_id_opt_spec {
22 2     2 0 97 return ( [ 'project-id:s' => 'Project Id' ], );
23             }
24              
25             sub project_workdir_opt_spec {
26 0     0 0 0 return ( [ 'project-workdir:s' => 'Project translation files path' ], );
27             }
28              
29             sub file_params_opt_spec {
30             return (
31 0     0 0 0 [ 'filetype:s' => 'Type of translation files' ],
32             );
33             }
34              
35             sub validate_file_params {
36 0     0 0 0 my ( $self, $opt, $args ) = @_;
37 0         0 my $rundata = $self->app->{rundata};
38 0 0       0 $rundata->{filetype} = defined $opt->{filetype} ? $opt->{filetype} : '.po';
39             }
40              
41             sub validate_project_id {
42 2     2 0 7 my ( $self, $opt, $args ) = @_;
43 2         12 my $rundata = $self->app->{rundata};
44             $self->usage_error("'project_id' is required")
45 2 50       19 unless defined $opt->{project_id};
46 2         10 $rundata->{project_id} = $opt->{project_id};
47             }
48              
49             sub validate_project_workdir {
50 0     0 0 0 my ( $self, $opt, $args ) = @_;
51              
52 0         0 my $rundata = $self->app->{rundata};
53             $self->app->usage_error(
54             "'project_workdir', which is set to '$opt->{project_workdir}', does not point to a valid directory"
55 0 0       0 ) unless -d $opt->{project_workdir};
56 0         0 $rundata->{project_workdir} = abs_path( $opt->{project_workdir} );
57             }
58              
59             sub validate_args {
60 2     2 1 7 my ( $self, $opt, $args ) = @_;
61              
62 2         9 my $app = $self->app;
63 2         17 my $rundata = $self->app->{rundata};
64              
65 2 50 33     23 if ( defined $opt->{token_id} && defined $opt->{token} ) {
66 0         0 $app->{config}->{username} = $opt->{token_id};
67 0         0 $app->{config}->{password} = $opt->{token};
68             }
69              
70 2 50       8 if ( defined $opt->{base_url} ) {
71 0         0 $app->{config}->{base_url} = $opt->{base_url};
72             }
73              
74 2 100       7 if ( defined $opt->{log} ) {
75             $self->usage_error(
76             "directory of 'log', which is set to '$opt->{log}', does not point to a valid directory"
77 1 50 33     93 ) unless -d dirname( $opt->{log} ) && -w _;
78 1         7 $app->{config}->{log} = $opt->{log};
79             }
80              
81             $self->usage_error(
82             "set auth params via 'config' command first or provide options '--token-id' and '--token'"
83             )
84             unless ( defined $app->{config}->username
85 2 50 33     14 && defined $app->{config}->password );
86              
87 2 100       88 $rundata->{debug} = 1 if defined $opt->{debug};
88              
89 2         13 $app->init;
90             }
91              
92             1;