blib/lib/Perinci/Sub/To/CLIDocData.pm

filter: Statementstmt 9.6% 27 / 279 Branchbran 0.0% 0 / 178 Conditioncond 0.0% 0 / 156 MC/DCmcdc 0.0% 0 / 90 Subroutinesub 50.0% 6 / 12 Podpod 100% 1 / 1 totaltotal 4.7% 34 / 716 CC 161 SCAR 95.1
CC
161
Cov
4%
gen_cli_doc_data_from_meta
17556.0
_fmt_opt
156.0
_add_category_from_spec
110.0
CRAP 13492.5
↑ Summary
1 package Perinci::Sub::To::CLIDocData;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Perinci::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Perinci::Sub::Util qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 1 our $DATE = '2022-11-14'; # DATE
13 1 our $DIST = 'Perinci-Sub-To-CLIDocData'; # DIST
14 1 our $VERSION = '0.305'; # VERSION
15  
16 1 our %SPEC;
17  
18 1 require Exporter;
19 1 our @ISA = qw(Exporter);
20 1 our @EXPORT_OK = qw(gen_cli_doc_data_from_meta);
21  
22 0 ▶sub _has_cats {
Subroutine _has_cats: not called CC=6 SCAR=37.4
23 0 for my $spec (@{ $_[0] }) {
24 0 ▶ for (@{ $spec->{tags} // [] }) {
Condition0%0/2
$spec->{"tags"} // []
l!l
00
MC/DC0%0/1
$spec->{"tags"} // []
$spec->{"tags"}
Truth table0%0/2
A
A= $spec->{"tags"}
Aresult
11
00
25 0 ▶ my $tag_name = ref($_) ? $_->{name} : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
26 0 ▶ if ($tag_name =~ /^category:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag_name =~ /^category:/) 0 0 0
27 0 return 1;
28 }
29 }
30 }
31 0 0;
32 }
33  
34 0 ▶sub _add_category_from_spec {
Subroutine _add_category_from_spec: not called CC=10 SCAR=47.0
35 0 my ($cats_spec, $thing, $spec, $noun, $has_cats) = @_;
36 0 my @cats;
37 0 ▶ for (@{ $spec->{tags} // [] }) {
Condition0%0/2
$spec->{"tags"} // []
l!l
00
MC/DC0%0/1
$spec->{"tags"} // []
$spec->{"tags"}
Truth table0%0/2
A
A= $spec->{"tags"}
Aresult
11
00
38 0 ▶ my $tag_name = ref($_) ? $_->{name} : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
39 0 ▶ if ($tag_name =~ /^category(\d+)?:(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag_name =~ /^category(\d+)?:(.+)/) 0 0 0
40 0 my $cat = ucfirst($2);
41 0 ▶ my $ordering = $1 // 50;
Condition0%0/2
$1 // 50
l!l
00
MC/DC0%0/1
$1 // 50
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
42 0 $cat =~ s/-/ /g;
43 0 $cat .= " " . $noun;
44 0 push @cats, [$cat, $ordering]; # name, ordering
45 }
46 }
47 0 ▶ if (!@cats) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@cats) 0 0 0
48 0 ▶ @cats = [$has_cats ? "Other $noun" : ucfirst($noun), 99]; # XXX translatable?
Branch: 1 branch
BranchTrueFalseTotal
$has_cats ? : 0 0 0
49 }
50  
51 # old, will be removed someday
52 0 $thing->{category} = $cats[0][0];
53 # new/current
54 0 $thing->{categories} = [map {$_->[0]} @cats];
55  
56 0 ▶ $cats_spec->{$_->[0]}{order} //= $_->[1] for @cats;
Condition0%0/3
$$cats_spec{$_->[0]}{"order"} //= $_->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$$cats_spec{$_->[0]}{"order"} //= $_->[1]
$$cats_spec{$_->[0]}{"order"} $_->[1]
Truth table0%0/3
A //= B
A= $$cats_spec{$_->[0]}{"order"}B= $_->[1]
ABresult
1X1
011
000
57 }
58  
59 0 ▶sub _add_default_from_arg_spec {
Subroutine _add_default_from_arg_spec: not called CC=4 SCAR=30.0
60 0 my ($opt, $arg_spec) = @_;
61 0 ▶ if (exists $arg_spec->{default}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $arg_spec->{'default'}) { } 0 0 0
elsif ($arg_spec->{'schema'} and exists $arg_spec->{'schema'}[1]{'default'}) { } 0 0 0
62 0 $opt->{default} = $arg_spec->{default};
63 ▶ } elsif ($arg_spec->{schema} && exists($arg_spec->{schema}[1]{default})) {
Condition0%0/3
$arg_spec->{"schema"} and exists $arg_spec->{"schema"}[1]{"default"}
!ll&&!rl&&r
000
MC/DC0%0/2
$arg_spec->{"schema"} and exists $arg_spec->{"schema"}[1]{"default"}
$arg_spec->{"schema"} exists $arg_spec->{"schema"}[1]{"default"}
Truth table0%0/3
A and B
A= $arg_spec->{"schema"}B= exists $arg_spec->{"schema"}[1]{"default"}
ABresult
0X0
100
111
64 0 $opt->{default} = $arg_spec->{schema}[1]{default};
65 }
66 }
67  
68 0 ▶sub _dash_prefix {
Subroutine _dash_prefix: not called CC=2 SCAR=17.9
69 0 ▶ length($_[0]) > 1 ? "--$_[0]" : "-$_[0]";
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] > 1 ? : 0 0 0
70 }
71  
72 0 ▶sub _fmt_opt {
Subroutine _fmt_opt: not called CC=12 SCAR=50.5
73 0 my $spec = shift;
74 0 my @ospecs = @_;
75 0 my @res;
76 0 my $i = 0;
77 0 for my $ospec (@ospecs) {
78 0 my $j = 0;
79 0 my $parsed = $ospec->{parsed};
80 0 for (@{ $parsed->{opts} }) {
81 0 my $opt = _dash_prefix($_);
82 0 ▶ if ($i==0 && $j==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 and $j == 0) 0 0 0
Condition0%0/3
$i == 0 and $j == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$i == 0 and $j == 0
$i == 0 $j == 0
Truth table0%0/3
A and B
A= $i == 0B= $j == 0
ABresult
0X0
100
111
83 0 ▶ if ($parsed->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed->{"type"}) 0 0 0
84 0 ▶ if ($spec->{'x.schema.entity'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'x.schema.entity'}) { } 0 0 0
elsif ($spec->{'x.schema.element_entity'}) { } 0 0 0
85 0 $opt .= "=".$spec->{'x.schema.entity'};
86 } elsif ($spec->{'x.schema.element_entity'}) {
87 0 $opt .= "=".$spec->{'x.schema.element_entity'};
88 } else {
89 0 $opt .= "=$parsed->{type}";
90 }
91 }
92 # mark required option with a '*'
93 $opt .= "*" if $spec->{req} && !$ospec->{is_base64} &&
94 0 ▶ !$ospec->{is_json} && !$ospec->{is_yaml};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"req"} and not $ospec->{"is_base64"} and not $ospec->{"is_json"} and not $ospec->{"is_yaml"} 0 0 0
Condition0%0/9
$spec->{"req"} and not $ospec->{"is_base64"} and not $ospec->{"is_json"} and not $ospec->{"is_yaml"}
!ll&&!rl&&r
000
$spec->{"req"} and not $ospec->{"is_base64"} and not $ospec->{"is_json"}
!ll&&!rl&&r
000
$spec->{"req"} and not $ospec->{"is_base64"}
!ll&&!rl&&r
000
MC/DC0%0/4
$spec->{"req"} and not $ospec->{"is_base64"} and not $ospec->{"is_json"} and not $ospec->{"is_yaml"}
$spec->{"req"} not $ospec->{"is_base64"} not $ospec->{"is_json"} not $ospec->{"is_yaml"}
Truth table0%0/5
A and not(B) and not(C) and not(D)
A= $spec->{"req"}B= not $ospec->{"is_base64"}C= not $ospec->{"is_json"}D= not $ospec->{"is_yaml"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
95 }
96 0 push @res, $opt;
97 0 $j++;
98 }
99 0 $i++;
100 }
101 0 join ", ", @res;
102 }
103  
104 $SPEC{gen_cli_doc_data_from_meta} = {
105 1 v => 1.1,
106 summary => 'From Rinci function metadata, generate structure convenient '.
107 'for producing CLI documentation (help/usage/POD)',
108 description => <<'_',
109  
110 This function calls <pm:Perinci::Sub::GetArgs::Argv>'s
111 `gen_getopt_long_spec_from_meta()` (or receive its result as an argument, if
112 passed, to avoid calling the function twice) and post-processes it: produce
113 command usage line, format the options, include information from metadata, group
114 the options by category. It also selects examples in the `examples` property
115 which are applicable to CLI environment and format them.
116  
117 The resulting data structure is convenient to use when one wants to produce a
118 documentation for CLI program (including help/usage message and POD).
119  
120 _
121 args => {
122 meta => {
123 schema => 'hash*', # XXX rifunc
124 req => 1,
125 pos => 0,
126 },
127 meta_is_normalized => {
128 schema => 'bool*',
129 },
130 common_opts => {
131 summary => 'Will be passed to gen_getopt_long_spec_from_meta()',
132 schema => 'hash*',
133 },
134 ggls_res => {
135 summary => 'Full result from gen_getopt_long_spec_from_meta()',
136 schema => 'array*', # XXX envres
137 description => <<'_',
138  
139 If you already call <pm:Perinci::Sub::GetArgs::Argv>'s
140 `gen_getopt_long_spec_from_meta()`, you can pass the _full_ enveloped result
141 here, to avoid calculating twice. What will be useful for the function is the
142 extra result in result metadata (`func.*` keys in `$res->[3]` hash).
143  
144 _
145 },
146 per_arg_json => {
147 schema => 'bool',
148 summary => 'Pass per_arg_json=1 to Perinci::Sub::GetArgs::Argv',
149 },
150 per_arg_yaml => {
151 schema => 'bool',
152 summary => 'Pass per_arg_json=1 to Perinci::Sub::GetArgs::Argv',
153 },
154 lang => {
155 schema => 'str*',
156 },
157 mark_different_lang => {
158 schema => 'bool*',
159 default => 1,
160 },
161 },
162 result => {
163 schema => 'hash*',
164 },
165 };
166 0 ▶sub gen_cli_doc_data_from_meta {
Subroutine gen_cli_doc_data_from_meta: not called CC=132 SCAR=97.7
Pod documented
167 0 require Getopt::Long::Negate::EN;
168  
169 0 my %args = @_;
170  
171 0 my $lang = $args{lang};
172 0 ▶ my $mark_different_lang = $args{mark_different_lang} // 1;
Condition0%0/2
$args{"mark_different_lang"} // 1
l!l
00
MC/DC0%0/1
$args{"mark_different_lang"} // 1
$args{"mark_different_lang"}
Truth table0%0/2
A
A= $args{"mark_different_lang"}
Aresult
11
00
173 0 ▶ my $meta = $args{meta} or return [400, 'Please specify meta'];
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $args{"meta"} or return [400, "Please specify meta"] 0 0 0
174 0 my $common_opts = $args{common_opts};
175 0 ▶ unless ($args{meta_is_normalized}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"meta_is_normalized"}) 0 0 0
176 0 require Perinci::Sub::Normalize;
177 0 $meta = Perinci::Sub::Normalize::normalize_function_metadata($meta);
178 }
179 0 ▶ my $ggls_res = $args{ggls_res} // do {
Condition0%0/3
$args{"ggls_res"} // do { require Perinci::Sub::GetArgs::Argv; Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta("meta", $meta, "meta_is_normalized", 1, "common_opts", $common_opts, "per_arg_json", $args{"per_arg_json"}, "per_arg_yaml", $args{"per_arg_yaml"}) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"ggls_res"} // do { require Perinci::Sub::GetArgs::Argv; Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta("meta", $meta, "meta_is_normalized", 1, "common_opts", $common_opts, "per_arg_json", $args{"per_arg_json"}, "per_arg_yaml", $args{"per_arg_yaml"}) }
$args{"ggls_res"} do { require Perinci::Sub::GetArgs::Argv; Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta("meta", $meta, "meta_is_normalized", 1, "common_opts", $common_opts, "per_arg_json", $args{"per_arg_json"}, "per_arg_yaml", $args{"per_arg_yaml"}) }
Truth table0%0/3
A // B
A= $args{"ggls_res"}B= do { require Perinci::Sub::GetArgs::Argv; Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta("meta", $meta, "meta_is_normalized", 1, "common_opts", $common_opts, "per_arg_json", $args{"per_arg_json"}, "per_arg_yaml", $args{"per_arg_yaml"}) }
ABresult
1X1
011
000
180 0 require Perinci::Sub::GetArgs::Argv;
181 Perinci::Sub::GetArgs::Argv::gen_getopt_long_spec_from_meta(
182 meta=>$meta, meta_is_normalized=>1, common_opts=>$common_opts,
183 per_arg_json => $args{per_arg_json},
184 per_arg_yaml => $args{per_arg_yaml},
185 0 );
186 };
187 0 ▶ $ggls_res->[0] == 200 or return $ggls_res;
Branch: 1 branch
BranchTrueFalseTotal
$ggls_res->[0] == 200 or return $ggls_res 0 0 0
188  
189 0 my $langprop_args = {lang=>$lang, mark_different_lang=>$mark_different_lang};
190 0 ▶ my $args_prop = $meta->{args} // {};
Condition0%0/2
$meta->{"args"} // {}
l!l
00
MC/DC0%0/1
$meta->{"args"} // {}
$meta->{"args"}
Truth table0%0/2
A
A= $meta->{"args"}
Aresult
11
00
191 0 my $clidocdata = {
192 option_categories => {},
193 example_categories => {},
194 };
195  
196 # a mapping from arg spec keys to %opts keys, so we can create a POD link
197 # from a positional argument in usage line to option, later when generating
198 # usage line
199 0 my %arg_spec_to_opts;
200  
201 # a mapping from keys in func.specmeta (ospec) to %opts keys, so we can
202 # create a POD link from an option in usage line to option in Options
203 # section, later when generating usage line
204 my %ospec_to_opts;
205  
206 0 my %opts;
207 GEN_LIST_OF_OPTIONS: {
208 0 my $ospecs = $ggls_res->[3]{'func.specmeta'};
209 # separate groupable aliases because they will be merged with the
210 # argument options
211 0 my (@k, @k_aliases);
212  
213 OSPEC1:
214 0 for (sort keys %$ospecs) {
215 0 my $ospec = $ospecs->{$_};
216 {
217 0 ▶ last unless $ospec->{is_alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $ospec->{"is_alias"} 0 0 0
218 0 ▶ next if $ospec->{is_code};
Branch: 1 branch
BranchTrueFalseTotal
if $ospec->{"is_code"} 0 0 0
219 0 my $arg_spec = $args_prop->{$ospec->{arg}};
220 0 my $alias_spec = $arg_spec->{cmdline_aliases}{$ospec->{alias}};
221 0 ▶ next if $alias_spec->{summary};
Branch: 1 branch
BranchTrueFalseTotal
if $alias_spec->{"summary"} 0 0 0
222 0 push @k_aliases, $_;
223 0 next OSPEC1;
224 }
225 0 push @k, $_;
226 }
227  
228 0 my %negs; # key=arg, only show one negation form for each arg option
229  
230 OSPEC2:
231 0 ▶ while (@k) {
Branch: 1 branch
BranchTrueFalseTotal
if (@k) 0 0 0
232 0 my $k = shift @k;
233 0 my $ospec = $ospecs->{$k};
234 0 my $opt;
235 my $optkey;
236  
237 0 ▶ if ($ospec->{is_alias} || defined($ospec->{arg})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ospec->{'is_alias'} or defined $ospec->{'arg'}) { } 0 0 0
Condition0%0/3
$ospec->{"is_alias"} or defined $ospec->{"arg"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ospec->{"is_alias"} or defined $ospec->{"arg"}
$ospec->{"is_alias"} defined $ospec->{"arg"}
Truth table0%0/3
A or B
A= $ospec->{"is_alias"}B= defined $ospec->{"arg"}
ABresult
1X1
011
000
238 0 my $arg_spec;
239 my $alias_spec;
240  
241 0 ▶ if ($ospec->{is_alias}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ospec->{'is_alias'}) { } 0 0 0
242 # non-groupable alias
243  
244 0 my $real_opt_ospec = $ospecs->{ $ospec->{alias_for} };
245  
246 0 $arg_spec = $args_prop->{ $ospec->{arg} };
247 0 $alias_spec = $arg_spec->{cmdline_aliases}{$ospec->{alias}};
248 0 my $rimeta = rimeta($alias_spec);
249 0 $optkey = _fmt_opt($arg_spec, $ospec);
250 $opt = {
251 opt_parsed => $ospec->{parsed},
252 orig_opt => $k,
253 is_alias => 1,
254 alias_for => $ospec->{alias_for},
255 summary => $rimeta->langprop($langprop_args, 'summary') //
256 0 ▶ "Alias for "._dash_prefix($real_opt_ospec->{parsed}{opts}[0]),
Condition0%0/2
$rimeta->langprop($langprop_args, "summary") // 'Alias for ' . _dash_prefix($real_opt_ospec->{"parsed"}{"opts"}[0])
l!l
00
MC/DC0%0/1
$rimeta->langprop($langprop_args, "summary") // 'Alias for ' . _dash_prefix($real_opt_ospec->{"parsed"}{"opts"}[0])
$rimeta->langprop($langprop_args, "summary")
Truth table0%0/2
A
A= $rimeta->langprop($langprop_args, "summary")
Aresult
11
00
257 description =>
258 $rimeta->langprop($langprop_args, 'description'),
259 };
260 } else {
261 # an option for argument
262  
263 0 $arg_spec = $args_prop->{$ospec->{arg}};
264 0 my $rimeta = rimeta($arg_spec);
265 $opt = {
266 opt_parsed => $ospec->{parsed},
267 0 orig_opt => $k,
268 };
269  
270 # for bool, only display either the positive (e.g. --bool)
271 # or the negative (e.g. --nobool) depending on the default
272 0 ▶ if (defined($ospec->{is_neg})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ospec->{"is_neg"}) 0 0 0
273 my $default = $arg_spec->{default} //
274 0 ▶ $arg_spec->{schema}[1]{default};
Condition0%0/3
$arg_spec->{"default"} // $arg_spec->{"schema"}[1]{"default"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg_spec->{"default"} // $arg_spec->{"schema"}[1]{"default"}
$arg_spec->{"default"} $arg_spec->{"schema"}[1]{"default"}
Truth table0%0/3
A // B
A= $arg_spec->{"default"}B= $arg_spec->{"schema"}[1]{"default"}
ABresult
1X1
011
000
275 0 ▶ next OSPEC2 if $default && !$ospec->{is_neg};
Branch: 1 branch
BranchTrueFalseTotal
if $default and not $ospec->{"is_neg"} 0 0 0
Condition0%0/3
$default and not $ospec->{"is_neg"}
!ll&&!rl&&r
000
MC/DC0%0/2
$default and not $ospec->{"is_neg"}
$default not $ospec->{"is_neg"}
Truth table0%0/3
A and not(B)
A= $defaultB= not $ospec->{"is_neg"}
ABresult
0X0
100
111
276 0 ▶ next OSPEC2 if !$default && $ospec->{is_neg};
Branch: 1 branch
BranchTrueFalseTotal
if not $default and $ospec->{"is_neg"} 0 0 0
Condition0%0/3
not $default and $ospec->{"is_neg"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $default and $ospec->{"is_neg"}
not $default $ospec->{"is_neg"}
Truth table0%0/3
not(A) and B
A= not $defaultB= $ospec->{"is_neg"}
ABresult
0X0
100
111
277 0 ▶ if ($ospec->{is_neg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ospec->{"is_neg"}) 0 0 0
278 0 ▶ next OSPEC2 if $negs{$ospec->{arg}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $negs{$ospec->{"arg"}}++ 0 0 0
279 }
280 }
281  
282 0 ▶ if ($ospec->{is_neg}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ospec->{'is_neg'}) { } 0 0 0
elsif (defined $ospec->{'is_neg'}) { } 0 0 0
elsif (($ospec->{'parsed'}{'type'} // '') eq 's@') { } 0 0 0
283 # for negative option, use negative summary instead of
284 # regular (positive sentence) summary
285 $opt->{summary} =
286 0 $rimeta->langprop($langprop_args, 'summary.alt.bool.not');
287 } elsif (defined $ospec->{is_neg}) {
288 # for boolean option which we show the positive, show
289 # the positive summary if available
290 $opt->{summary} =
291 0 ▶ $rimeta->langprop($langprop_args, 'summary.alt.bool.yes') //
Condition0%0/3
$rimeta->langprop($langprop_args, "summary.alt.bool.yes") // $rimeta->langprop($langprop_args, "summary")
l!l&&r!l&&!r
000
MC/DC0%0/2
$rimeta->langprop($langprop_args, "summary.alt.bool.yes") // $rimeta->langprop($langprop_args, "summary")
$rimeta->langprop($langprop_args, "summary.alt.bool.yes") $rimeta->langprop($langprop_args, "summary")
Truth table0%0/3
A // B
A= $rimeta->langprop($langprop_args, "summary.alt.bool.yes")B= $rimeta->langprop($langprop_args, "summary")
ABresult
1X1
011
000
292 $rimeta->langprop($langprop_args, 'summary');
293 ▶ } elsif (($ospec->{parsed}{type}//'') eq 's@') {
Condition0%0/2
$ospec->{"parsed"}{"type"} // ""
l!l
00
MC/DC0%0/1
$ospec->{"parsed"}{"type"} // ""
$ospec->{"parsed"}{"type"}
Truth table0%0/2
A
A= $ospec->{"parsed"}{"type"}
Aresult
11
00
294 # for array of string that can be specified via multiple
295 # --opt, show singular version of summary if available.
296 # otherwise show regular summary.
297 $opt->{summary} =
298 0 ▶ $rimeta->langprop($langprop_args, 'summary.alt.plurality.singular') //
Condition0%0/3
$rimeta->langprop($langprop_args, "summary.alt.plurality.singular") // $rimeta->langprop($langprop_args, "summary")
l!l&&r!l&&!r
000
MC/DC0%0/2
$rimeta->langprop($langprop_args, "summary.alt.plurality.singular") // $rimeta->langprop($langprop_args, "summary")
$rimeta->langprop($langprop_args, "summary.alt.plurality.singular") $rimeta->langprop($langprop_args, "summary")
Truth table0%0/3
A // B
A= $rimeta->langprop($langprop_args, "summary.alt.plurality.singular")B= $rimeta->langprop($langprop_args, "summary")
ABresult
1X1
011
000
299 $rimeta->langprop($langprop_args, 'summary');
300 } else {
301 $opt->{summary} =
302 0 $rimeta->langprop($langprop_args, 'summary');
303 }
304 $opt->{description} =
305 0 $rimeta->langprop($langprop_args, 'description');
306  
307 # find aliases that can be grouped together with this option
308 0 my @aliases;
309 0 my $j = $#k_aliases;
310 0 ▶ while ($j >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j >= 0) 0 0 0
311 0 my $aospec = $ospecs->{ $k_aliases[$j] };
312 {
313 0 ▶ last unless $aospec->{arg} eq $ospec->{arg};
Branch: 1 branch
BranchTrueFalseTotal
unless $aospec->{"arg"} eq $ospec->{"arg"} 0 0 0
314 0 push @aliases, $aospec;
315 0 splice @k_aliases, $j, 1;
316 }
317 0 $j--;
318 }
319  
320 0 $optkey = _fmt_opt($arg_spec, $ospec, @aliases);
321 }
322  
323 0 $opt->{arg_spec} = $arg_spec;
324 0 ▶ $opt->{alias_spec} = $alias_spec if $alias_spec;
Branch: 1 branch
BranchTrueFalseTotal
if $alias_spec 0 0 0
325  
326 # include keys from func.specmeta
327 0 for (qw/arg fqarg is_base64 is_json is_yaml/) {
328 0 ▶ $opt->{$_} = $ospec->{$_} if defined $ospec->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ospec->{$_} 0 0 0
329 }
330  
331 # include keys from arg_spec
332 0 for (qw/req pos slurpy greedy is_password links tags/) {
333 0 ▶ $opt->{$_} = $arg_spec->{$_} if defined $arg_spec->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg_spec->{$_} 0 0 0
334 }
335  
336 {
337 # we don't want argument options to end up in "Other" like
338 # --help or -v, they are put at the end. so if an argument
339 # option does not have category, we'll put it in the "main"
340 # category.
341 0 local $arg_spec->{tags} = ['category0:main']
342 0 ▶ if !$arg_spec->{tags} || !@{$arg_spec->{tags}};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg_spec->{"tags"} and @{$arg_spec->{"tags"};} 0 0 0
Condition0%0/3
$arg_spec->{"tags"} and @{$arg_spec->{"tags"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$arg_spec->{"tags"} and @{$arg_spec->{"tags"};}
$arg_spec->{"tags"} @{$arg_spec->{"tags"};}
Truth table0%0/3
A and B
A= $arg_spec->{"tags"}B= @{$arg_spec->{"tags"};}
ABresult
0X0
100
111
343 _add_category_from_spec($clidocdata->{option_categories},
344 0 $opt, $arg_spec, "options", 1);
345 }
346 0 _add_default_from_arg_spec($opt, $arg_spec);
347  
348 } else {
349 # option from common_opts
350  
351 0 my $spec = $common_opts->{$ospec->{common_opt}};
352  
353 # for bool, only display either the positive (e.g. --bool)
354 # or the negative (e.g. --nobool) depending on the default
355 0 ▶ my $show_neg = $ospec->{parsed}{is_neg} && $spec->{default};
Condition0%0/3
$ospec->{'parsed'}{'is_neg'} && $spec->{'default'}
!ll&&!rl&&r
000
MC/DC0%0/2
$ospec->{'parsed'}{'is_neg'} && $spec->{'default'}
$ospec->{'parsed'}{'is_neg'} $spec->{'default'}
Truth table0%0/3
A && B
A= $ospec->{'parsed'}{'is_neg'}B= $spec->{'default'}
ABresult
0X0
100
111
356  
357 0 ▶ local $ospec->{parsed}{opts} = do {
Branch: 1 branch
BranchTrueFalseTotal
if $show_neg 0 0 0
358 # XXX check if it's single-letter, get first
359 # non-single-letter
360 my @opts = Getopt::Long::Negate::EN::negations_for_option(
361 0 $ospec->{parsed}{opts}[0]);
362 0 [ $opts[0] ];
363 } if $show_neg;
364  
365 0 $optkey = _fmt_opt($spec, $ospec);
366 0 my $rimeta = rimeta($spec);
367 $opt = {
368 opt_parsed => $ospec->{parsed},
369 orig_opt => $k,
370 common_opt => $ospec->{common_opt},
371 common_opt_spec => $spec,
372 summary => $show_neg ?
373 $rimeta->langprop($langprop_args, 'summary.alt.bool.not') :
374 $rimeta->langprop($langprop_args, 'summary'),
375 (schema => $spec->{schema}) x !!$spec->{schema},
376 ('x.schema.entity' => $spec->{'x.schema.entity'}) x !!$spec->{'x.schema.entity'},
377 ('x.schema.element_entity' => $spec->{'x.schema.element_entity'}) x !!$spec->{'x.schema.element_entity'},
378 description =>
379 $rimeta->langprop($langprop_args, 'description'),
380 0 ▶ (default => $spec->{default}) x !!(exists($spec->{default}) && !$show_neg),
Branch: 1 branch
BranchTrueFalseTotal
$show_neg ? : 0 0 0
Condition0%0/3
exists $spec->{'default'} && !$show_neg
!ll&&!rl&&r
000
MC/DC0%0/2
exists $spec->{'default'} && !$show_neg
exists $spec->{'default'} !$show_neg
Truth table0%0/3
A && not(B)
A= exists $spec->{'default'}B= !$show_neg
ABresult
0X0
100
111
381 };
382  
383 _add_category_from_spec($clidocdata->{option_categories},
384 0 $opt, $spec, "options", 1);
385  
386 }
387  
388 0 $opts{$optkey} = $opt;
389 0 ▶ $arg_spec_to_opts{ $ospec->{arg} } = $optkey if $ospec->{arg};
Branch: 1 branch
BranchTrueFalseTotal
if $ospec->{"arg"} 0 0 0
390 0 $ospec_to_opts{$k} = $optkey;
391 } # while @k
392  
393 # link ungrouped alias to its main opt
394 OPT1:
395 0 for my $k (keys %opts) {
396 0 my $opt = $opts{$k};
397 next unless $opt->{is_alias} || $opt->{is_base64} ||
398 0 ▶ $opt->{is_json} || $opt->{is_yaml};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"is_alias"} or $opt->{"is_base64"} or $opt->{"is_json"} or $opt->{"is_yaml"} 0 0 0
Condition0%0/9
$opt->{"is_alias"} or $opt->{"is_base64"} or $opt->{"is_json"} or $opt->{"is_yaml"}
l!l&&r!l&&!r
000
$opt->{"is_alias"} or $opt->{"is_base64"} or $opt->{"is_json"}
l!l&&r!l&&!r
000
$opt->{"is_alias"} or $opt->{"is_base64"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$opt->{"is_alias"} or $opt->{"is_base64"} or $opt->{"is_json"} or $opt->{"is_yaml"}
$opt->{"is_alias"} $opt->{"is_base64"} $opt->{"is_json"} $opt->{"is_yaml"}
Truth table0%0/5
A or B or C or D
A= $opt->{"is_alias"}B= $opt->{"is_base64"}C= $opt->{"is_json"}D= $opt->{"is_yaml"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
399 0 for my $k2 (keys %opts) {
400 0 my $arg_opt = $opts{$k2};
401 next if $arg_opt->{is_alias} || $arg_opt->{is_base64} ||
402 0 ▶ $arg_opt->{is_json} || $arg_opt->{is_yaml};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_opt->{"is_alias"} or $arg_opt->{"is_base64"} or $arg_opt->{"is_json"} or $arg_opt->{"is_yaml"} 0 0 0
Condition0%0/9
$arg_opt->{"is_alias"} or $arg_opt->{"is_base64"} or $arg_opt->{"is_json"} or $arg_opt->{"is_yaml"}
l!l&&r!l&&!r
000
$arg_opt->{"is_alias"} or $arg_opt->{"is_base64"} or $arg_opt->{"is_json"}
l!l&&r!l&&!r
000
$arg_opt->{"is_alias"} or $arg_opt->{"is_base64"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$arg_opt->{"is_alias"} or $arg_opt->{"is_base64"} or $arg_opt->{"is_json"} or $arg_opt->{"is_yaml"}
$arg_opt->{"is_alias"} $arg_opt->{"is_base64"} $arg_opt->{"is_json"} $arg_opt->{"is_yaml"}
Truth table0%0/5
A or B or C or D
A= $arg_opt->{"is_alias"}B= $arg_opt->{"is_base64"}C= $arg_opt->{"is_json"}D= $arg_opt->{"is_yaml"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
403 next unless defined($arg_opt->{arg}) &&
404 0 ▶ $arg_opt->{arg} eq $opt->{arg};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg_opt->{"arg"} and $arg_opt->{"arg"} eq $opt->{"arg"} 0 0 0
Condition0%0/3
defined $arg_opt->{"arg"} and $arg_opt->{"arg"} eq $opt->{"arg"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $arg_opt->{"arg"} and $arg_opt->{"arg"} eq $opt->{"arg"}
defined $arg_opt->{"arg"} $arg_opt->{"arg"} eq $opt->{"arg"}
Truth table0%0/3
A and B
A= defined $arg_opt->{"arg"}B= $arg_opt->{"arg"} eq $opt->{"arg"}
ABresult
0X0
100
111
405 0 $opt->{main_opt} = $k2;
406 0 next OPT1;
407 }
408 }
409  
410 } # GEN_LIST_OF_OPTIONS
411 0 $clidocdata->{opts} = \%opts;
412  
413 #use DDC; dd \%arg_spec_to_opts;
414 #use DDC; dd \%ospec_to_opts;
415  
416 GEN_USAGE_LINE: {
417 0 my @plain_args;
418 my @pod_args;
419  
420 0 my %args_prop = %$args_prop; # copy because we want to iterate & delete
421 0 my $max_pos = -1;
422 0 for (values %args_prop) {
423 $max_pos = $_->{pos}
424 0 ▶ if defined($_->{pos}) && $_->{pos} > $max_pos;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->{"pos"} and $_->{"pos"} > $max_pos 0 0 0
Condition0%0/3
defined $_->{"pos"} and $_->{"pos"} > $max_pos
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->{"pos"} and $_->{"pos"} > $max_pos
defined $_->{"pos"} $_->{"pos"} > $max_pos
Truth table0%0/3
A and B
A= defined $_->{"pos"}B= $_->{"pos"} > $max_pos
ABresult
0X0
100
111
425 }
426 0 my $pos = 0;
427 0 ▶ while ($pos <= $max_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $max_pos) 0 0 0
428 0 my ($arg, $arg_spec);
429 0 for (keys %args_prop) {
430 0 $arg_spec = $args_prop{$_};
431 0 ▶ if (defined($arg_spec->{pos}) && $arg_spec->{pos}==$pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg_spec->{"pos"} and $arg_spec->{"pos"} == $pos) 0 0 0
Condition0%0/3
defined $arg_spec->{"pos"} and $arg_spec->{"pos"} == $pos
!ll&&!rl&&r
000
MC/DC0%0/2
defined $arg_spec->{"pos"} and $arg_spec->{"pos"} == $pos
defined $arg_spec->{"pos"} $arg_spec->{"pos"} == $pos
Truth table0%0/3
A and B
A= defined $arg_spec->{"pos"}B= $arg_spec->{"pos"} == $pos
ABresult
0X0
100
111
432 0 $arg = $_;
433 0 last;
434 }
435 }
436 0 $pos++;
437 0 ▶ next unless defined($arg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 0 0 0
438 0 my $arg0 = $arg;
439 0 ▶ if ($arg_spec->{slurpy} // $arg_spec->{greedy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_spec->{"slurpy"} // $arg_spec->{"greedy"}) 0 0 0
Condition0%0/3
$arg_spec->{"slurpy"} // $arg_spec->{"greedy"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg_spec->{"slurpy"} // $arg_spec->{"greedy"}
$arg_spec->{"slurpy"} $arg_spec->{"greedy"}
Truth table0%0/3
A // B
A= $arg_spec->{"slurpy"}B= $arg_spec->{"greedy"}
ABresult
1X1
011
000
440 # try to find the singular form
441 $arg = $arg_spec->{'x.name.singular'}
442 if $arg_spec->{'x.name.is_plural'} &&
443 0 ▶ defined $arg_spec->{'x.name.singular'};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_spec->{"x.name.is_plural"} and defined $arg_spec->{"x.name.singular"} 0 0 0
Condition0%0/3
$arg_spec->{"x.name.is_plural"} and defined $arg_spec->{"x.name.singular"}
!ll&&!rl&&r
000
MC/DC0%0/2
$arg_spec->{"x.name.is_plural"} and defined $arg_spec->{"x.name.singular"}
$arg_spec->{"x.name.is_plural"} defined $arg_spec->{"x.name.singular"}
Truth table0%0/3
A and B
A= $arg_spec->{"x.name.is_plural"}B= defined $arg_spec->{"x.name.singular"}
ABresult
0X0
100
111
444 }
445 0 ▶ if ($arg_spec->{req}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_spec->{'req'}) { } 0 0 0
446 0 push @plain_args, "<$arg>";
447 0 push @pod_args , qq#E<lt>I<L<$arg|/"$arg_spec_to_opts{$arg0}">>E<gt>#;
448 } else {
449 0 push @plain_args, "[$arg]";
450 0 push @pod_args , qq#[I<L<$arg|/"$arg_spec_to_opts{$arg0}">>]#;
451 }
452 0 ▶ $plain_args[-1] .= " ..." if ($arg_spec->{slurpy} // $arg_spec->{greedy});
Branch: 1 branch
BranchTrueFalseTotal
if $arg_spec->{"slurpy"} // $arg_spec->{"greedy"} 0 0 0
Condition0%0/3
$arg_spec->{"slurpy"} // $arg_spec->{"greedy"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg_spec->{"slurpy"} // $arg_spec->{"greedy"}
$arg_spec->{"slurpy"} $arg_spec->{"greedy"}
Truth table0%0/3
A // B
A= $arg_spec->{"slurpy"}B= $arg_spec->{"greedy"}
ABresult
1X1
011
000
453 0 ▶ $pod_args [-1] .= " ..." if ($arg_spec->{slurpy} // $arg_spec->{greedy});
Branch: 1 branch
BranchTrueFalseTotal
if $arg_spec->{"slurpy"} // $arg_spec->{"greedy"} 0 0 0
Condition0%0/3
$arg_spec->{"slurpy"} // $arg_spec->{"greedy"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg_spec->{"slurpy"} // $arg_spec->{"greedy"}
$arg_spec->{"slurpy"} $arg_spec->{"greedy"}
Truth table0%0/3
A // B
A= $arg_spec->{"slurpy"}B= $arg_spec->{"greedy"}
ABresult
1X1
011
000
454 0 delete $args_prop{$arg};
455 }
456  
457 # XXX utilize information from args_rels
458  
459 0 require Getopt::Long::Util;
460 0 require Module::Installed::Tiny;
461 0 my @plain_opts;
462 my @pod_opts;
463 0 my %opt_locations; # key=$ARGNAME or "common:$SOMEKEY"
464 0 for my $ospec (sort {
465 ($ggls_res->[3]{'func.specmeta'}{$a}{is_neg} ? 1:0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{is_neg} ? 1:0) ||
466 ($ggls_res->[3]{'func.specmeta'}{$a}{is_alias} ? 1:0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{is_alias} ? 1:0) ||
467 ($ggls_res->[3]{'func.specmeta'}{$a}{is_json} ? 1:0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{is_json} ? 1:0) ||
468 0 ▶ ($ggls_res->[3]{'func.specmeta'}{$a}{is_yaml} ? 1:0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{is_yaml} ? 1:0) ||
Branch: 8 branches
BranchTrueFalseTotal
$ggls_res->[3]{'func.specmeta'}{$a}{'is_neg'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$b}{'is_neg'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$a}{'is_alias'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$b}{'is_alias'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$a}{'is_json'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$b}{'is_json'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$a}{'is_yaml'} ? : 0 0 0
$ggls_res->[3]{'func.specmeta'}{$b}{'is_yaml'} ? : 0 0 0
Condition0%0/12
($ggls_res->[3]{'func.specmeta'}{$a}{'is_neg'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_neg'} ? 1 : 0) || ($ggls_res->[3]{'func.specmeta'}{$a}{'is_alias'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_alias'} ? 1 : 0) || ($ggls_res->[3]{'func.specmeta'}{$a}{'is_json'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_json'} ? 1 : 0) || ($ggls_res->[3]{'func.specmeta'}{$a}{'is_yaml'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_yaml'} ? 1 : 0) || $a cmp $b
l!l&&r!l&&!r
000
($ggls_res->[3]{"func.specmeta"}{$a}{"is_neg"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_neg"} ? 1 : 0) or ($ggls_res->[3]{"func.specmeta"}{$a}{"is_alias"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_alias"} ? 1 : 0) or ($ggls_res->[3]{"func.specmeta"}{$a}{"is_json"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_json"} ? 1 : 0) or ($ggls_res->[3]{"func.specmeta"}{$a}{"is_yaml"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_yaml"} ? 1 : 0)
l!l&&r!l&&!r
000
($ggls_res->[3]{"func.specmeta"}{$a}{"is_neg"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_neg"} ? 1 : 0) or ($ggls_res->[3]{"func.specmeta"}{$a}{"is_alias"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_alias"} ? 1 : 0) or ($ggls_res->[3]{"func.specmeta"}{$a}{"is_json"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_json"} ? 1 : 0)
l!l&&r!l&&!r
000
($ggls_res->[3]{"func.specmeta"}{$a}{"is_neg"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_neg"} ? 1 : 0) or ($ggls_res->[3]{"func.specmeta"}{$a}{"is_alias"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_alias"} ? 1 : 0)
l!l&&r!l&&!r
000
MC/DC0%0/5
($ggls_res->[3]{'func.specmeta'}{$a}{'is_neg'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_neg'} ? 1 : 0) || ($ggls_res->[3]{'func.specmeta'}{$a}{'is_alias'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_alias'} ? 1 : 0) || ($ggls_res->[3]{'func.specmeta'}{$a}{'is_json'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_json'} ? 1 : 0) || ($ggls_res->[3]{'func.specmeta'}{$a}{'is_yaml'} ? 1 : 0) <=> ($ggls_res->[3]{'func.specmeta'}{$b}{'is_yaml'} ? 1 : 0) || $a cmp $b
($ggls_res->[3]{"func.specmeta"}{$a}{"is_neg"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_neg"} ? 1 : 0) ($ggls_res->[3]{"func.specmeta"}{$a}{"is_alias"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_alias"} ? 1 : 0) ($ggls_res->[3]{"func.specmeta"}{$a}{"is_json"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_json"} ? 1 : 0) ($ggls_res->[3]{"func.specmeta"}{$a}{"is_yaml"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_yaml"} ? 1 : 0) $a cmp $b
Truth table0%0/6
A or B or C or D || E
A= ($ggls_res->[3]{"func.specmeta"}{$a}{"is_neg"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_neg"} ? 1 : 0)B= ($ggls_res->[3]{"func.specmeta"}{$a}{"is_alias"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_alias"} ? 1 : 0)C= ($ggls_res->[3]{"func.specmeta"}{$a}{"is_json"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_json"} ? 1 : 0)D= ($ggls_res->[3]{"func.specmeta"}{$a}{"is_yaml"} ? 1 : 0) <=> ($ggls_res->[3]{"func.specmeta"}{$b}{"is_yaml"} ? 1 : 0)E= $a cmp $b
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
469 $a cmp $b
470 0 } keys %{ $ggls_res->[3]{'func.specmeta'} }) {
471 0 my $ospecmeta = $ggls_res->[3]{'func.specmeta'}{$ospec};
472  
473 0 ▶ my $argprop = defined $ospecmeta->{arg} ? $args_prop{ $ospecmeta->{arg} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ospecmeta->{'arg'} ? : 0 0 0
474 # only include args that have not been mentioned in positional
475 0 ▶ next if defined $ospecmeta->{arg} && !$argprop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ospecmeta->{"arg"} and not $argprop 0 0 0
Condition0%0/3
defined $ospecmeta->{"arg"} and not $argprop
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ospecmeta->{"arg"} and not $argprop
defined $ospecmeta->{"arg"} not $argprop
Truth table0%0/3
A and not(B)
A= defined $ospecmeta->{"arg"}B= not $argprop
ABresult
0X0
100
111
476 # only inlude common options that are not a specific action that are
477 # invoked on its own
478  
479 0 ▶ my $copt = defined $ospecmeta->{common_opt} ? $common_opts->{ $ospecmeta->{common_opt} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ospecmeta->{'common_opt'} ? : 0 0 0
480  
481 0 ▶ next if defined $ospecmeta->{common_opt} && $copt->{usage};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ospecmeta->{"common_opt"} and $copt->{"usage"} 0 0 0
Condition0%0/3
defined $ospecmeta->{"common_opt"} and $copt->{"usage"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ospecmeta->{"common_opt"} and $copt->{"usage"}
defined $ospecmeta->{"common_opt"} $copt->{"usage"}
Truth table0%0/3
A and B
A= defined $ospecmeta->{"common_opt"}B= $copt->{"usage"}
ABresult
0X0
100
111
482 0 my ($caption_from_schema, $type, $cset);
483 0 ▶ if ($argprop && $argprop->{schema} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($argprop and $argprop->{"schema"} and ref $argprop->{"schema"} eq "ARRAY") 0 0 0
Condition0%0/6
$argprop and $argprop->{"schema"} and ref $argprop->{"schema"} eq "ARRAY"
!ll&&!rl&&r
000
$argprop and $argprop->{"schema"}
!ll&&!rl&&r
000
MC/DC0%0/3
$argprop and $argprop->{"schema"} and ref $argprop->{"schema"} eq "ARRAY"
$argprop $argprop->{"schema"} ref $argprop->{"schema"} eq "ARRAY"
Truth table0%0/4
A and B and C
A= $argpropB= $argprop->{"schema"}C= ref $argprop->{"schema"} eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
484 ref $argprop->{schema} eq 'ARRAY' # ignore non-normalized schema for now
485 ) {
486 0 $type = $argprop->{schema}[0];
487 0 $cset = $argprop->{schema}[1];
488 #log_trace "argprop=%s, type=%s", $argprop, $type;
489 0 ▶ if ($type eq 'array') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'array') { } 0 0 0
elsif ($type eq 'hash') { } 0 0 0
490 0 ▶ if ($cset->{of} && ref $cset->{of} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cset->{"of"} and ref $cset->{"of"} eq "ARRAY") 0 0 0
Condition0%0/3
$cset->{"of"} and ref $cset->{"of"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$cset->{"of"} and ref $cset->{"of"} eq "ARRAY"
$cset->{"of"} ref $cset->{"of"} eq "ARRAY"
Truth table0%0/3
A and B
A= $cset->{"of"}B= ref $cset->{"of"} eq "ARRAY"
ABresult
0X0
100
111
491 0 $caption_from_schema = $cset->{of}[0];
492 }
493 } elsif ($type eq 'hash') {
494 0 ▶ if ($cset->{of} && ref $cset->{of} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cset->{"of"} and ref $cset->{"of"} eq "ARRAY") 0 0 0
Condition0%0/3
$cset->{"of"} and ref $cset->{"of"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$cset->{"of"} and ref $cset->{"of"} eq "ARRAY"
$cset->{"of"} ref $cset->{"of"} eq "ARRAY"
Truth table0%0/3
A and B
A= $cset->{"of"}B= ref $cset->{"of"} eq "ARRAY"
ABresult
0X0
100
111
495 0 $caption_from_schema = $cset->{of}[0];
496 }
497 } else {
498 0 $caption_from_schema = $type;
499 }
500 }
501 #use DDC; dd $ospec; dd $ospecmeta;
502 my $opt_link =
503 defined $ospecmeta->{arg} ? $arg_spec_to_opts{ $ospecmeta->{arg} } :
504 defined $ospecmeta->{alias_for} ? $ospec_to_opts{ $ospecmeta->{alias_for} } :
505 0 ▶ $ospec_to_opts{$ospec};
Branch: 2 branches
BranchTrueFalseTotal
defined $ospecmeta->{'arg'} ? : 0 0 0
defined $ospecmeta->{'alias_for'} ? : 0 0 0
506 my $hres = Getopt::Long::Util::humanize_getopt_long_opt_spec({
507 extended=>1,
508 separator=>"|",
509 value_label=>(
510 $ospecmeta->{is_json} ? 'json' :
511 $ospecmeta->{is_yaml} ? 'yaml' :
512 $argprop ?
513 ($argprop->{'x.cli.opt_value_label'} // $argprop->{caption} // $caption_from_schema) :
514 $copt->{value_label}
515 ),
516 opt_link => qq#/"$opt_link"#,
517 value_label_link=>(
518 $ospecmeta->{is_json} ? undef :
519 $ospecmeta->{is_yaml} ? undef :
520 0 ▶ defined($caption_from_schema) && Module::Installed::Tiny::module_installed("Sah::Schema::$caption_from_schema") ? "Sah::Schema::$caption_from_schema" : undef
Branch: 6 branches
BranchTrueFalseTotal
$ospecmeta->{'is_json'} ? : 0 0 0
$ospecmeta->{'is_yaml'} ? : 0 0 0
$argprop ? : 0 0 0
$ospecmeta->{'is_json'} ? : 0 0 0
$ospecmeta->{'is_yaml'} ? : 0 0 0
defined $caption_from_schema && Module::Installed::Tiny::module_installed("Sah::Schema::$caption_from_schema") ? : 0 0 0
Condition0%0/9
($argprop->{"x.cli.opt_value_label"} // $argprop->{"caption"}) // $caption_from_schema
l!l&&r!l&&!r
000
$argprop->{"x.cli.opt_value_label"} // $argprop->{"caption"}
l!l&&r!l&&!r
000
defined $caption_from_schema and Module::Installed::Tiny::module_installed("Sah::Schema::$caption_from_schema")
!ll&&!rl&&r
000
MC/DC0%0/3
($argprop->{"x.cli.opt_value_label"} // $argprop->{"caption"}) // $caption_from_schema
$argprop->{"x.cli.opt_value_label"} $argprop->{"caption"} $caption_from_schema
MC/DC0%0/2
defined $caption_from_schema and Module::Installed::Tiny::module_installed("Sah::Schema::$caption_from_schema")
defined $caption_from_schema Module::Installed::Tiny::module_installed("Sah::Schema::$caption_from_schema")
Truth table0%0/4
A // B // C
A= $argprop->{"x.cli.opt_value_label"}B= $argprop->{"caption"}C= $caption_from_schema
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/3
A and B
A= defined $caption_from_schemaB= Module::Installed::Tiny::module_installed("Sah::Schema::$caption_from_schema")
ABresult
0X0
100
111
521 ),
522 }, $ospec);
523 0 my $plain_opt = $hres->{plaintext};
524 0 my $pod_opt = $hres->{pod};
525  
526 0 my $key;
527 0 ▶ if ($copt && defined $copt->{key}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($copt and defined $copt->{'key'}) { } 0 0 0
elsif (defined $ospecmeta->{'arg'}) { } 0 0 0
Condition0%0/3
$copt and defined $copt->{"key"}
!ll&&!rl&&r
000
MC/DC0%0/2
$copt and defined $copt->{"key"}
$copt defined $copt->{"key"}
Truth table0%0/3
A and B
A= $coptB= defined $copt->{"key"}
ABresult
0X0
100
111
528 # group common options by key.
529 0 $key = "00common:" . $copt->{key};
530 } elsif (defined $ospecmeta->{arg}) {
531 0 $key = $ospecmeta->{arg};
532 } else {
533 0 $key = $ospec;
534 0 $key =~ s/[=:].+\z//;
535 }
536 0 $key =~ s/_/-/g;
537  
538 #say "D:ospec=$ospec -> key=$key, ospecmeta->{arg}=$ospecmeta->{arg}";
539  
540 0 ▶ $opt_locations{$key} //= scalar @plain_opts;
Condition0%0/2
$opt_locations{$key} //= scalar @plain_opts
l!l
00
MC/DC0%0/1
$opt_locations{$key} //= scalar @plain_opts
$opt_locations{$key}
Truth table0%0/2
A
A= $opt_locations{$key}
Aresult
11
00
541 0 push @{ $plain_opts[ $opt_locations{$key} ] }, $plain_opt;
542 0 push @{ $pod_opts [ $opt_locations{$key} ] }, $pod_opt;
543 #use Data::Dmp; print "key: $key, ospec: $ospec, ospecmeta: ", dmp($ospecmeta), ", argprop: ", dmp($argprop), ", copt: ", dmp($copt), "\n";
544 }
545  
546 0 ▶ $clidocdata->{compact_usage_line} = "[[prog]]".
Branch: 2 branches
BranchTrueFalseTotal
keys %args_prop || keys %$common_opts ? : 0 0 0
@plain_args ? : 0 0 0
Condition0%0/3
keys %args_prop or keys %$common_opts
l!l&&r!l&&!r
000
MC/DC0%0/2
keys %args_prop or keys %$common_opts
keys %args_prop keys %$common_opts
Truth table0%0/3
A or B
A= keys %args_propB= keys %$common_opts
ABresult
1X1
011
000
547 (keys(%args_prop) || keys(%$common_opts) ? " [options]" : ""). # XXX translatable?
548 (@plain_args ? " ".join(" ", @plain_args) : "");
549 $clidocdata->{usage_line} = "[[prog]]".
550 (@plain_opts+@plain_args ? " ".
551 join(" ",
552 0 ▶ (map { "[". join("|", @$_) . "]" } @plain_opts),
Branch: 2 branches
BranchTrueFalseTotal
@plain_opts + @plain_args ? : 0 0 0
@plain_opts && @plain_args ? : 0 0 0
Condition0%0/3
@plain_opts and @plain_args
!ll&&!rl&&r
000
MC/DC0%0/2
@plain_opts and @plain_args
@plain_opts @plain_args
Truth table0%0/3
A and B
A= @plain_optsB= @plain_args
ABresult
0X0
100
111
553 (@plain_opts && @plain_args ? ("--") : ()),
554 @plain_args,
555 ) : "");
556 $clidocdata->{'usage_line.alt.fmt.pod'} = "B<[[prog]]>".
557 (@pod_opts+@pod_args ? " ".
558 join(" ",
559 0 ▶ (map { "[". join("|", @$_) . "]" } @pod_opts),
Branch: 2 branches
BranchTrueFalseTotal
@pod_opts + @pod_args ? : 0 0 0
@pod_opts && @pod_args ? : 0 0 0
Condition0%0/3
@pod_opts and @pod_args
!ll&&!rl&&r
000
MC/DC0%0/2
@pod_opts and @pod_args
@pod_opts @pod_args
Truth table0%0/3
A and B
A= @pod_optsB= @pod_args
ABresult
0X0
100
111
560 (@pod_opts && @pod_args ? ("--") : ()),
561 @pod_args,
562 ) : "");
563 } # GEN_USAGE_LINE
564  
565 # filter and format examples
566 0 my @examples;
567 {
568 0 ▶ my $examples = $meta->{examples} // [];
Condition0%0/2
$meta->{"examples"} // []
l!l
00
MC/DC0%0/1
$meta->{"examples"} // []
$meta->{"examples"}
Truth table0%0/2
A
A= $meta->{"examples"}
Aresult
11
00
569 0 my $has_cats = _has_cats($examples);
570  
571 0 for my $eg (@$examples) {
572 0 my $rimeta = rimeta($eg);
573 0 my $argv;
574 my $cmdline;
575 0 ▶ if (defined($eg->{src})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $eg->{'src'}) { } 0 0 0
576 # we only show shell command examples
577 0 ▶ if ($eg->{src_plang} =~ /^(sh|bash)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eg->{'src_plang'} =~ /^(sh|bash)$/) { } 0 0 0
578 0 $cmdline = $eg->{src};
579 } else {
580 0 next;
581 }
582 } else {
583 0 require String::ShellQuote;
584 0 ▶ if ($eg->{argv}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eg->{'argv'}) { } 0 0 0
585 0 $argv = $eg->{argv};
586 } else {
587 0 require Perinci::Sub::ConvertArgs::Argv;
588 my $res = Perinci::Sub::ConvertArgs::Argv::convert_args_to_argv(
589 0 args => $eg->{args}, meta => $meta, use_pos => 1);
590 0 ▶ return err($res, 500, "Can't convert args to argv")
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
591 unless $res->[0] == 200;
592 0 $argv = $res->[2];
593 }
594 0 $cmdline = "[[prog]]";
595 0 for my $arg (@$argv) {
596 0 my $qarg = String::ShellQuote::shell_quote($arg);
597 0 $cmdline .= " $qarg"; # XXX markup with color?
598 }
599 }
600 0 my $egdata = {
601 cmdline => $cmdline,
602 summary => $rimeta->langprop($langprop_args, 'summary'),
603 description => $rimeta->langprop($langprop_args, 'description'),
604 example_spec => $eg,
605 };
606 # XXX show result from $eg
607 _add_category_from_spec($clidocdata->{example_categories},
608 0 $egdata, $eg, "examples", $has_cats);
609 0 push @examples, $egdata;
610 }
611 }
612 0 $clidocdata->{examples} = \@examples;
613  
614 0 [200, "OK", $clidocdata];
615 }
616  
617 1 1;
618 # ABSTRACT: From Rinci function metadata, generate structure convenient for producing CLI documentation (help/usage/POD)
619  
620 __END__
↑ Summary