Skip to content

feat: implement barzel init --force to overwrite existing .barzel.toml#49

Merged
thefourcraft merged 3 commits intoproductionfrom
feature/init-force-flag
May 4, 2026
Merged

feat: implement barzel init --force to overwrite existing .barzel.toml#49
thefourcraft merged 3 commits intoproductionfrom
feature/init-force-flag

Conversation

@thefourcraft
Copy link
Copy Markdown
Member

Summary

Fixes the broken promise in init.rs: the skip message said "use --force to overwrite" but --force didn't exist. Now it does.

Changes

src/cli.rs — adds --force flag to the Init subcommand.

src/init.rsrun_init signature changes from (target, stdio) -> Result<()> to (target, stdio, force) -> Result<InitOutcome>. InitOutcome is Created | Skipped | Overwritten. Config is only overwritten when force=true.

src/main.rs — threads force from parsed CLI args.

src/stdio.rs — adds force: bool (default false) to StdioRequest; threads it to run_init; adds config_status: "created" | "skipped" | "overwritten" to the init success response so agents can tell whether the config was actually written.

README.md — documents barzel init . --force, the stdio force field, and adds the force row to the request fields table.

Tests added (5)

  • init_skips_if_toml_already_exists_without_force — outcome is Skipped, sentinel preserved
  • init_force_overwrites_existing_toml — outcome is Overwritten, sentinel gone
  • stdio_request_parses_force_true — JSON deserialization
  • stdio_request_force_defaults_to_false — default when field absent
  • init_force_returns_overwritten_outcome — end-to-end outcome via stdio path

Test plan

  • cargo clippy --bin barzel -- -D warnings — clean
  • cargo test --bins — 717 passed, 0 failed (was 712)
  • git diff --stat — 5 files: src/cli.rs, src/init.rs, src/main.rs, src/stdio.rs, README.md

- Add --force flag to 'barzel init' CLI command
- Add force: bool field to StdioRequest for {"command":"init"}
- run_init now returns InitOutcome (Created/Skipped/Overwritten)
- Existing config is skipped by default; overwritten only when force=true
- stdio init response includes config_status field with the outcome
- README updated with --force example and stdio force field
- init response message is now outcome-conditional:
  created -> 'project initialized'
  skipped -> 'config already exists'
  overwritten -> 'config overwritten'
- README documents config_status table so agents know the three values
- Test verifies message/status mapping is stable
…on code

Test now calls the same init_status_and_message() used by handle_stdio
instead of duplicating the match, so it guards the actual stdio contract.
@thefourcraft thefourcraft merged commit edc979e into production May 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant