Desertbit/grumble
Jump to navigation
Jump to search
External
Internal
Overview
Unit Testing Commands
These options do not capture the command output, just side effects:
Option 1
command := somepackage.SomeCommand(...)
app := grumble.New(&grumble.Config{Name: "test"})
app.AddCommand(command)
args := []string{
"somecommand",
"--arg1", "test1",
"--arg2", "test2",
}
err := app.RunCommand(args)
Option 2
In this case, a flag must be registered, even if it has a zero value, otherwise the attempt to get the flag will panic the runtime.
flags := map[string]*grumble.FlagMapItem{
"arg1": return &grumble.FlagMapItem{Value: arg1},
"arg2": return &grumble.FlagMapItem{Value: arg2},
}
ctx := &grumble.Context{
Flags: flags,
Context: context.Background(),
}
command := somepackage.SomeCommand(...)
err := command.Run(ctx)