From c38b524e09a3f3a10f09d08f2fa6f4b619608a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Fri, 9 Jun 2023 18:16:28 +0200 Subject: [PATCH] Finalized license, warranty flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made the clap Parser able to be run without a subcommand, by wrapping the subcommand field of the Parser struct in an Option. Further destructured the subcommand arms fields in main with Some(), and made the default case None just return (). Signed-off-by: Christina Sørensen --- src/cli.rs | 4 ++-- src/main.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index bfd54c5..c70b9a3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -29,7 +29,7 @@ const CONFIG_FILE: &str = "/.config/gg/config.yaml"; long_version=env!("CARGO_PKG_VERSION"), about="GitOps for the masses", long_about="A Rust GitOps and linkfarm orchestrator inspired by GNU Stow", - subcommand_required=true, + subcommand_required=false, arg_required_else_help=true, help_template="\ {before-help}{name} {version} @@ -59,7 +59,7 @@ pub struct Args { pub code_of_conduct: bool, #[command(subcommand)] - pub command: Commands, + pub command: Option, } #[derive(Subcommand, Debug)] diff --git a/src/main.rs b/src/main.rs index 533899b..4005214 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,27 +42,28 @@ fn main() { _ => (), } match &args.command { - Commands::Link { msg: _ } => { + Some(Commands::Link { msg: _ }) => { config.link_all(); } - Commands::Quick { msg } => { + Some(Commands::Quick { msg }) => { config.quick(&msg.as_ref().unwrap()); } - Commands::Clone { msg: _ } => { + Some(Commands::Clone { msg: _ }) => { config.clone_all(); } - Commands::Pull { msg: _ } => { + Some(Commands::Pull { msg: _ }) => { config.pull_all(); } - Commands::Add { msg: _ } => { + Some(Commands::Add { msg: _ }) => { config.add_all(); } - Commands::Commit { msg: _ } => { + Some(Commands::Commit { msg: _ }) => { config.commit_all(); } - Commands::CommitMsg { msg } => { + Some(Commands::CommitMsg { msg }) => { config.commit_all_msg(&msg.as_ref().unwrap()); } + None => (), } trace!("{:?}", config); }