Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 656fcae

Browse files
committed
feat(clap): implement -u as good as possible
We can't have the `-u <mode> <file> <mime>` style yet, but clap-rs/clap#88 might help with that at some point. Related to #92 and #81
1 parent 1aff313 commit 656fcae

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/mako/cli/lib/argparse.mako

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
elif isinstance(v, basestring):
1717
v = '"%s"' % v
1818
elif isinstance(v, list):
19-
v = 'vec![%s]' % ','.join('UploadProtocol::%s' % p.capitalize() for p in v)
19+
v = 'vec![%s]' % ','.join('"%s"' % p for p in v)
2020
return 'Some(%s)' % v
2121
%>\
2222
<%def name="grammar(c)">\
@@ -182,13 +182,11 @@ let arg_data = [
182182
183183
if mc.media_params:
184184
upload_protocols = [mp.protocol for mp in mc.media_params]
185-
# TODO: figure out how to have a group of arguments
186-
# NOTE: use possible_values() to specify 'mode'
187185
args.append((
188186
UPLOAD_FLAG,
189187
"Specify which file to upload",
190188
"mode",
191-
True,
189+
False,
192190
False,
193191
upload_protocols
194192
))
@@ -266,7 +264,20 @@ for &(main_command_name, ref subcommands) in &arg_data {
266264
arg = arg.multiple(multi);
267265
}
268266
if let &Some(ref protocols) = protocols {
269-
267+
arg = arg.possible_values(protocols.clone());
268+
arg = arg.requires("file");
269+
arg = arg.requires("mime");
270+
271+
scmd = scmd.arg(Arg::with_name("file")
272+
.short("f")
273+
.required(false)
274+
.help("The file to upload")
275+
.takes_value(true));
276+
scmd = scmd.arg(Arg::with_name("mime")
277+
.short("m")
278+
.required(false)
279+
.help("The file's mime time, like 'application/octet-stream'")
280+
.takes_value(true));
270281
}
271282
scmd = scmd.arg(arg);
272283
}

0 commit comments

Comments
 (0)