Parse command-line arguments: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 920: | Line 920: | ||
Fruit: orange |
Fruit: orange |
||
Arguments: ["-arg"]</pre> |
Arguments: ["-arg"]</pre> |
||
=={{header|Rust}}== |
|||
<lang rust>use structopt::StructOpt; |
|||
#[derive(StructOpt)] |
|||
struct Opt { |
|||
#[structopt(short)] |
|||
b: bool, |
|||
#[structopt(short, required = false, default_value = "")] |
|||
s: String, |
|||
#[structopt(short, required = false, default_value = "0")] |
|||
n: i32, |
|||
} |
|||
fn main() { |
|||
let opt = Opt::from_args(); |
|||
println!("b: {}", opt.b); |
|||
println!("s: {}", opt.s); |
|||
println!("n: {}", opt.n); |
|||
}</lang> |
|||
Examples: |
|||
<pre> |
|||
> parse |
|||
b: false |
|||
s: |
|||
n: 0 |
|||
> parse -s bye -b |
|||
b: true |
|||
s: bye |
|||
n: 0 |
|||
> parse -n 99 -s "say my name" |
|||
b: false |
|||
s: say my name |
|||
n: 99 |
|||
</pre> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |