diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c0e352..fe6389f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Changed - - make `status` subcommand more ergonomic +- refactor `branch` subcommand into `checkout` ## [v0.1.0] - 2022-07-17 diff --git a/src/main.rs b/src/main.rs index f6aaa02..71d7ab8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ fn main() { let args = parse_args(); let work_dir = args - .path + .workspace .unwrap_or_else(|| std::env::current_dir().expect("Unable to obtain current_dir")); let mut vcs = match vcs::Vcs::new(work_dir) { Ok(val) => val, @@ -23,8 +23,8 @@ fn main() { }; match args.command { - Commands::Branch(BranchCommand::Set { branch }) => { - vcs.set_branch(&branch) + Commands::Branch(BranchCommand::Set { branch, projects }) => { + vcs.set_branch(&branch, projects) .expect("Error setting branch on projects"); } Commands::Profile(ProfileCommand::Save { profile }) => { diff --git a/src/vcs.rs b/src/vcs.rs index 5a1028a..f228d3f 100644 --- a/src/vcs.rs +++ b/src/vcs.rs @@ -230,20 +230,37 @@ impl Vcs { return Ok(()); } - self.set_projects_using(profile_name, |project| { + self.set_projects_using(profile_name, None, |project| { project.switch_to_profile(profile_name) }) } - pub fn set_branch(&mut self, branch_name: &str) -> Result<(), Error> { - self.set_projects_using(branch_name, |project| project.repo.checkout(branch_name)) + pub fn set_branch( + &mut self, + branch_name: &str, + projects: Option>, + ) -> Result<(), Error> { + self.set_projects_using(branch_name, projects, |project| { + project.repo.checkout(branch_name) + }) } - fn set_projects_using(&mut self, dest_name: &str, setter: F) -> Result<(), Error> + fn set_projects_using( + &mut self, + dest_name: &str, + projects: Option>, + setter: F, + ) -> Result<(), Error> where F: Fn(&mut Project) -> Result, { for project in &mut self.projects { + if let Some(only_projects) = &projects { + if !only_projects.iter().any(|p| p == project.name()) { + continue; + } + } + let current_ref = project.repo.current_ref()?; // stash changes before moving project off to a new ref let stashed_changes = project.repo.stash_changes(¤t_ref)?; diff --git a/src/vcs/cli.rs b/src/vcs/cli.rs index 8a6c21b..e52841c 100644 --- a/src/vcs/cli.rs +++ b/src/vcs/cli.rs @@ -9,8 +9,8 @@ pub struct Cli { #[clap(subcommand)] pub command: Commands, /// Path to workspace folder, defaults to CWD - #[clap(short = 'p')] - pub path: Option, + #[clap(short = 'w')] + pub workspace: Option, } #[derive(Debug, Parser)] @@ -45,5 +45,10 @@ pub enum ProfileCommand { pub enum BranchCommand { /// Switch all projects in workspace to given branch #[clap(arg_required_else_help = true)] - Set { branch: String }, + Set { + branch: String, + /// Project list, do any operation only on projects in this list (*comma separated*) + #[clap(short = 'p')] + projects: Option>, + }, }