You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.6 KiB

4 years ago
package console_test
import (
"context"
"os"
"gitoa.ru/go-4devs/console"
)
//nolint:lll
4 years ago
func ExampleNew_help() {
ctx := context.Background()
os.Args = []string{
"bin/console",
"test:command",
"-h",
"--no-ansi",
}
console.New(console.WithExit(func(int) {})).
Add(
Command(),
).
Execute(ctx)
// Output:
// Description:
// test command
//
// Usage:
// test:command [options] [--] [<test_argument>]
//
// Arguments:
// test_argument test argument
//
// Options:
// --duration[=DURATION] test duration with default [default: 1s]
// --bool test bool option
// --string[=STRING] array string (multiple values allowed)
// -q, --quiet Do not output any message
// -v, --verbose Increase the verbosity of messages: -v for info output, -vv for debug and -vvv for trace (multiple values allowed)
// -h, --help Display this help message
// -V, --version Display this application version
// --ansi Do not ask any interactive question
// --no-ansi Disable ANSI output
}
func ExampleNew_list() {
ctx := context.Background()
os.Args = []string{
"bin/console",
"--no-ansi",
}
console.New(console.WithExit(func(int) {})).
Add(
Command(),
&console.Command{
Name: "fdevs:console:arg",
Description: "Understanding how Console Arguments and Options Are Handled",
},
&console.Command{
Name: "fdevs:console:hello",
Description: "example hello command",
},
&console.Command{
Name: "app:start",
Description: "example command in other namespace",
},
4 years ago
).
Execute(ctx)
// Output:
// Usage:
// command [options] [arguments]
//
// Options:
// -q, --quiet Do not output any message
// -v, --verbose Increase the verbosity of messages: -v for info output, -vv for debug and -vvv for trace (multiple values allowed)
// -h, --help Display this help message
// -V, --version Display this application version
// --ansi Do not ask any interactive question
// --no-ansi Disable ANSI output
//
// Available commands:
// help Displays help for a command
// list Lists commands
// app
// app:start example command in other namespace
// fdevs
// fdevs:console:arg Understanding how Console Arguments and Options Are Handled
// fdevs:console:hello example hello command
// fdevs:console:test test command
// test
// test:command test command
}