line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Daiku::CLI; |
2
|
3
|
|
|
3
|
|
131415
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
100
|
|
3
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
78
|
|
4
|
3
|
|
|
3
|
|
903
|
use Daiku::Daikufile; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
92
|
|
5
|
3
|
|
|
3
|
|
2213
|
use Getopt::Long 2.39 (); |
|
3
|
|
|
|
|
26507
|
|
|
3
|
|
|
|
|
145
|
|
6
|
3
|
|
|
3
|
|
1275
|
use Encode qw/encode_utf8/; |
|
3
|
|
|
|
|
16726
|
|
|
3
|
|
|
|
|
210
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use Mouse 0.92; |
|
3
|
|
|
|
|
60
|
|
|
3
|
|
|
|
|
24
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has file => ( |
11
|
|
|
|
|
|
|
is => 'rw', |
12
|
|
|
|
|
|
|
isa => 'Str', |
13
|
|
|
|
|
|
|
default => "Daikufile", |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub run { |
17
|
10
|
|
|
10
|
0
|
18491
|
my ($self, @args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
10
|
|
|
|
|
116
|
my $p = Getopt::Long::Parser->new( |
20
|
|
|
|
|
|
|
config => [qw(posix_default no_ignore_case bundling)], |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
10
|
|
|
|
|
1076
|
$p->getoptionsfromarray( |
24
|
|
|
|
|
|
|
\@args, |
25
|
|
|
|
|
|
|
"f|file=s" => \(my $file), |
26
|
|
|
|
|
|
|
"C|directory=s" => \(my $directory), |
27
|
|
|
|
|
|
|
"h|help" => \(my $help), |
28
|
|
|
|
|
|
|
"v|version" => \(my $version), |
29
|
|
|
|
|
|
|
"T|tasks" => \(my $tasks), |
30
|
|
|
|
|
|
|
); |
31
|
10
|
50
|
|
|
|
3602
|
if ($version) { |
32
|
0
|
|
|
|
|
0
|
require Daiku; |
33
|
0
|
|
|
|
|
0
|
printf "Daiku %s\n", Daiku->VERSION; |
34
|
0
|
|
|
|
|
0
|
exit 0; |
35
|
|
|
|
|
|
|
} |
36
|
10
|
50
|
|
|
|
30
|
if ($help) { |
37
|
0
|
|
|
|
|
0
|
require Pod::Usage; |
38
|
0
|
|
|
|
|
0
|
Pod::Usage::pod2usage(0); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
10
|
|
|
|
|
19
|
my @target = @args; |
42
|
|
|
|
|
|
|
|
43
|
10
|
100
|
|
|
|
31
|
$self->file($file) if $file; |
44
|
10
|
100
|
|
|
|
23
|
if ($directory) { |
45
|
1
|
50
|
|
|
|
9
|
chdir $directory or die "chdir $directory failed: $!\n"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
10
|
|
|
|
|
86
|
my $engine = Daiku::Daikufile->parse($self->file); |
49
|
|
|
|
|
|
|
|
50
|
9
|
100
|
|
|
|
26
|
if ($tasks) { |
51
|
1
|
|
|
|
|
5
|
_print_tasks($engine->tasks); |
52
|
1
|
|
|
|
|
21
|
return 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
8
|
100
|
|
|
|
22
|
if (!@target) { |
56
|
2
|
|
|
|
|
5
|
@target = ('default'); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
13
|
my $exit = 0; |
60
|
8
|
|
|
|
|
16
|
for my $target (@target) { |
61
|
10
|
|
|
|
|
14
|
eval { $engine->build($target) }; |
|
10
|
|
|
|
|
34
|
|
62
|
10
|
100
|
|
|
|
41
|
if ($@) { |
63
|
4
|
|
|
|
|
65
|
warn "$@\n"; |
64
|
4
|
|
|
|
|
16
|
$exit = 2; # like make(1) |
65
|
4
|
|
|
|
|
7
|
last; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
8
|
|
|
|
|
176
|
return $exit; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _print_tasks { |
72
|
1
|
|
|
1
|
|
3
|
my $tasks = shift; |
73
|
1
|
|
|
|
|
1
|
my $column_width = 1; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
3
|
my @tasks; |
76
|
1
|
|
|
|
|
82
|
for my $task (values %$tasks) { |
77
|
6
|
100
|
100
|
|
|
57
|
next unless $task->isa('Daiku::Task') && defined $task->desc; |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
36
|
my $task_name = $task->dst; |
80
|
3
|
|
|
|
|
3
|
my $len = length $task_name; |
81
|
3
|
100
|
|
|
|
5
|
$column_width = $len if $column_width < $len; |
82
|
3
|
|
|
|
|
11
|
push @tasks, { |
83
|
|
|
|
|
|
|
name => $task_name, |
84
|
|
|
|
|
|
|
desc => $task->desc, |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
4
|
for my $t (@tasks) { |
89
|
3
|
|
|
|
|
81
|
printf "daiku %-${column_width}s # %s\n", encode_utf8($t->{name}), encode_utf8($t->{desc}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
|
3
|
|
2108
|
no Mouse; __PACKAGE__->meta->make_immutable; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
14
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |