MCPcopy
hub / github.com/urfave/cli / TestCommand_UseShortOptionHandlingCommand

Function TestCommand_UseShortOptionHandlingCommand

command_test.go:1282–1310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1280}
1281
1282func TestCommand_UseShortOptionHandlingCommand(t *testing.T) {
1283 var (
1284 one, two bool
1285 name string
1286 expected = "expectedName"
1287 )
1288
1289 cmd := &Command{
1290 Name: "cmd",
1291 Flags: []Flag{
1292 &BoolFlag{Name: "one", Aliases: []string{"o"}},
1293 &BoolFlag{Name: "two", Aliases: []string{"t"}},
1294 &StringFlag{Name: "name", Aliases: []string{"n"}},
1295 },
1296 Action: func(_ context.Context, cmd *Command) error {
1297 one = cmd.Bool("one")
1298 two = cmd.Bool("two")
1299 name = cmd.String("name")
1300 return nil
1301 },
1302 UseShortOptionHandling: true,
1303 Writer: io.Discard,
1304 }
1305
1306 require.NoError(t, cmd.Run(buildTestContext(t), []string{"cmd", "-on", expected}))
1307 require.True(t, one)
1308 require.False(t, two)
1309 require.Equal(t, expected, name)
1310}
1311
1312func TestCommand_UseShortOptionHandlingCommand_missing_value(t *testing.T) {
1313 cmd := buildMinimalTestCommand()

Callers

nothing calls this directly

Calls 4

BoolMethod · 0.95
StringMethod · 0.95
RunMethod · 0.95
buildTestContextFunction · 0.85

Tested by

no test coverage detected