Skip to content

Commit 3d3156f

Browse files
author
Stefano Ciarcià
committed
fix: flags resolution
1 parent bd91dd6 commit 3d3156f

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

.vscode/launch.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
"mode": "debug",
1212
"program": "${workspaceFolder}/main.go",
1313
"args": [
14-
"krew",
15-
"install",
16-
"v0.4.5"
14+
"kubectl",
15+
"list-remote",
16+
// "--force",
17+
// "--limit",
18+
// "10"
1719
],
1820
"env": {
1921
"GITHUB_TOKEN": "<my-token>"

cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ func Execute() {
4040

4141
func init() {
4242
// global flags
43+
// config file
44+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.vrsr/config.yaml)")
45+
// bin path
4346
defaultBinPath, err := utils.GetDefaultBinPath()
4447
if err != nil {
4548
fmt.Fprintln(os.Stderr, "Error determining default bin path:", err)
4649
os.Exit(1)
4750
}
4851
rootCmd.PersistentFlags().StringP("bin-path", "b", defaultBinPath, "Absolute path to folder storing in-use tools binaries")
52+
// vrs path
4953
defaultVrsPath, err := utils.GetDefaultVrsPath()
5054
if err != nil {
5155
fmt.Fprintln(os.Stderr, "Error determining default vrs path:", err)

config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
# kubectl:
1010
# list-remote:
1111
# devel: true
12-
# limit: 10
12+
# limit: 21
1313
# force: true
1414
# kind:
1515
# list-remote:
1616
# devel: true
1717
# limit: 10
1818
# force: true
19+
# helm:
20+
# list-remote:
21+
# devel: true
22+
# limit: 10
23+
# force: true

internal/cli/common/listRemote.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ func newGithubListRemoteCommand(tool string, repoConf github.RepoConfDef) *cobra
3030
return listRemoteGithub(cmd, tool, repoConf)
3131
},
3232
}
33+
// Bind flags to Viper keys so config file / env / flags work together.
3334
listRemoteCmd.Flags().BoolVar(&includeDevel, "devel", false, "Include pre-release versions (alpha, beta, rc)")
35+
viper.BindPFlag(fmt.Sprintf("%s.list-remote.devel", tool), listRemoteCmd.Flags().Lookup("devel"))
3436
listRemoteCmd.Flags().IntVarP(&limit, "limit", "l", 0, "Limit number of versions displayed")
37+
viper.BindPFlag(fmt.Sprintf("%s.list-remote.limit", tool), listRemoteCmd.Flags().Lookup("limit"))
3538
listRemoteCmd.Flags().BoolVarP(&forceRefresh, "force", "f", false, "Force refresh of remote versions cache")
39+
viper.BindPFlag(fmt.Sprintf("%s.list-remote.force", tool), listRemoteCmd.Flags().Lookup("force"))
3640
return listRemoteCmd
3741
}
3842

3943
// listRemoteGithub lists all remote versions of the specified tool available as GitHub releases (sorted by semver)
4044
func listRemoteGithub(cmd *cobra.Command, tool string, repoConf github.RepoConfDef) error {
41-
includeDevel = viper.GetBool(tool + "list-remote.devel")
42-
limit = viper.GetInt(tool + "list-remote.limit")
43-
forceRefresh = viper.GetBool(tool + "list-remote.force")
45+
includeDevel = viper.GetBool(tool + ".list-remote.devel")
46+
limit = viper.GetInt(tool + ".list-remote.limit")
47+
forceRefresh = viper.GetBool(tool + ".list-remote.force")
4448
ghc := github.New(nil)
4549
releasesData, err := ghc.FetchAllReleases(tool, github.FetchOptions{
4650
IncludeDevel: includeDevel,

0 commit comments

Comments
 (0)