Skip to content

Commit da72ef9

Browse files
committed
Support summaries with multiple lines
1 parent 89bbaa4 commit da72ef9

19 files changed

+225
-27
lines changed

examples/bash/myapp.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bash
1+
#!/usr/bin/env bash
22

33
# Generated with perl module App::Spec v0.000
44

examples/bash/mysimpleapp.bash

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bash
1+
#!/usr/bin/env bash
22

33
# Generated with perl module App::Spec v0.000
44

@@ -15,8 +15,14 @@ _mysimpleapp() {
1515
local INDEX=`expr $cword - 1`
1616
MYWORDS=("${words[@]:1:$cword}")
1717

18-
FLAGS=('--verbose' 'be verbose' '-v' 'be verbose' '--wc' 'word count' '--lc' 'line count' '--help' 'Show command help' '-h' 'Show command help')
19-
OPTIONS=('--with' 'with ...' '--file1' 'existing file' '--file2' 'possible file' '--dir1' 'existing dir' '--dir2' 'possible dir')
18+
FLAGS=('--verbose' 'be verbose' '-v' 'be verbose' '--wc' 'word count' '--lc' 'line count' '--longoption' 'some long option description
19+
split over several lines to
20+
demonstrate
21+
' '--help' 'Show command help' '-h' 'Show command help')
22+
OPTIONS=('--with' 'with ...' '--file1' 'existing file' '--file2' 'possible file' '--dir1' 'existing dir' '--dir2' 'possible dir' '--longoption2' 'some other long option
23+
description split over several
24+
lines to demonstrate
25+
')
2026
__mysimpleapp_handle_options_flags
2127

2228
case ${MYWORDS[$INDEX-1]} in
@@ -40,6 +46,8 @@ _mysimpleapp() {
4046
compopt -o dirnames
4147
return
4248
;;
49+
--longoption2)
50+
;;
4351

4452
esac
4553
case $INDEX in

examples/bash/nometa.bash

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bash
1+
#!/usr/bin/env bash
22

33
# Generated with perl module App::Spec v0.000
44

@@ -23,7 +23,10 @@ _nometa() {
2323

2424
0)
2525
__comp_current_options || return
26-
__nometa_dynamic_comp 'commands' 'foo'$'\t''Test command'$'\n''help'$'\t''Show command help'
26+
__nometa_dynamic_comp 'commands' 'foo'$'\t''Test command'$'\n''help'$'\t''Show command help'$'\n''longsubcommand'$'\t''A subcommand with a
27+
very long summary split
28+
over multiple lines
29+
'
2730

2831
;;
2932
*)
@@ -53,7 +56,7 @@ _nometa() {
5356

5457
1)
5558
__comp_current_options || return
56-
__nometa_dynamic_comp 'commands' 'foo'
59+
__nometa_dynamic_comp 'commands' 'foo'$'\n''longsubcommand'
5760

5861
;;
5962
*)
@@ -63,8 +66,28 @@ _nometa() {
6366
__nometa_handle_options_flags
6467
__comp_current_options true || return # no subcmds, no params/opts
6568
;;
69+
longsubcommand)
70+
__nometa_handle_options_flags
71+
__comp_current_options true || return # no subcmds, no params/opts
72+
;;
73+
esac
74+
75+
;;
76+
esac
77+
;;
78+
longsubcommand)
79+
__nometa_handle_options_flags
80+
case ${MYWORDS[$INDEX-1]} in
81+
6682
esac
83+
case $INDEX in
84+
1)
85+
__comp_current_options || return
86+
;;
87+
6788

89+
*)
90+
__comp_current_options || return
6891
;;
6992
esac
7093
;;

examples/bash/pcorelist.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bash
1+
#!/usr/bin/env bash
22

33
# Generated with perl module App::Spec v0.000
44

examples/bash/subrepo.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bash
1+
#!/usr/bin/env bash
22

33
# Generated with perl module App::Spec v0.000
44

examples/html/mysimpleapp.html

+15-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,21 @@ <h1 id="DESCRIPTION">DESCRIPTION</h1>
3434

3535
<h2 id="GLOBAL-OPTIONS">GLOBAL OPTIONS</h2>
3636

37-
<pre><code> --verbose -v [] be verbose (flag; multiple)
38-
--wc word count (flag)
39-
--lc line count (flag)
40-
--with with ...
41-
--help -h Show command help (flag) </code></pre>
37+
<pre><code> --verbose -v [] be verbose (flag; multiple)
38+
--wc word count (flag)
39+
--lc line count (flag)
40+
--with with ...
41+
--file1 existing file
42+
--file2 possible file
43+
--dir1 existing dir
44+
--dir2 possible dir
45+
--longoption some long option description (flag)
46+
split over several lines to
47+
demonstrate
48+
--longoption2 some other long option
49+
description split over several
50+
lines to demonstrate
51+
--help -h Show command help (flag) </code></pre>
4252

