aboutsummaryrefslogtreecommitdiff
path: root/vendor/clap/examples/derive_ref/hand_subcommand.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/clap/examples/derive_ref/hand_subcommand.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/clap/examples/derive_ref/hand_subcommand.rs')
-rw-r--r--vendor/clap/examples/derive_ref/hand_subcommand.rs79
1 files changed, 0 insertions, 79 deletions
diff --git a/vendor/clap/examples/derive_ref/hand_subcommand.rs b/vendor/clap/examples/derive_ref/hand_subcommand.rs
deleted file mode 100644
index ebaa60d..0000000
--- a/vendor/clap/examples/derive_ref/hand_subcommand.rs
+++ /dev/null
@@ -1,79 +0,0 @@
-use clap::error::{Error, ErrorKind};
-use clap::{ArgMatches, Args as _, Command, FromArgMatches, Parser, Subcommand};
-
-#[derive(Parser, Debug)]
-struct AddArgs {
- name: Vec<String>,
-}
-#[derive(Parser, Debug)]
-struct RemoveArgs {
- #[arg(short, long)]
- force: bool,
- name: Vec<String>,
-}
-
-#[derive(Debug)]
-enum CliSub {
- Add(AddArgs),
- Remove(RemoveArgs),
-}
-
-impl FromArgMatches for CliSub {
- fn from_arg_matches(matches: &ArgMatches) -> Result<Self, Error> {
- match matches.subcommand() {
- Some(("add", args)) => Ok(Self::Add(AddArgs::from_arg_matches(args)?)),
- Some(("remove", args)) => Ok(Self::Remove(RemoveArgs::from_arg_matches(args)?)),
- Some((_, _)) => Err(Error::raw(
- ErrorKind::InvalidSubcommand,
- "Valid subcommands are `add` and `remove`",
- )),
- None => Err(Error::raw(
- ErrorKind::MissingSubcommand,
- "Valid subcommands are `add` and `remove`",
- )),
- }
- }
- fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> Result<(), Error> {
- match matches.subcommand() {
- Some(("add", args)) => *self = Self::Add(AddArgs::from_arg_matches(args)?),
- Some(("remove", args)) => *self = Self::Remove(RemoveArgs::from_arg_matches(args)?),
- Some((_, _)) => {
- return Err(Error::raw(
- ErrorKind::InvalidSubcommand,
- "Valid subcommands are `add` and `remove`",
- ))
- }
- None => (),
- };
- Ok(())
- }
-}
-
-impl Subcommand for CliSub {
- fn augment_subcommands(cmd: Command) -> Command {
- cmd.subcommand(AddArgs::augment_args(Command::new("add")))
- .subcommand(RemoveArgs::augment_args(Command::new("remove")))
- .subcommand_required(true)
- }
- fn augment_subcommands_for_update(cmd: Command) -> Command {
- cmd.subcommand(AddArgs::augment_args(Command::new("add")))
- .subcommand(RemoveArgs::augment_args(Command::new("remove")))
- .subcommand_required(true)
- }
- fn has_subcommand(name: &str) -> bool {
- matches!(name, "add" | "remove")
- }
-}
-
-#[derive(Parser, Debug)]
-struct Cli {
- #[arg(short, long)]
- top_level: bool,
- #[command(subcommand)]
- subcommand: CliSub,
-}
-
-fn main() {
- let args = Cli::parse();
- println!("{args:#?}");
-}