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

Function TestRequiredFlags

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

Source from the content-addressed store, hash-verified

851}
852
853func TestRequiredFlags(t *testing.T) {
854 c := &Command{Use: "c", Run: emptyRun}
855 c.Flags().String("foo1", "", "")
856 assertNoErr(t, c.MarkFlagRequired("foo1"))
857 c.Flags().String("foo2", "", "")
858 assertNoErr(t, c.MarkFlagRequired("foo2"))
859 c.Flags().String("bar", "", "")
860
861 expected := fmt.Sprintf("required flag(s) %q, %q not set", "foo1", "foo2")
862
863 _, err := executeCommand(c)
864 got := err.Error()
865
866 if got != expected {
867 t.Errorf("Expected error: %q, got: %q", expected, got)
868 }
869}
870
871func TestPersistentRequiredFlags(t *testing.T) {
872 parent := &Command{Use: "parent", Run: emptyRun}

Callers

nothing calls this directly

Calls 6

FlagsMethod · 0.95
MarkFlagRequiredMethod · 0.95
executeCommandFunction · 0.85
StringMethod · 0.80
ErrorMethod · 0.80
assertNoErrFunction · 0.70

Tested by

no test coverage detected