0 branches
Tree
Top files
Clone with HTTPS:
testdata
cli: drop trailing periods and use 'Print' in default help/version/man descriptions (#27123)
last May 13
2.52 KB
README.md
cli: render command groups, inherited flags, examples and learn-more in --help (#27124)
last May 23
1.79 KB
cli_test.v
tests: skip some slow running tests on jobs that do not use tcc (only when the outputs/checked invariants *do not* depend on the used C compiler)
last Dec 7
833 bytes
flag.v
docs: use cmd/tools/find_doc_comments_with_no_dots.v to put some missing dots in the doc comments of public symbols.
1 year ago
7.78 KB
help.v
cli: render command groups, inherited flags, examples and learn-more in --help (#27124)
last May 23
7.63 KB
help_test.v
cli: render command groups, inherited flags, examples and learn-more in --help (#27124)
last May 23
3.91 KB
man.v
checker: warn when a local variable shadows a function declaration (fixes #22685) (#27272)
last May 26
3.71 KB
man_test.v
fmt: fix formating a file in an oscillating manner (fix #22223, fix #22026) (#22232)
1 year ago
1.66 KB
version.v
checker: warn when a local variable shadows a function declaration (fixes #22685) (#27272)
last May 26
932 bytes
Description
cli is a command line option parser, that supports
declarative subcommands, each having a separate set of options.
See also the flag module, for a simpler command line option parser,
that supports only options.
Example
module main
import os
import cli
fn main() {
mut app := cli.Command{
name: 'example-app'
description: 'example-app'
execute: fn (cmd cli.Command) ! {
println('hello app')
return
}
commands: [
cli.Command{
name: 'sub'
alias: 's'
execute: fn (cmd cli.Command) ! {
println('hello subcommand')
return
}
},
]
}
app.setup()
app.parse(os.args)
}
Subcommands can set alias to accept a shorter invocation token, for example
example-app s.
Help layout
--help is generated automatically. Beyond Usage:, Flags: and Commands:
the output picks up extra sections when the relevant Command fields are
populated:
Inherited flags:— flags inherited from any ancestor throughFlag.global. Renders separately from local flags so a sub-command's own surface stays readable.- Grouped commands — set
groupon a sub-command to lift it out of the defaultCommands:block into a section named after the group. The group string is rendered verbatim followed by:, so capitalisation is the caller's choice. Sub-commands sharing a group keep their declaration order. Examples:— setexamples []stringon aCommand; each entry becomes one indented line.Learn more:— setlearn_more string; newlines split the block into separate lines.
Sections that have nothing to render are simply omitted, so existing apps
see no change unless they opt in by setting these fields. See
examples/cli_groups.v for a runnable program that exercises all of them.