Usage Line Customisation
By default, ArgMojo generates usage lines like
usage: myapp <PATTERN> [OPTIONS] — showing [OPTIONS] for named arguments and
listing each positional. This convention (shared by clap, cobra, and Click)
works well for most CLIs.
For some programs you may want a hand-written usage string — for example, git’s
usage line enumerates a few key flags inline rather than collapsing them into
[OPTIONS]. The usage() method on Command lets you replace the
auto-generated usage line with your own text:
from argmojo import Command, Argument
def main() raises:
var cmd = Command("git", "The stupid content tracker", version="2.45.0")
cmd.usage("git [-v | --version] [-h | --help] [-C <path>] <command> [<args>]")
cmd.add_argument(Argument("verbose", help="Verbose output").long["verbose"]().short["v"]().flag())
cmd.add_argument(Argument("path", help="Run as if started in <path>").short["C"]())
var result = cmd.parse()
The custom string appears as-is after usage: in both --help output and error
messages:
$ ./git --help
The stupid content tracker
usage: git [-v | --version] [-h | --help] [-C <path>] <command> [<args>]
options:
-v, --verbose Verbose output
-C <path> Run as if started in <path>
-h, --help Print help
-V, --version Print version
When no custom usage is set, the auto-generated line is used as before — no change in default behaviour.