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

Function TestChildFlagWithParentLocalFlag

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

Source from the content-addressed store, hash-verified

581}
582
583func TestChildFlagWithParentLocalFlag(t *testing.T) {
584 rootCmd := &Command{Use: "root", Run: emptyRun}
585 childCmd := &Command{Use: "child", Run: emptyRun}
586 rootCmd.AddCommand(childCmd)
587
588 var intFlagValue int
589 rootCmd.Flags().StringP("sf", "s", "", "")
590 childCmd.Flags().IntVarP(&intFlagValue, "intf", "i", -1, "")
591
592 _, err := executeCommand(rootCmd, "child", "-i7", "-sabc")
593 if err == nil {
594 t.Errorf("Invalid flag should generate error")
595 }
596
597 checkStringContains(t, err.Error(), "unknown shorthand")
598
599 if intFlagValue != 7 {
600 t.Errorf("Expected flag value: %v, got %v", 7, intFlagValue)
601 }
602}
603
604func TestFlagInvalidInput(t *testing.T) {
605 rootCmd := &Command{Use: "root", Run: emptyRun}

Callers

nothing calls this directly

Calls 5

AddCommandMethod · 0.95
FlagsMethod · 0.95
executeCommandFunction · 0.85
ErrorMethod · 0.80
checkStringContainsFunction · 0.70

Tested by

no test coverage detected