1
- use clap:: { crate_version, App , AppSettings , Arg , SubCommand } ;
1
+ use clap:: { crate_version, AppSettings , Arg , Command } ;
2
2
3
3
/// Generate cli argument parser without the `complete` subcommand.
4
- pub fn build_cli_nocomplete ( ) -> App < ' static > {
4
+ pub fn build_cli_nocomplete ( ) -> Command < ' static > {
5
5
let arg_limit =
6
- Arg :: with_name ( "limit" ) . long ( "limit" )
7
- . takes_value ( true )
8
- . default_value ( "10" )
9
- . help ( "Use the last N merge times to predict next merge time." ) ;
6
+ Arg :: new ( "limit" ) . long ( "limit" )
7
+ . takes_value ( true )
8
+ . default_value ( "10" )
9
+ . help ( "Use the last N merge times to predict next merge time." ) ;
10
10
let arg_pkg =
11
- Arg :: with_name ( "package" ) . takes_value ( true ) . help ( "Show only packages matching <package>." ) ;
12
- let arg_exact =
13
- Arg :: with_name ( "exact" ) . short ( 'e' )
14
- . long ( "exact" )
15
- . help ( "Match package with a string instead of a regex." )
16
- . long_help (
17
- "Match package with a string instead of a regex. \
11
+ Arg :: new ( "package" ) . takes_value ( true ) . help ( "Show only packages matching <package>." ) ;
12
+ let arg_exact = Arg :: new ( "exact" ) . short ( 'e' )
13
+ . long ( "exact" )
14
+ . help ( "Match package with a string instead of a regex." )
15
+ . long_help (
16
+ "Match package with a string instead of a regex. \
18
17
Regex is case-insensitive and matches on category/name (see \
19
18
https://docs.rs/regex/*/regex/#syntax). String is case-sentitive and \
20
19
matches on whole name, or whole category/name if it contains a /.",
20
+ ) ;
21
+ let arg_show_l =
22
+ Arg :: new ( "show" ) . short ( 's' )
23
+ . long ( "show" )
24
+ . value_name ( "h,m,u,s,a" )
25
+ . validator ( |s| find_invalid ( "hmusa" , & s) )
26
+ . default_value ( "m" )
27
+ . help ( "Show (h)eaders, (m)erges, (u)nmerges, (s)yncs, and/or (a)ll." )
28
+ . long_help (
29
+ "Show individual (m)erges, (u)nmerges, portage tree (s)yncs, \
30
+ or (a)ll of these (any letters combination).",
21
31
) ;
22
- let arg_show_l = Arg :: with_name ( "show" )
23
- . short ( 's' )
24
- . long ( "show" )
25
- . value_name ( "h,m,u,s,a" )
26
- . validator ( |s| find_invalid ( "hmusa" , & s) )
27
- . default_value ( "m" )
28
- . help ( "Show (h)eaders, (m)erges, (u)nmerges, (s)yncs, and/or (a)ll." )
29
- . long_help ( "Show individual (m)erges, (u)nmerges, portage tree (s)yncs, \
30
- or (a)ll of these (any letters combination).") ;
31
- let arg_show_s = Arg :: with_name ( "show" )
32
- . short ( 's' )
33
- . long ( "show" )
34
- . value_name ( "h,p,t,s,a" )
35
- . validator ( |s| find_invalid ( "hptsa" , & s) )
36
- . default_value ( "p" )
37
- . help ( "Show (h)eaders, (p)ackages, (t)otals, (s)yncs, and/or (a)ll." )
38
- . long_help ( "Show per-(p)ackage merges/unmerges, (t)otal merges/unmerges, \
39
- portage tree (s)yncs, or (a)ll of these (any letters combination).") ;
40
- let arg_group =
41
- Arg :: with_name ( "group" ) . short ( 'g' )
42
- . long ( "groupby" )
43
- . value_name ( "y,m,w,d" )
44
- . possible_values ( & [ "y" , "m" , "w" , "d" ] )
45
- . hide_possible_values ( true )
46
- . help ( "Group by (y)ear, (m)onth, (w)eek, or (d)ay." )
47
- . long_help (
48
- "Group by (y)ear, (m)onth, (w)eek, or (d)ay.\n \
32
+ let arg_show_s =
33
+ Arg :: new ( "show" ) . short ( 's' )
34
+ . long ( "show" )
35
+ . value_name ( "h,p,t,s,a" )
36
+ . validator ( |s| find_invalid ( "hptsa" , & s) )
37
+ . default_value ( "p" )
38
+ . help ( "Show (h)eaders, (p)ackages, (t)otals, (s)yncs, and/or (a)ll." )
39
+ . long_help (
40
+ "Show per-(p)ackage merges/unmerges, (t)otal merges/unmerges, \
41
+ portage tree (s)yncs, or (a)ll of these (any letters combination).",
42
+ ) ;
43
+ let arg_group = Arg :: new ( "group" ) . short ( 'g' )
44
+ . long ( "groupby" )
45
+ . value_name ( "y,m,w,d" )
46
+ . possible_values ( & [ "y" , "m" , "w" , "d" ] )
47
+ . hide_possible_values ( true )
48
+ . help ( "Group by (y)ear, (m)onth, (w)eek, or (d)ay." )
49
+ . long_help (
50
+ "Group by (y)ear, (m)onth, (w)eek, or (d)ay.\n \
49
51
The grouping key is displayed in the first column. \
50
52
Weeks start on monday and are formated as 'year-weeknumber'.",
51
- ) ;
52
- App :: new ( "emlop" )
53
+ ) ;
54
+ Command :: new ( "emlop" )
53
55
. version ( crate_version ! ( ) )
54
- . global_setting ( AppSettings :: ColoredHelp )
55
56
. global_setting ( AppSettings :: DeriveDisplayOrder )
56
- . global_setting ( AppSettings :: UnifiedHelpMessage )
57
- . setting ( AppSettings :: DisableHelpSubcommand )
58
- . setting ( AppSettings :: InferSubcommands )
59
- . setting ( AppSettings :: SubcommandRequiredElseHelp )
60
- // FIXME clap3 what's the equivalent ? .setting(AppSettings::VersionlessSubcommands)
57
+ . disable_help_subcommand ( true )
58
+ . infer_subcommands ( true )
59
+ . arg_required_else_help ( true )
61
60
. about ( "A fast, accurate, ergonomic EMerge LOg Parser.\n \
62
61
https://github.com/vincentdephily/emlop")
63
62
. after_help ( "Subcommands can be abbreviated down to a single letter.\n \
64
63
Subcommands have their own -h / --help.\n \
65
- Exit code is 0 if sucessful, 1 in case of errors (bad argument...), \
66
- 2 if search found nothing.")
67
- . help_message ( "Show short (-h) or detailed (--help) help." )
68
- . arg ( Arg :: with_name ( "utc" )
64
+ Exit code is 0 if sucessful, 1 if search found nothing, 2 in case of argument errors.")
65
+ . mut_arg ( "help" , |a| a. help ( "Show short (-h) or detailed (--help) help." ) )
66
+ . arg ( Arg :: new ( "utc" )
69
67
. long ( "utc" )
70
68
. global ( true )
71
69
. help ( "Parse/display dates in UTC instead of local time" ) )
72
- . arg ( Arg :: with_name ( "from" )
70
+ . arg ( Arg :: new ( "from" )
73
71
. value_name ( "date" )
74
72
. short ( 'f' )
75
73
. long ( "from" )
@@ -79,7 +77,7 @@ pub fn build_cli_nocomplete() -> App<'static> {
79
77
. long_help ( "Only parse log entries after <date>.\n \
80
78
Accepts formats like '2018-03-04', '2018-03-04 12:34:56', \
81
79
'2018-03-04T12:34', '1 year, 2 months', '10d', and unix timestamps.") )
82
- . arg ( Arg :: with_name ( "to" )
80
+ . arg ( Arg :: new ( "to" )
83
81
. value_name ( "date" )
84
82
. short ( 't' )
85
83
. long ( "to" )
@@ -89,7 +87,7 @@ pub fn build_cli_nocomplete() -> App<'static> {
89
87
. long_help ( "Only parse log entries before <date>.\n \
90
88
Accepts formats like '2018-03-04', '2018-03-04 12:34:56', \
91
89
'2018-03-04T12:34', '1 year, 2 months', '10d', and unix timestamps.") )
92
- . arg ( Arg :: with_name ( "duration" )
90
+ . arg ( Arg :: new ( "duration" )
93
91
. value_name ( "format" )
94
92
. long ( "duration" )
95
93
. global ( true )
@@ -103,7 +101,7 @@ pub fn build_cli_nocomplete() -> App<'static> {
103
101
s: 630
104
102
human: 10 minutes, 30 seconds
105
103
" ) )
106
- . arg ( Arg :: with_name ( "date" )
104
+ . arg ( Arg :: new ( "date" )
107
105
. value_name ( "format" )
108
106
. long ( "date" )
109
107
. global ( true )
@@ -120,24 +118,24 @@ pub fn build_cli_nocomplete() -> App<'static> {
120
118
compact: 20220131085946
121
119
unix: 1643619586
122
120
" ) )
123
- . arg ( Arg :: with_name ( "logfile" )
121
+ . arg ( Arg :: new ( "logfile" )
124
122
. value_name ( "file" )
125
123
. long ( "logfile" )
126
124
. short ( 'F' )
127
125
. global ( true )
128
126
. takes_value ( true )
129
127
. default_value ( "/var/log/emerge.log" )
130
128
. help ( "Location of emerge log file." ) )
131
- . arg ( Arg :: with_name ( "verbose" )
129
+ . arg ( Arg :: new ( "verbose" )
132
130
. short ( 'v' )
133
131
. global ( true )
134
- . multiple ( true )
132
+ . multiple_occurrences ( true )
135
133
. help ( "Increase verbosity (can be given multiple times)." )
136
134
. long_help ( "Increase verbosity (defaults to errors only)
137
135
-v: show warnings
138
136
-vv: show info
139
137
-vvv: show debug" ) )
140
- . arg ( Arg :: with_name ( "color" )
138
+ . arg ( Arg :: new ( "color" )
141
139
. long ( "color" ) . alias ( "colour" )
142
140
. global ( true )
143
141
. takes_value ( true )
@@ -146,23 +144,21 @@ pub fn build_cli_nocomplete() -> App<'static> {
146
144
. default_value ( "auto" )
147
145
. value_name ( "when" )
148
146
. help ( "Enable color (auto/always/never/y/n)." ) )
149
- . subcommand ( SubCommand :: with_name ( "log" )
147
+ . subcommand ( Command :: new ( "log" )
150
148
. about ( "Show log of sucessful merges, unmerges and syncs." )
151
149
. long_about ( "Show log of sucessful merges, unmerges and syncs.\n \
152
150
* (Un)merges: date, duration, package name-version.\n \
153
151
* Syncs: date, duration.")
154
- . help_message ( "Show short (-h) or detailed (--help) help." )
155
152
. arg ( & arg_show_l)
156
153
. arg ( & arg_exact)
157
154
. arg ( & arg_pkg) )
158
- . subcommand ( SubCommand :: with_name ( "predict" )
155
+ . subcommand ( Command :: new ( "predict" )
159
156
. about ( "Predict merge time for current or pretended merges." )
160
157
. long_about ( "Predict merge time for current or pretended merges.\n \
161
158
* If input is a terminal, predict time for the current merge (if any).\n \
162
159
* If input is a pipe (for example by running `emerge -rOp|emlop p`), predict time for those merges.")
163
- . help_message ( "Show short (-h) or detailed (--help) help." )
164
160
. arg ( & arg_limit) )
165
- . subcommand ( SubCommand :: with_name ( "stats" )
161
+ . subcommand ( Command :: new ( "stats" )
166
162
. about ( "Show statistics about sucessful merges, unmerges and syncs." )
167
163
. long_about ( "Show statistics about sucessful (un)merges (overall or per \
168
164
package) and syncs.\n \
@@ -171,7 +167,6 @@ pub fn build_cli_nocomplete() -> App<'static> {
171
167
* Total: merge count, total merge time, average merge time, \
172
168
unmerge count, total unmerge time, average unmerge time.\n \
173
169
* Sync: sync count, total sync time, predicted sync time.")
174
- . help_message ( "Show short (-h) or detailed (--help) help." )
175
170
. arg ( & arg_show_s)
176
171
. arg ( & arg_group)
177
172
. arg ( & arg_exact)
@@ -180,19 +175,23 @@ pub fn build_cli_nocomplete() -> App<'static> {
180
175
}
181
176
182
177
/// Generate cli argument parser.
183
- pub fn build_cli ( ) -> App < ' static > {
178
+ pub fn build_cli ( ) -> Command < ' static > {
184
179
let c = build_cli_nocomplete ( ) ;
185
- c. subcommand ( SubCommand :: with_name ( "complete" )
186
- . about ( "Generate shell completion script." )
187
- . long_about ( "Write shell completion script to stdout.\n \n \
180
+ c. subcommand (
181
+ Command :: new ( "complete" ) . about ( "Generate shell completion script." )
182
+ . long_about (
183
+ "Write shell completion script to stdout.\n \n \
188
184
You should redirect the output to a file that will be sourced by your shell.\n \
189
185
For example: `emlop complete bash > ~/.bash_completion.d/emlop`.\n \
190
186
To apply the changes, either restart you shell or `source` the generated file.
191
- " )
192
- . arg ( Arg :: with_name ( "shell" )
193
- . help ( "Target shell" )
194
- . required ( true )
195
- . possible_values ( & [ "bash" , "zsh" , "fish" ] ) ) )
187
+ " ,
188
+ )
189
+ . arg (
190
+ Arg :: new ( "shell" ) . help ( "Target shell" )
191
+ . required ( true )
192
+ . possible_values ( & [ "bash" , "zsh" , "fish" ] ) ,
193
+ ) ,
194
+ )
196
195
}
197
196
198
197
/// Clap validation helper that checks that all chars are valid.
0 commit comments