refactor branch subcommand into checkout

master
Ales Katona 2 years ago
parent ea94a69502
commit a4da01ac39
Signed by: almindor
GPG Key ID: 2F773149BF38B48F

@ -23,8 +23,11 @@ fn main() {
}; };
match args.command { match args.command {
Commands::Branch(BranchCommand::Set { branch, projects }) => { Commands::Checkout {
vcs.set_branch(&branch, projects) reference,
projects,
} => {
vcs.checkout_ref(&reference, projects)
.expect("Error setting branch on projects"); .expect("Error setting branch on projects");
} }
Commands::Profile(ProfileCommand::Save { profile }) => { Commands::Profile(ProfileCommand::Save { profile }) => {

@ -235,13 +235,13 @@ impl Vcs {
}) })
} }
pub fn set_branch( pub fn checkout_ref(
&mut self, &mut self,
branch_name: &str, ref_name: &str,
projects: Option<Vec<String>>, projects: Option<Vec<String>>,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.set_projects_using(branch_name, projects, |project| { self.set_projects_using(ref_name, projects, |project| {
project.repo.checkout(branch_name) project.repo.checkout(ref_name)
}) })
} }

@ -24,9 +24,14 @@ pub enum Commands {
/// Set or save profiles /// Set or save profiles
#[clap(subcommand)] #[clap(subcommand)]
Profile(ProfileCommand), Profile(ProfileCommand),
/// Set branch globally on workspace /// Checkout specific repo reference (branch, commit etc.)
#[clap(subcommand)] Checkout {
Branch(BranchCommand), /// Reference name
reference: String,
/// Project list to apply checkout to, defaults to all
#[clap(short = 'p')]
projects: Option<Vec<String>>,
},
} }
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
@ -40,15 +45,3 @@ pub enum ProfileCommand {
/// Lists all saved profiles /// Lists all saved profiles
List, 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<Vec<String>>,
},
}

Loading…
Cancel
Save