mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
add example.rs
This commit is contained in:
parent
c9e7ad90df
commit
d3872e0984
1 changed files with 38 additions and 0 deletions
38
examples/example.rs
Normal file
38
examples/example.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright (c) 2017 Guillaume Pinot <texitoi(a)texitoi.eu>
|
||||
//
|
||||
// This work is free. You can redistribute it and/or modify it under
|
||||
// the terms of the Do What The Fuck You Want To Public License,
|
||||
// Version 2, as published by Sam Hocevar. See the COPYING file for
|
||||
// more details.
|
||||
|
||||
extern crate structopt;
|
||||
#[macro_use]
|
||||
extern crate structopt_derive;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "example", about = "An example of StructOpt usage.")]
|
||||
struct Opt {
|
||||
/// A flag, true if used in the command line.
|
||||
#[structopt(short = "d", long = "debug", help = "Activate debug mode")]
|
||||
debug: bool,
|
||||
|
||||
/// An argument of type float, with a default value.
|
||||
#[structopt(short = "s", long = "speed", help = "Set speed", default_value = "42")]
|
||||
speed: f64,
|
||||
|
||||
/// Needed parameter, the first on the command line.
|
||||
#[structopt(help = "Input file")]
|
||||
input: String,
|
||||
|
||||
/// An optional parameter, will be `None` if not present on the
|
||||
/// command line.
|
||||
#[structopt(help = "Output file, stdout if not present")]
|
||||
output: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::from_args();
|
||||
println!("{:?}", opt);
|
||||
}
|
Loading…
Reference in a new issue