-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix config file flags in subcommands (#7475)
- Loading branch information
Showing
11 changed files
with
115 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/shared/testutil/require" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func TestLoadFlagsFromConfig(t *testing.T) { | ||
app := cli.App{} | ||
set := flag.NewFlagSet("test", 0) | ||
context := cli.NewContext(&app, set, nil) | ||
|
||
require.NoError(t, ioutil.WriteFile("flags_test.yaml", []byte("testflag: 100"), 0666)) | ||
|
||
require.NoError(t, set.Parse([]string{"test-command", "--" + ConfigFileFlag.Name, "flags_test.yaml"})) | ||
command := &cli.Command{ | ||
Name: "test-command", | ||
Flags: WrapFlags([]cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: ConfigFileFlag.Name, | ||
}, | ||
&cli.IntFlag{ | ||
Name: "testflag", | ||
Value: 0, | ||
}, | ||
}), | ||
Before: func(cliCtx *cli.Context) error { | ||
return LoadFlagsFromConfig(cliCtx, cliCtx.Command.Flags) | ||
}, | ||
Action: func(cliCtx *cli.Context) error { | ||
require.Equal(t, 100, cliCtx.Int("testflag")) | ||
return nil | ||
}, | ||
} | ||
require.NoError(t, command.Run(context)) | ||
require.NoError(t, os.Remove("flags_test.yaml")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.