4353
<h2 id="SUBCOMMANDS">SUBCOMMANDS</h2>
4454

examples/html/nometa.html

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<li><a href="#SUBCOMMANDS">SUBCOMMANDS</a>
2121
<ul>
2222
<li><a href="#foo">foo</a></li>
23+
<li><a href="#longsubcommand">longsubcommand</a></li>
2324
<li><a href="#help">help</a></li>
2425
</ul>
2526
</li>
@@ -51,6 +52,18 @@ <h3 id="foo">foo</h3>
5152

5253
<pre><code> test * </code></pre>
5354

55+
<h3 id="longsubcommand">longsubcommand</h3>
56+
57+
<pre><code> nometa longsubcommand [&lt;longparam&gt;]</code></pre>
58+
59+
<p>A subcommand with a very long summary split over multiple lines</p>
60+
61+
<p>Parameters:</p>
62+
63+
<pre><code> longparam A parameter with a
64+
very long summary split
65+
over multiple lines </code></pre>
66+
5467
<h3 id="help">help</h3>
5568

5669
<pre><code> nometa help &lt;subcommands&gt; [options]</code></pre>

examples/mysimpleapp-spec.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ options:
3232
- name: dir2
3333
summary: possible dir
3434
type: dirname
35+
- |
36+
longoption --some long option description
37+
split over several lines to
38+
demonstrate
39+
- name: longoption2
40+
summary: |
41+
some other long option
42+
description split over several
43+
lines to demonstrate
3544
3645
parameters:
3746
- name: foo

examples/nometa-spec.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,16 @@ subcommands:
1414
type: string
1515
required: true
1616
enum: [a, b, c]
17+
longsubcommand:
18+
summary: |
19+
A subcommand with a
20+
very long summary split
21+
over multiple lines
22+
parameters:
23+
- name: longparam
24+
summary: |
25+
A parameter with a
26+
very long summary split
27+
over multiple lines
1728
1829
# vim:et:sts=2:sws=2:sw=2:foldmethod=indent

examples/pod/mysimpleapp.pod

+15-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ Just a very simple example app to document some features
1212

1313
=head2 GLOBAL OPTIONS
1414

15-
--verbose -v [] be verbose (flag; multiple)
16-
--wc word count (flag)
17-
--lc line count (flag)
18-
--with with ...
19-
--help -h Show command help (flag)
15+
--verbose -v [] be verbose (flag; multiple)
16+
--wc word count (flag)
17+
--lc line count (flag)
18+
--with with ...
19+
--file1 existing file
20+
--file2 possible file
21+
--dir1 existing dir
22+
--dir2 possible dir
23+
--longoption some long option description (flag)
24+
split over several lines to
25+
demonstrate
26+
--longoption2 some other long option
27+
description split over several
28+
lines to demonstrate
29+
--help -h Show command help (flag)
2030

2131

2232
=head2 SUBCOMMANDS

examples/pod/nometa.pod

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ Parameters:
2727

2828
test *
2929

30+
=head3 longsubcommand
31+
32+
nometa longsubcommand [<longparam>]
33+
34+
A subcommand with a
35+
very long summary split
36+
over multiple lines
37+
38+
39+
Parameters:
40+
41+
longparam A parameter with a
42+
very long summary split
43+
over multiple lines
44+
3045
=head3 help
3146

3247
nometa help <subcommands> [options]

examples/zsh/_mysimpleapp

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ _mysimpleapp() {
2121
'--file2[possible file]:file2:_files' \
2222
'--dir1[existing dir]:dir1:_path_files -/' \
2323
'--dir2[possible dir]:dir2:_path_files -/' \
24+
'--longoption[some long option description
25+
split over several lines to
26+
demonstrate
27+
]' \
28+
'--longoption2[some other long option
29+
description split over several
30+
lines to demonstrate
31+
]:longoption2' \
2432
'--help[Show command help]' \
2533
'-h[Show command help]' \
2634
&& ret=0

examples/zsh/_nometa

+35-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ _nometa() {
1717

1818
case $state in
1919
cmd1)
20-
_alternative 'args:cmd2:((foo\:"Test command" help\:"Show command help"))'
20+
_alternative 'args:cmd2:((foo\:"Test command" help\:"Show command help" longsubcommand\:"A subcommand with a
21+
very long summary split
22+
over multiple lines
23+
"))'
2124
;;
2225

2326
args)
@@ -51,7 +54,7 @@ _nometa() {
5154

5255
case $state in
5356
cmd2)
54-
_alternative 'args:cmd3:((foo))'
57+
_alternative 'args:cmd3:((foo longsubcommand))'
5558
;;
5659

