diff options
Diffstat (limited to 'examples/simple_example.rs')
-rw-r--r-- | examples/simple_example.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/simple_example.rs b/examples/simple_example.rs new file mode 100644 index 0000000..d977495 --- /dev/null +++ b/examples/simple_example.rs @@ -0,0 +1,42 @@ +// Copyright (c) 2022 Google LLC All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +use {argh::FromArgs, std::fmt::Debug}; + +#[derive(FromArgs, PartialEq, Debug)] +/// Top-level command. +struct TopLevel { + #[argh(subcommand)] + nested: MySubCommandEnum, +} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand)] +enum MySubCommandEnum { + One(SubCommandOne), + Two(SubCommandTwo), +} + +#[derive(FromArgs, PartialEq, Debug)] +/// First subcommand. +#[argh(subcommand, name = "one")] +struct SubCommandOne { + #[argh(option)] + /// how many x + x: usize, +} + +#[derive(FromArgs, PartialEq, Debug)] +/// Second subcommand. +#[argh(subcommand, name = "two")] +struct SubCommandTwo { + #[argh(switch)] + /// whether to fooey + fooey: bool, +} + +fn main() { + let toplevel: TopLevel = argh::from_env(); + println!("{:#?}", toplevel); +} |