From a4da01ac39ddf053dec226a8ddacfe1cea49892b Mon Sep 17 00:00:00 2001 From: Ales Katona Date: Sat, 23 Jul 2022 17:32:59 -0700 Subject: [PATCH] refactor branch subcommand into checkout --- src/main.rs | 7 +++++-- src/vcs.rs | 8 ++++---- src/vcs/cli.rs | 23 ++++++++--------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 71d7ab8..d7871e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,8 +23,11 @@ fn main() { }; match args.command { - Commands::Branch(BranchCommand::Set { branch, projects }) => { - vcs.set_branch(&branch, projects) + Commands::Checkout { + reference, + projects, + } => { + vcs.checkout_ref(&reference, projects) .expect("Error setting branch on projects"); } Commands::Profile(ProfileCommand::Save { profile }) => { diff --git a/src/vcs.rs b/src/vcs.rs index f228d3f..5bab0e3 100644 --- a/src/vcs.rs +++ b/src/vcs.rs @@ -235,13 +235,13 @@ impl Vcs { }) } - pub fn set_branch( + pub fn checkout_ref( &mut self, - branch_name: &str, + ref_name: &str, projects: Option>, ) -> Result<(), Error> { - self.set_projects_using(branch_name, projects, |project| { - project.repo.checkout(branch_name) + self.set_projects_using(ref_name, projects, |project| { + project.repo.checkout(ref_name) }) } diff --git a/src/vcs/cli.rs b/src/vcs/cli.rs index e52841c..2a2946f 100644 --- a/src/vcs/cli.rs +++ b/src/vcs/cli.rs @@ -24,9 +24,14 @@ pub enum Commands { /// Set or save profiles #[clap(subcommand)] Profile(ProfileCommand), - /// Set branch globally on workspace - #[clap(subcommand)] - Branch(BranchCommand), + /// Checkout specific repo reference (branch, commit etc.) + Checkout { + /// Reference name + reference: String, + /// Project list to apply checkout to, defaults to all + #[clap(short = 'p')] + projects: Option>, + }, } #[derive(Debug, Parser)] @@ -40,15 +45,3 @@ pub enum ProfileCommand { /// Lists all saved profiles List, } - -#[derive(Debug, Parser)] -pub enum BranchCommand { - /// Switch all projects in workspace to given branch - #[clap(arg_required_else_help = true)] - Set { - branch: String, - /// Project list, do any operation only on projects in this list (*comma separated*) - #[clap(short = 'p')] - projects: Option>, - }, -}