File Coverage

blib/lib/Giblog/Command/all.pm
Criterion Covered Total %
statement 21 51 41.1
branch 0 16 0.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 29 76 38.1


line stmt bran cond sub pod time code
1             package Giblog::Command::all;
2              
3 1     1   1250 use base 'Giblog::Command';
  1         3  
  1         123  
4              
5 1     1   8 use strict;
  1         3  
  1         22  
6 1     1   6 use warnings;
  1         3  
  1         25  
7 1     1   5 use Mojolicious;
  1         2  
  1         7  
8 1     1   46 use Time::Piece 'localtime';
  1         2  
  1         9  
9 1     1   84 use Getopt::Long 'GetOptions';
  1         3  
  1         9  
10              
11 1     1   167 use Carp 'confess';
  1         2  
  1         554  
12              
13             sub run {
14 0     0 1   my ($self, @argv) = @_;
15            
16 0           my $message;
17             my $has_deploy_option;
18             {
19 0           local @ARGV = @argv;
  0            
20 0           my $getopt_option_all = Getopt::Long::Configure(qw(default no_auto_abbrev no_ignore_case));
21 0           GetOptions(
22             'm=s' => \$message,
23             'deploy' => \$has_deploy_option,
24             );
25 0           Getopt::Long::Configure($getopt_option_all);
26 0           @argv = @ARGV;
27             }
28 0           my ($remote_rep, $branch) = @argv;
29            
30 0           my $api = $self->api;
31              
32 0           my $home_dir = $api->rel_file('.');
33            
34 0 0         unless (defined $message) {
35 0           confess 'Must be specify message using -m option';
36             }
37              
38 0 0         unless (defined $remote_rep) {
39 0           confess 'Must be specify remote repository name';
40             }
41              
42 0 0         unless (defined $branch) {
43 0           confess 'Must be specify branch name';
44             }
45            
46 0           my @giblog_build_command = ('giblog', '-C', $home_dir, 'build');
47 0 0         if (system(@giblog_build_command) == -1) {
48 0           confess "Fail giblog all command. Command is @giblog_build_command: $?";
49             }
50 0           my @giblog_save_command = ('giblog', '-C', $home_dir, 'save', '-m', $message, $remote_rep, $branch);
51 0 0         if(system(@giblog_save_command) == -1) {
52 0           confess "Fail giblog all command. Command is @giblog_save_command : $?";
53             }
54 0           my @giblog_publish_command = ('giblog', '-C', $home_dir, 'publish', $remote_rep, $branch);
55 0 0         if (system(@giblog_publish_command) == -1) {
56 0           confess "Fail giblog all command. Command is @giblog_publish_command : $?";
57             }
58              
59 0 0         if ($has_deploy_option) {
60 0           my @giblog_deploy_command = ('giblog', '-C', $home_dir, 'deploy');
61 0 0         if (system(@giblog_deploy_command) == -1) {
62 0           confess "Fail giblog all command with --deploy option. Command is @giblog_deploy_command: $?";
63             }
64             }
65             }
66              
67             1;
68              
69             =encoding utf8
70              
71             =head1 NAME
72              
73             Giblog::Command::all - all command
74              
75             =head1 DESCRIPTION
76              
77             L is all command to execute "giblog build", "giblog save", and "giblog publish".
78              
79             =head1 USAGE
80              
81             giblog all -m COMMIT_COMMENT REMOTE_REPOSITORY BRANCH
82              
83             giblog all -m COMMIT_COMMENT --deploy REMOTE_REPOSITORY BRANCH
84            
85             =head1 METHODS
86              
87             L inherits all methods from L and
88             implements the following new ones.
89              
90             =head2 run
91              
92             $command->run('-m', $message, $remote_repository, $branch);
93             $command->run('-m', $message, '--deploy', $remote_repository, $branch);
94              
95             all command executes the following git commands(giblog build, giblog save, giblog publish).
96              
97             This is the same as the following command. In this example, the commit message is "Hello". the repository name is "origin". the branch name is "main".
98              
99             giblog build
100             giblog save -m "Hello" origin main
101             giblog publish origin main
102              
103             If C<--deploy> option is specified, "giblog deploy" is executed after executing "giblog all" command.