Skip to content

Commit

Permalink
add MustGetStringSliceExpanded
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Oct 13, 2021
1 parent 05384ab commit 2497cc6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions must.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ func MustGetStringSlice(cmd *cobra.Command, name string) []string {
return value
}

// MustGetStringSlice returns the []string value of a flag with the given name,
// calls os.ExpandEnv on values, and panics if that flag was never defined.
func MustGetStringSliceExpanded(cmd *cobra.Command, name string) []string {
slice := MustGetStringSlice(cmd, name)
for i, str := range slice {
slice[i] = os.ExpandEnv(str)
}
return slice
}

// MustGetStringToInt returns the map[string]int value of a flag with the given
// name and panics if that flag was never defined.
func MustGetStringToInt(cmd *cobra.Command, name string) map[string]int {
Expand Down

0 comments on commit 2497cc6

Please sign in to comment.