Skip to content

Commit 93af252

Browse files
authored
Merge pull request #16 from bugout-dev/remove-prefix
Remove path from param keys flag
2 parents 8445a02 + 1395f17 commit 93af252

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

checkenv.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
)
1010

11-
const CHECKENV_VERSION = "v0.0.5"
11+
const CHECKENV_VERSION = "v0.0.6"
1212

1313
type showSpec struct {
1414
loadFrom map[string]interface{}
@@ -65,6 +65,16 @@ func AddValueQuotes(val string, showQuotes bool) string {
6565
return val
6666
}
6767

68+
// Cut off the path and return only the key after the '/'.
69+
func RemoveKeyPath(key string, removePath bool) string {
70+
if removePath {
71+
valSlice := strings.Split(key, "/")
72+
return valSlice[len(valSlice)-1]
73+
}
74+
75+
return key
76+
}
77+
6878
func main() {
6979
pluginsCommand := "plugins"
7080
pluginsFlags := flag.NewFlagSet("plugins", flag.ExitOnError)
@@ -77,6 +87,7 @@ func main() {
7787
showFlags.BoolVar(showHelp, "help", false, "Use this flag if you want help with this command")
7888
showExport := showFlags.Bool("export", false, "Use this flag to prepend and \"export \" before every environment variable definition")
7989
showQuotes := showFlags.Bool("quotes", false, "Use this flag to put value in quotes")
90+
showRemovePath := showFlags.Bool("remove-path", false, "Use this flag to cut off the path and return only the key after the '/'")
8091
showRaw := showFlags.Bool("raw", false, "Use this flag to prevent comments output")
8192
showValue := showFlags.Bool("value", false, "Print value only")
8293
showName := showFlags.Bool("name", false, "Print name only")
@@ -136,11 +147,11 @@ func main() {
136147
}
137148
for k, v := range providedVars[providerSpec] {
138149
if !*showValue && !*showName {
139-
fmt.Printf("%s%s=%s\n", exportPrefix, k, AddValueQuotes(v, *showQuotes))
150+
fmt.Printf("%s%s=%s\n", exportPrefix, RemoveKeyPath(k, *showRemovePath), AddValueQuotes(v, *showQuotes))
140151
} else if *showValue {
141152
fmt.Printf("%s\n", AddValueQuotes(v, *showQuotes))
142153
} else if *showName {
143-
fmt.Printf("%s\n", k)
154+
fmt.Printf("%s\n", RemoveKeyPath(k, *showRemovePath))
144155
}
145156
}
146157
}

0 commit comments

Comments
 (0)