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

Function TestPersistentFlagIsSet

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

Source from the content-addressed store, hash-verified

3747}
3748
3749func TestPersistentFlagIsSet(t *testing.T) {
3750 result := ""
3751 resultIsSet := false
3752
3753 app := &Command{
3754 Name: "root",
3755 Flags: []Flag{
3756 &StringFlag{
3757 Name: "result",
3758 },
3759 },
3760 Commands: []*Command{
3761 {
3762 Name: "sub",
3763 Action: func(_ context.Context, cmd *Command) error {
3764 result = cmd.String("result")
3765 resultIsSet = cmd.IsSet("result")
3766 return nil
3767 },
3768 },
3769 },
3770 }
3771
3772 err := app.Run(context.Background(), []string{"root", "--result", "before", "sub"})
3773 require.NoError(t, err)
3774 require.Equal(t, "before", result)
3775 require.True(t, resultIsSet)
3776
3777 err = app.Run(context.Background(), []string{"root", "sub", "--result", "after"})
3778 require.NoError(t, err)
3779 require.Equal(t, "after", result)
3780 require.True(t, resultIsSet)
3781}
3782
3783func TestDuplicatePersistentFlagUsesEnvSource(t *testing.T) {
3784 t.Setenv("APP_RESULT", "from-env")

Callers

nothing calls this directly

Calls 3

RunMethod · 0.95
IsSetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected