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

Function TestTraverseWithParentFlags

command_test.go:2322–2342  ·  command_test.go::TestTraverseWithParentFlags
(t *testing.T)

Source from the content-addressed store, hash-verified

2320}
2321
2322func TestTraverseWithParentFlags(t *testing.T) {
2323 rootCmd := &Command{Use: "root", TraverseChildren: true}
2324 rootCmd.Flags().String("str", "", "")
2325 rootCmd.Flags().BoolP("bool", "b", false, "")
2326
2327 childCmd := &Command{Use: "child"}
2328 childCmd.Flags().Int("int", -1, "")
2329
2330 rootCmd.AddCommand(childCmd)
2331
2332 c, args, err := rootCmd.Traverse([]string{"-b", "--str", "ok", "child", "--int"})
2333 if err != nil {
2334 t.Errorf("Unexpected error: %v", err)
2335 }
2336 if len(args) != 1 && args[0] != "--add" {
2337 t.Errorf("Wrong args: %v", args)
2338 }
2339 if c.Name() != childCmd.Name() {
2340 t.Errorf("Expected command: %q, got: %q", childCmd.Name(), c.Name())
2341 }
2342}
2343
2344func TestTraverseNoParentFlags(t *testing.T) {
2345 rootCmd := &Command{Use: "root", TraverseChildren: true}

Callers

nothing calls this directly

Calls 5

FlagsMethod · 0.95
AddCommandMethod · 0.95
TraverseMethod · 0.95
NameMethod · 0.95
StringMethod · 0.80

Tested by

no test coverage detected