blib/lib/Complete/Fish/Gen/FromGetoptLongDescriptive.pm

filter: Statementstmt 36.1% 17 / 47 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 2 / 2 totaltotal 32.8% 22 / 67 CC 9 SCAR 31.8
CC
9
Cov
29%
gen_fish_complete_from_getopt_long_descriptive_spec
42.0
gen_fish_complete_from_getopt_long_descriptive_script
20.0
__ANON__
2.0
CRAP 24.1
↑ Summary
1 package Complete::Fish::Gen::FromGetoptLongDescriptive;
2  
3 1 our $DATE = '2016-10-27'; # DATE
4 1 our $VERSION = '0.001'; # VERSION
5  
6 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our %SPEC;
11  
12 1 require Exporter;
13 1 our @ISA = qw(Exporter);
14 1 our @EXPORT_OK = qw(
15 gen_fish_complete_from_getopt_long_descriptive_script
16 gen_fish_complete_from_getopt_long_descriptive_spec
17 );
18  
19 $SPEC{gen_fish_complete_from_getopt_long_descriptive_spec} = {
20 1 v => 1.1,
21 summary => 'From Getopt::Long::Descriptive spec, generate tab completion '.
22 'commands for the fish shell',
23 description => <<'_',
24  
25 This routine generate fish `complete` command for each short/long option,
26 enabling fish to display the options in a different color.
27  
28 _
29 args => {
30 spec => {
31 summary => 'Getopt::Long::Descriptive specification',
32 schema => 'array*',
33 req => 1,
34 pos => 0,
35 },
36 cmdname => {
37 summary => 'Command name to be completed',
38 schema => 'str*',
39 req => 1,
40 },
41 compname => {
42 summary => 'Completer name, if there is a completer for option values',
43 schema => 'str*',
44 },
45 },
46 result => {
47 schema => 'str*',
48 summary => 'A script that can be fed to the fish shell',
49 },
50 };
51 0 ▶sub gen_fish_complete_from_getopt_long_descriptive_spec {
Subroutine gen_fish_complete_from_getopt_long_descriptive_spec: not called CC=6 SCAR=37.4
Pod documented
52 0 my %args = @_;
53  
54 0 ▶ my $gldspec = $args{spec} or return [400, "Please specify 'spec'"];
Branch: 1 branch
BranchTrueFalseTotal
my $gldspec = $args{"spec"} or return [400, "Please specify 'spec'"] 0 0 0
55  
56 0 require Getopt::Long::Util;
57 0 my $glspec = {};
58 0 my $opt_desc = {};
59  
60 0 for my $i (0..$#{$gldspec}) {
61 0 ▶ next if !$i; # first argument is program usage
Branch: 1 branch
BranchTrueFalseTotal
unless $i 0 0 0
62 0 my $ospec = $gldspec->[$i];
63 0 ▶ next unless @$ospec;
Branch: 1 branch
BranchTrueFalseTotal
unless @$ospec 0 0 0
64 0 my ($glospec, $desc) = @$ospec;
65 0 my $parsed = Getopt::Long::Util::parse_getopt_long_opt_spec($glospec);
66 0 ▶ $glspec->{$glospec} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 for my $o (@{ $parsed->{opts} }) {
68 0 $opt_desc->{$o} = $desc;
69 }
70 }
71  
72 0 require Complete::Fish::Gen::FromGetoptLong;
73 Complete::Fish::Gen::FromGetoptLong::gen_fish_complete_from_getopt_long_spec(
74 spec => $glspec,
75 opt_desc => $opt_desc,
76 cmdname => $args{cmdname},
77 compname => $args{compname},
78 0 );
79 }
80  
81 $SPEC{gen_fish_complete_from_getopt_long_descriptive_script} = {
82 1 v => 1.1,
83 summary => 'Generate fish completion script from Getopt::Long::Descriptive script',
84 description => <<'_',
85  
86 This routine generate fish `complete` command for each short/long option,
87 enabling fish to display the options in a different color.
88  
89 _
90 args => {
91 filename => {
92 schema => 'filename*',
93 req => 1,
94 pos => 0,
95 cmdline_aliases => {f=>{}},
96 },
97 cmdname => {
98 summary => 'Command name to be completed, defaults to filename',
99 schema => 'str*',
100 },
101 compname => {
102 summary => 'Completer name',
103 schema => 'str*',
104 },
105 skip_detect => {
106 schema => ['bool', is=>1],
107 cmdline_aliases => {D=>{}},
108 },
109 },
110 result => {
111 schema => 'str*',
112 summary => 'A script that can be fed to the fish shell',
113 },
114 };
115 0 ▶sub gen_fish_complete_from_getopt_long_descriptive_script {
Subroutine gen_fish_complete_from_getopt_long_descriptive_script: not called CC=4 SCAR=30.0
Pod documented
116 0 my %args = @_;
117  
118 0 my $filename = $args{filename};
119 0 ▶ return [404, "No such file or not a file: $filename"] unless -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 0 0
120  
121 0 require Getopt::Long::Descriptive::Dump;
122 my $dump_res = Getopt::Long::Descriptive::Dump::dump_getopt_long_descriptive_script(
123 filename => $filename,
124 skip_detect => $args{skip_detect},
125 0 );
126 0 ▶ return $dump_res unless $dump_res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $dump_res->[0] == 200 0 0 0
127  
128 0 my $cmdname = $args{cmdname};
129 0 ▶ if (!$cmdname) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmdname) 0 0 0
130 0 ($cmdname = $filename) =~ s!.+/!!;
131 }
132 0 my $compname = $args{compname};
133  
134 0 my $gldspec = $dump_res->[2];
135  
136 0 gen_fish_complete_from_getopt_long_descriptive_spec(
137 spec => $gldspec,
138 cmdname => $cmdname,
139 compname => $compname,
140 );
141 }
142  
143 1 1;
144 # ABSTRACT: Generate fish completion script from Getopt::Long::Descriptive spec/script
145  
146 __END__
↑ Summary