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.

45 lines
1.1 KiB

package console_test
import (
"context"
"fmt"
"gitoa.ru/go-4devs/console"
"gitoa.ru/go-4devs/console/input/array"
"gitoa.ru/go-4devs/console/input/value"
"gitoa.ru/go-4devs/console/output/writer"
)
func ExampleRun() {
cmd := Command()
ctx := context.Background()
out := writer.Stdout()
in := array.New()
err := console.Run(ctx, cmd, in, out)
fmt.Println("err:", err)
// Output:
// test argument:
// bool option:false
// duration option with default:1s
// array string:[]
// err: <nil>
}
func ExampleExecute() {
cmd := Command()
ctx := context.Background()
in := array.New()
// Run command: ./bin "argument value" -b --string="same value" --string="other value"
in.SetOption("bool", value.New(true))
in.SetOption("string", value.New([]string{"same value", "other value"}))
in.SetArgument("test_argument", value.New("argument value"))
console.Execute(ctx, cmd, console.WithInput(in), console.WithExit(func(int) {}))
// Output:
// test argument:argument value
// bool option:true
// duration option with default:1s
// array string:[same value,other value]
}