cli: make branch command's --delete flag actually a flag, and require name arg

I had forgotten to make the `delete` argument a flag by giving it a
name, so instead it conflicted with `name` argument, as tests
discovered.

While at it, I also made `name` required. It wasn't before because I
originally had a single command for `jj branch` and `jj branches` and
then I didn't think to make it required when I split them up.
This commit is contained in:
Martin von Zweigbergk 2021-08-04 14:21:40 -07:00
parent 10b2e25c30
commit f85613cf66

View file

@ -730,8 +730,8 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
.about("Update or delete branch")
.arg(rev_arg())
.arg(Arg::with_name("allow-backwards").long("allow-backwards"))
.arg(Arg::with_name("delete"))
.arg(Arg::with_name("name").index(1));
.arg(Arg::with_name("delete").long("delete"))
.arg(Arg::with_name("name").index(1).required(true));
let branches_command = SubCommand::with_name("branches").about("List branches");
let evolve_command =
SubCommand::with_name("evolve").about("Resolve problems with the repo's meta-history");
@ -2080,7 +2080,7 @@ fn cmd_branch(
sub_matches: &ArgMatches,
) -> Result<(), CommandError> {
let mut repo_command = command.repo_helper(ui)?;
if let Some(branch_name) = sub_matches.value_of("name") {
let branch_name = sub_matches.value_of("name").unwrap();
if sub_matches.is_present("delete") {
let mut tx = repo_command.start_transaction(&format!("delete branch {}", branch_name));
tx.mut_repo().remove_local_branch(branch_name);
@ -2095,8 +2095,7 @@ fn cmd_branch(
)
{
return Err(CommandError::UserError(
"Use --allow-backwards to allow moving a branch backwards or sideways"
.to_string(),
"Use --allow-backwards to allow moving a branch backwards or sideways".to_string(),
));
}
let mut tx = repo_command.start_transaction(&format!(
@ -2110,11 +2109,6 @@ fn cmd_branch(
);
repo_command.finish_transaction(ui, tx)?;
}
} else {
return Err(CommandError::UserError(
"No branch name specified".to_string(),
));
}
Ok(())
}