Skip to content

Commit

Permalink
feat(clap): implement -u as good as possible
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Byron committed Apr 29, 2015
1 parent 1aff313 commit 656fcae
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/mako/cli/lib/argparse.mako
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
elif isinstance(v, basestring):
v = '"%s"' % v
elif isinstance(v, list):
v = 'vec![%s]' % ','.join('UploadProtocol::%s' % p.capitalize() for p in v)
v = 'vec![%s]' % ','.join('"%s"' % p for p in v)
return 'Some(%s)' % v
%>\
<%def name="grammar(c)">\
Expand Down Expand Up @@ -182,13 +182,11 @@ let arg_data = [
if mc.media_params:
upload_protocols = [mp.protocol for mp in mc.media_params]
# TODO: figure out how to have a group of arguments
# NOTE: use possible_values() to specify 'mode'
args.append((
UPLOAD_FLAG,
"Specify which file to upload",
"mode",
True,
False,
False,
upload_protocols
))
Expand Down Expand Up @@ -266,7 +264,20 @@ for &(main_command_name, ref subcommands) in &arg_data {
arg = arg.multiple(multi);
}
if let &Some(ref protocols) = protocols {
arg = arg.possible_values(protocols.clone());
arg = arg.requires("file");
arg = arg.requires("mime");
scmd = scmd.arg(Arg::with_name("file")
.short("f")
.required(false)
.help("The file to upload")
.takes_value(true));
scmd = scmd.arg(Arg::with_name("mime")
.short("m")
.required(false)
.help("The file's mime time, like 'application/octet-stream'")
.takes_value(true));
}
scmd = scmd.arg(arg);
}
Expand Down

0 comments on commit 656fcae

Please sign in to comment.