Files
console/app_test.go
andrey 5577600f95
Some checks failed
Go Action / goaction (pull_request) Failing after 1m53s
update dump args
2026-01-05 14:13:11 +03:00

99 lines
3.0 KiB
Go

package console_test
import (
"context"
"os"
"gitoa.ru/go-4devs/console"
)
//nolint:lll
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:
// --string[=STRING] array string (multiple values allowed)
// --group-bool bool
// --group-test-string[=GROUP-TEST-STRING] test group string [default:group string default value]
// --log-{service}-level[=LOG-{SERVICE}-LEVEL] service level [default:debug]
// --bool test bool option
// --duration[=DURATION] test duration with default
// --ansi Do not ask any interactive question
// -V, --version Display this application version
// -h, --help Display this help message
// -v, --verbose Increase the verbosity of messages: -v for info output, -vv for debug and -vvv for trace (multiple values allowed)
// -q, --quiet Do not output any message
// --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",
},
).
Execute(ctx)
// Output:
// Usage:
// command [options] [arguments]
//
// Options:
// --no-ansi Disable ANSI output
// --ansi Do not ask any interactive question
// -V, --version Display this application version
// -h, --help Display this help message
// -v, --verbose Increase the verbosity of messages: -v for info output, -vv for debug and -vvv for trace (multiple values allowed)
// -q, --quiet Do not output any message
//
// 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
}