Skip to content

Commit

Permalink
fix(clap): commit before un-using UploadProtocol
Browse files Browse the repository at this point in the history
We will try to wait for clap-rs/clap#87
to allow us to use the enumeration instead of strings, as well as
an iterator, which will look more idiomatic in the end.
  • Loading branch information
Byron committed Apr 29, 2015
1 parent db4624b commit 1aff313
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/mako/cli/lib/argparse.mako
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
v = v and 'true' or 'false'
elif isinstance(v, basestring):
v = '"%s"' % v
elif isinstance(v, list):
v = 'vec![%s]' % ','.join('UploadProtocol::%s' % p.capitalize() for p in v)
return 'Some(%s)' % v
%>\
<%def name="grammar(c)">\
Expand Down Expand Up @@ -118,6 +120,8 @@ Configuration:
None
))
%>\
use cmn::UploadProtocol;
let mut app = App::new("${util.program_name()}")
<%block filter="indent_by(7)">\
.author("${', '.join(cargo.authors)}")
Expand Down Expand Up @@ -161,6 +165,7 @@ let arg_data = [
mangle_subcommand(p.name),
True,
False,
None,
))
# end for each required property
Expand All @@ -171,6 +176,7 @@ let arg_data = [
KEY_VALUE_ARG,
True,
True,
None
))
# end request_value
Expand All @@ -183,7 +189,8 @@ let arg_data = [
"Specify which file to upload",
"mode",
True,
True,
False,
upload_protocols
))
## args.append('-%s %s %s %s' % (UPLOAD_FLAG, mode, FILE_ARG, MIME_ARG))
# end upload handling
Expand All @@ -195,6 +202,7 @@ let arg_data = [
VALUE_ARG,
False,
True,
None
))
# end paramters
Expand All @@ -205,17 +213,19 @@ let arg_data = [
OUT_ARG,
False,
False,
None
))
# handle output
%>\
("${mangle_subcommand(method)}", ${rust_optional(mc.m.get('description'))},
vec![
% for flag, desc, arg_name, required, multi in args:
% for flag, desc, arg_name, required, multi, upload_protocols in args:
(${rust_optional(arg_name)},
${rust_optional(flag)},
${rust_optional(desc)},
${rust_optional(required)},
${rust_optional(multi)}),
${rust_optional(multi)},
${rust_optional(upload_protocols)}),
% if not loop.last:
% endif
Expand All @@ -234,7 +244,7 @@ for &(main_command_name, ref subcommands) in &arg_data {
if let &Some(desc) = desc {
scmd = scmd.about(desc);
}
for &(ref arg_name, ref flag, ref desc, ref required, ref multi) in args {
for &(ref arg_name, ref flag, ref desc, ref required, ref multi, ref protocols) in args {
let mut arg = Arg::with_name(match (arg_name, flag) {
(&Some(an), _) => an,
(_, &Some(f)) => f,
Expand All @@ -254,6 +264,9 @@ for &(main_command_name, ref subcommands) in &arg_data {
}
if let &Some(multi) = multi {
arg = arg.multiple(multi);
}
if let &Some(ref protocols) = protocols {
}
scmd = scmd.arg(arg);
}
Expand Down
1 change: 0 additions & 1 deletion src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<%
hub_type_name = 'api::' + hub_type(c.schemas, util.canonical_name())
%>\
mod cmn;
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError};
Expand Down
2 changes: 2 additions & 0 deletions src/mako/cli/main.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use std::env;
use std::io::{self, Write};
use clap::{App, SubCommand, Arg};

mod cmn;

## ${engine.new(c)}\

fn main() {
Expand Down
16 changes: 16 additions & 0 deletions src/rust/cli/cmn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ use std::default::Default;

const FIELD_SEP: char = '.';

/// Unused for now, can be used once https://github.com/kbknapp/clap-rs/issues/87
/// is available
pub enum UploadProtocol {
Simple,
Resumable,
}

impl AsRef<str> for UploadProtocol {
fn as_ref(&self) -> &str {
match *self {
UploadProtocol::Simple => "simple",
UploadProtocol::Resumable => "resumable",
}
}
}

#[derive(Clone, Default)]
pub struct FieldCursor(Vec<String>);

Expand Down

0 comments on commit 1aff313

Please sign in to comment.