From 3217e27d4b0fc32db3a8708c2e178d53cef45b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Tue, 11 Jul 2023 19:54:05 +0200 Subject: [PATCH] feat(wip): repo and category selecting for subcmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This starts to implement repo and category selecting for subcommands that make use of these (push, pull, quick, fast... most of them!) Still, this is proof of concept, now it needs to actually be made robust and generalized, as well as implemented on all the commands. Signed-off-by: Christina Sørensen --- doc/roadmap.org | 3 ++- src/cli.rs | 6 +++++- src/main.rs | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/doc/roadmap.org b/doc/roadmap.org index bae4000..53cbdf9 100644 --- a/doc/roadmap.org +++ b/doc/roadmap.org @@ -1,7 +1,8 @@ #+title: Roadmap * 0.2.1 -- [ ] jumps +- [X] jumps +- [-] repo and category selecting for subcommands * 0.2.0 (maybe) - [X] Links in categories? - [X] Fix category with no links diff --git a/src/cli.rs b/src/cli.rs index a9d1387..38c4c3a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -84,7 +84,11 @@ pub enum Commands { /// Do quick pull-commit-push with msg for commit #[command(visible_alias = "q")] - Quick { msg: Option }, + Quick { + repo: Option, + name: Option, + msg: Option, + }, /// Do fast pull-commit-push with msg for commit, skipping repo on failure #[command(visible_alias = "f")] diff --git a/src/main.rs b/src/main.rs index cb9d792..1905182 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,15 +74,37 @@ fn main() { Some(Commands::Link { msg: _ }) => { config.link_all(); } - Some(Commands::Quick { msg }) => { - let s = Box::leak( - msg.as_mut() - .get_or_insert(&mut QUICK_COMMIT.to_string()) - .clone() - .into_boxed_str(), - ); - config.quick(s); - } + // NOTE: This implements "sub-subcommand"-like matching on repository, + // name, and additional data for a subcommand + // TODO: generalize for reuse by all commands that operate on repo->name->msg + Some(Commands::Quick { repo, name, msg }) => match (&repo, &name, &msg) { + (None, None, None) => { + let s = Box::leak( + msg.as_mut() + .get_or_insert(&mut QUICK_COMMIT.to_string()) + .clone() + .into_boxed_str(), + ); + config.quick(s); + } + (repo, None, None) => { + println!("{}", repo.as_ref().unwrap()); + todo!(); + } + (repo, name, None) => { + println!("{} {}", repo.as_ref().unwrap(), name.as_ref().unwrap()); + todo!(); + } + (repo, name, msg) => { + println!( + "{} {} {}", + repo.as_ref().unwrap(), + name.as_ref().unwrap(), + msg.as_ref().unwrap(), + ); + todo!(); + } + }, Some(Commands::Fast { msg }) => { let s = Box::leak( msg.as_mut()