5760
args)
@@ -68,13 +71,43 @@ _nometa() {
6871
&& ret=0
6972

7073

74+
;;
75+
longsubcommand)
76+
77+
# ---- Command: help longsubcommand
78+
_arguments -s -C \
79+
'1: :->cmd1' \
80+
'2: :->cmd2' \
81+
'--help[Show command help]' \
82+
'-h[Show command help]' \
83+
'--all[]' \
84+
&& ret=0
85+
86+
7187
;;
7288
esac
7389

7490
;;
7591

7692
esac
7793
;;
94+
longsubcommand)
95+
96+
# ---- Command: longsubcommand
97+
_arguments -s -C \
98+
'1: :->cmd1' \
99+
'2: :->longparam' \
100+
'--help[Show command help]' \
101+
'-h[Show command help]' \
102+
&& ret=0
103+
104+
case $state in
105+
longparam)
106+
107+
;;
108+
esac
109+
110+
;;
78111
esac
79112

80113
;;

lib/App/Spec.pm

+9-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ EOM
8686
for my $name (@keys) {
8787
my $cmd_spec = $subcmds->{ $name };
8888
my $summary = $cmd_spec->summary;
89-
push @table, [$name, $summary];
89+
my @lines = split m/\n/, $summary;
90+
push @table, [$name, $lines[0] // ''];
91+
push @table, ['', $_] for map { s/^ +//; $_ } @lines[1 .. $#lines];
9092
if (length $name > $maxlength) {
9193
$maxlength = length $name;
9294
}
@@ -121,7 +123,9 @@ EOM
121123

122124
my $flags = $self->_param_flags_string($param);
123125

124-
push @table, [$name, $req, $multi, $summary . $flags];
126+
my @lines = split m/\n/, $summary;
127+
push @table, [$name, $req, $multi, ($lines[0] // '') . $flags];
128+
push @table, ['', ' ', ' ', $_] for map { s/^ +//; $_ } @lines[1 .. $#lines];
125129
if (length $name > $maxlength) {
126130
$maxlength = length $name;
127131
}
@@ -164,7 +168,9 @@ EOM
164168

165169
my $flags = $self->_param_flags_string($opt);
166170

167-
push @table, [$string, $req, $multi, $summary . $flags];
171+
my @lines = split m/\n/, $summary;
172+
push @table, [$string, $req, $multi, ($lines[0] // '') . $flags];
173+
push @table, ['', ' ', ' ', $_ ] for map { s/^ +//; $_ } @lines[1 .. $#lines];
168174
}
169175
my $options_string = $colored->([qw/ bold /], "Options:");
170176
$body .= "\n$options_string\n";

lib/App/Spec/Argument.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ sub from_dsl {
129129
}
130130
}
131131

132-
if ($dsl =~ s/^\s*--\s*(.*)//) {
132+
if ($dsl =~ s/^\s*--\s*(.*)//s) {
133133
# TODO only summary should be supported
134134
$hash{summary} = $1;
135135
}

lib/App/Spec/Pod.pm

+6-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ sub params2pod {
163163
$multi = '[]';
164164
}
165165
my $flags = $self->spec->_param_flags_string($param);
166-
push @rows, [" " . $param->name, " " . $required, $multi, $summary . $flags];
166+
my @lines = split m/\n/, $summary;
167+
push @rows, [" " . $param->name, " " . $required, $multi, ($lines[0] // '') . $flags];
168+
push @rows, [" " , " ", '', $_] for map {s/^ +//; $_ } @lines[1 .. $#lines];
167169
}
168170
my $test = $self->simple_table(\@rows);
169171
return $test;
@@ -212,7 +214,9 @@ sub options2pod {
212214
length $_ > 1 ? "--$_" : "-$_"
213215
} ($name, @$aliases);
214216
my $flags = $self->spec->_param_flags_string($opt);
215-
push @rows, [" @names", " " . $required, $multi, $summary . $flags];
217+
my @lines = split m/\n/, $summary;
218+
push @rows, [" @names", " " . $required, $multi, ($lines[0] // '') . $flags];
219+
push @rows, [" ", " " , '', $_ ] for map {s/^ +//; $_ } @lines[1 .. $#lines];
216220
}
217221
my $test = $self->simple_table(\@rows);
218222
return $test;

t/11.appspecrun.t

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use FindBin '$Bin';
55
use lib "$Bin/lib";
66
use App::Spec::Example::MyApp;
77
use App::Spec::Example::MySimpleApp;
8+
use App::Spec::Example::Nometa;
89
use App::Spec;
910
use YAML::PP;
1011
$ENV{PERL5_APPSPECRUN_COLOR} = 'never';

0 commit comments

Comments
 (0)