(d637288) Guard an existing codename behind --force, and bump to 0.21.1
`campaign set --codename` replaced whatever was there. Once a campaign has a codename it is referred to by it -- on every card in the campaign, at the command line, and in somebody's shell history -- so changing it silently is the mistake `install-skill --force` exists to prevent. So it is refused, and the refusal names both words and the flag rather than leaving it to be found. Checked before any edit is applied, like `SetArgs::contested`, so a call also carrying `--title` writes neither field rather than half of what was asked for. Setting the codename a campaign already carries stays a no-op rather than becoming a refusal: `--force` is about overwriting a *different* word, and there is nothing to overwrite. That is the division `install::Outcome` already draws between `Unchanged` and `Refused`. `--force` guards the codename alone. A campaign always has a title, so guarding that would mean the flag was always required, which is a tax rather than a guard. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
72dbdec2ec
commit
95426e87be
+18
-1
@@ -337,6 +337,13 @@ pub enum CampaignCommand {
|
||||
/// variants are a ticket's fields, so reusing it here would put a ticket's enum on a
|
||||
/// campaign and inventing a second one is a decision worth making on purpose.
|
||||
///
|
||||
/// `--force` guards the codename and nothing else. A campaign that already has one is
|
||||
/// referred to by it: it is on every card in the campaign, it is what resolves it at the
|
||||
/// command line, and it is very likely in somebody's shell history. Replacing that silently
|
||||
/// is the same mistake overwriting an edited skill document would be, which is what
|
||||
/// `install-skill --force` exists for. A title needs no guard, since a campaign always has
|
||||
/// one and replacing it is the whole point of the flag.
|
||||
///
|
||||
/// The group makes at least one field mandatory, so a bare `worklane campaign set <c>` is a
|
||||
/// usage error rather than a silent no-op, exactly as it is for [`SetArgs`].
|
||||
#[derive(clap::Args)]
|
||||
@@ -357,9 +364,19 @@ pub struct CampaignSetArgs {
|
||||
/// Replace the codename, a single word to call the campaign by
|
||||
///
|
||||
/// The same parser `campaign add --codename` takes, so a codename is one thing however
|
||||
/// it was written.
|
||||
/// it was written. Replacing one a campaign already has needs `--force`
|
||||
#[arg(short, long, value_parser = codename)]
|
||||
pub codename: Option<String>,
|
||||
|
||||
/// Replace a codename the campaign already has
|
||||
///
|
||||
/// Without it, `--codename` on a campaign that already has one is refused and nothing
|
||||
/// is written. The codename is how a campaign is referred to once it has one, on every
|
||||
/// card in it and at the command line, so changing it is a decision rather than a
|
||||
/// correction. Setting the codename a campaign already carries is a no-op either way,
|
||||
/// not a refusal: there is nothing to overwrite
|
||||
#[arg(short, long)]
|
||||
pub force: bool,
|
||||
}
|
||||
|
||||
/// What a campaign holds: a title, a description and an owner.
|
||||
|
||||
+26
-1
@@ -1242,13 +1242,38 @@ pub fn cmd_tags(worklane_dir: &Path) -> Result<()> {
|
||||
/// `set_or_insert_metadata_field`, the upsert `assign` already uses for the Campaign field
|
||||
/// on a ticket, for the same reason.
|
||||
///
|
||||
/// **Replacing a codename the campaign already has needs `--force`.** Once a campaign has
|
||||
/// one it is referred to by it: it is on every card in the campaign, it is what resolves the
|
||||
/// campaign at the command line, and changing it out from under that is the same mistake
|
||||
/// overwriting an edited skill document would be. So it is refused, and the refusal names
|
||||
/// both words and the flag, the way `install-skill` names `--force` rather than leaving it
|
||||
/// to be found.
|
||||
///
|
||||
/// Checked before any edit is applied, like `SetArgs::contested`, so a call that also
|
||||
/// carries `--title` writes neither field rather than half of what was asked for.
|
||||
///
|
||||
/// No-op detection compares the whole file, the way `set` and `chown` do, so setting a
|
||||
/// codename a campaign already carries writes nothing.
|
||||
/// codename a campaign already carries writes nothing. That is a no-op and not a refusal:
|
||||
/// `--force` is about overwriting a *different* word, and there is nothing to overwrite.
|
||||
pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
let campaign = resolve_campaign(&args.campaign, &worklane_dir)?;
|
||||
let title = campaign.title.clone();
|
||||
|
||||
let overwrite = match (&args.codename, &campaign.codename) {
|
||||
(Some(wanted), Some(held)) if wanted != held => Some((held, wanted)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((held, wanted)) = overwrite.filter(|_| !args.force) {
|
||||
return Err(anyhow!(
|
||||
"Campaign '{}' is already codenamed '{}', so nothing was written. \
|
||||
Pass --force to replace it with '{}'",
|
||||
title,
|
||||
held,
|
||||
wanted
|
||||
));
|
||||
}
|
||||
|
||||
let mut content = campaign.content.clone();
|
||||
let mut changed: Vec<&str> = Vec::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user