diff --git a/src/command.rs b/src/command.rs index 866c903..ced9f32 100644 --- a/src/command.rs +++ b/src/command.rs @@ -32,6 +32,7 @@ impl Command { long: "verbose".to_string(), multiple: false, takes_value: false, + required: false, validate_as_number: false, val: "".to_string(), }); @@ -85,6 +86,7 @@ pub struct OptionFlag { pub multiple: bool, // Can it have multiple values? (-vvv OR -i one -i two) pub takes_value: bool, // Does it take a value? (-i value) pub validate_as_number: bool, // Should we validate it as a number? + pub required: bool, pub val: String, } @@ -97,6 +99,7 @@ impl OptionFlag { long: "".to_string(), multiple: false, takes_value: false, + required: false, validate_as_number: false, val: "".to_string(), } diff --git a/src/main.rs b/src/main.rs index 7e47edd..6e3b81c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,13 +101,13 @@ fn build_subcommands<'a, 'b>( } } - // Add all required arguments + // Add all positional arguments for a in &c.required_args { let arg = Arg::with_name(&a.name).required(true); subcmd = subcmd.arg(arg); } - // Add all optional flags + // Add all named flags for f in &c.option_flags { let arg = Arg::with_name(&f.name) .help(&f.desc) @@ -115,6 +115,7 @@ fn build_subcommands<'a, 'b>( .long(&f.long) .takes_value(f.takes_value) .multiple(f.multiple); + .required(f.required); subcmd = subcmd.arg(arg); } cli_app = cli_app.subcommand(subcmd); diff --git a/src/parser.rs b/src/parser.rs index dfce78c..ba53ead 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -129,6 +129,9 @@ pub fn build_command_structure(maskfile_contents: String) -> Command { } } } + "required" => { + current_option_flag.required = true; + } _ => (), }; }