Skip to content

[core] Enable custom usage line#27

Merged
forfudan merged 2 commits intomainfrom
update
Mar 13, 2026
Merged

[core] Enable custom usage line#27
forfudan merged 2 commits intomainfrom
update

Conversation

@forfudan
Copy link
Owner

@forfudan forfudan commented Mar 13, 2026

This PR adds support for overriding ArgMojo’s auto-generated usage line with a fully custom, git-style usage string, and documents/tests the new capability.

Changes:

  • Add Command.usage(text) and _custom_usage storage, used by both help generation and plain-text usage hints.
  • Add a new test suite validating custom vs default usage behavior and copy preservation.
  • Update documentation (user manual, changelog, planning docs) and wire the new test into pixi.toml.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for overriding ArgMojo’s auto-generated usage line with a fully custom, git-style usage string, and documents/tests the new capability.

Changes:

  • Add Command.usage(text) and _custom_usage storage, used by both help generation and plain-text usage hints.
  • Add a new test suite validating custom vs default usage behavior and copy preservation.
  • Update documentation (user manual, changelog, planning docs) and wire the new test into pixi.toml.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/argmojo/command.mojo Introduces _custom_usage, usage(), and integrates custom usage into help/usage rendering.
tests/test_usage.mojo New tests for custom usage in help (plain/colored), default usage fallback, copy behavior, and parsing unaffected.
pixi.toml Adds the new test file to the test task pipeline.
docs/user_manual.md Documents command.usage("...") and updates reference tables/TOC.
docs/changelog.md Adds a changelog entry for usage customization (currently has a formatting/content issue).
docs/argmojo_overall_planning.md Marks usage customization as implemented and lists the new test file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +3314 to +3322
Usage: git [-v | --version] [-h | --help] [-C <path>] <command> [<args>]

The stupid content tracker

Options:
-v, --verbose Verbose output
-C <path> Run as if started in <path>
-h, --help Print help
-V, --version Print version
assert_equal(result.get_string("file"), "input.txt")
assert_true(result.get_flag("verbose"), msg="--verbose should work")


Comment on lines +28 to +29
16. **Confirmation option.** Add `confirmation_option()` and `confirmation_option["prompt"]()` builder methods on `Command`.
17. **Usage line customisation.** Add `usage(text)` method on `Command`. When set, the given text replaces the auto-generated `Usage: myapp [OPTIONS] ...` line in both `--help` output and error messages. This lets you write git-style usage strings like `git [-v | --version] [-h | --help] [-C <path>] <command> [<args>]`. When not set, the default auto-generated usage line is used. When enabled, the command automatically registers a `--yes` / `-y` flag and prompts the user for confirmation after parsing (and after interactive prompting, if any). If the user does not confirm (`y`/`yes`), the command aborts with an error. Passing `--yes` or `-y` on the command line skips the prompt entirely. When stdin is not interactive (piped input, `/dev/null`), the command aborts gracefully. This is equivalent to Click's `confirmation_option` decorator (PR #26).

## Usage Line Customisation

By default, ArgMojo generates usage lines like `Usage: myapp [OPTIONS] <PATTERN>` — showing `[OPTIONS]` for named arguments and listing each positional. This convention (shared by clap, cobra, and Click) works well for most CLIs.
@forfudan forfudan merged commit 26ab33c into main Mar 13, 2026
2 checks passed
@forfudan forfudan deleted the update branch March 13, 2026 20:32
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.

2 participants