MCPcopy
hub / github.com/spf13/cobra / TestTraverseWithTwoSubcommands

Function TestTraverseWithTwoSubcommands

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

Source from the content-addressed store, hash-verified

2401}
2402
2403func TestTraverseWithTwoSubcommands(t *testing.T) {
2404 rootCmd := &Command{Use: "root", TraverseChildren: true}
2405
2406 subCmd := &Command{Use: "sub", TraverseChildren: true}
2407 rootCmd.AddCommand(subCmd)
2408
2409 subsubCmd := &Command{
2410 Use: "subsub",
2411 }
2412 subCmd.AddCommand(subsubCmd)
2413
2414 c, _, err := rootCmd.Traverse([]string{"sub", "subsub"})
2415 if err != nil {
2416 t.Fatalf("Unexpected error: %v", err)
2417 }
2418 if c.Name() != subsubCmd.Name() {
2419 t.Fatalf("Expected command: %q, got %q", subsubCmd.Name(), c.Name())
2420 }
2421}
2422
2423// TestUpdateName checks if c.Name() updates on changed c.Use.
2424// Related to https://github.com/spf13/cobra/pull/422#discussion_r143918343.

Callers

nothing calls this directly

Calls 3

AddCommandMethod · 0.95
TraverseMethod · 0.95
NameMethod · 0.95

Tested by

no test coverage detected