Created
May 31, 2016 06:47
-
-
Save anonymous/e32e5d58b5316989d55219aab68eba8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
struct CommandArg<'o> { | |
names: &'o [&'o str], | |
help_text: &'o str, | |
} | |
fn parse_args_and_run_etc(args: &[CommandArg]) { | |
print!("Usage: app thingy "); | |
for arg in args { | |
match arg.names.first() { | |
Some(n) => print!("{} <VALUE> ", n), | |
None => print!("<VALUE> "), | |
} | |
} | |
println!(""); | |
} | |
pub fn hypothetical_subcommand() { | |
let path = CommandArg { | |
names: &["--path", "-p"], | |
help_text: "The directory in which to create the instance.", | |
}; | |
let name = CommandArg { names: &[], help_text: "The name of the instance to create." }; | |
parse_args_and_run_etc(&[path, name]); | |
} | |
fn main() { | |
hypothetical_subcommand(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version with Cow: