Skip to content

Commit a7331f4

Browse files
committed
Append quotes if set flag
1 parent 0767ac8 commit a7331f4

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

checkenv.go

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

11-
const CHECKENV_VERSION = "v0.0.3"
11+
const CHECKENV_VERSION = "v0.0.4"
1212

1313
type showSpec struct {
1414
loadFrom map[string]interface{}
@@ -56,6 +56,15 @@ func VariablesFromProviderSpec(providerSpec string) (map[string]string, error) {
5656
return plugin.Provider(providerArgs)
5757
}
5858

59+
// Append quotes to value if needed
60+
func AddValueQuotes(val string, showQuotes bool) string {
61+
if showQuotes {
62+
return fmt.Sprintf("\"%s\"", val)
63+
}
64+
65+
return val
66+
}
67+
5968
func main() {
6069
pluginsCommand := "plugins"
6170
pluginsFlags := flag.NewFlagSet("plugins", flag.ExitOnError)
@@ -67,6 +76,7 @@ func main() {
6776
showHelp := showFlags.Bool("h", false, "Use this flag if you want help with this command")
6877
showFlags.BoolVar(showHelp, "help", false, "Use this flag if you want help with this command")
6978
showExport := showFlags.Bool("export", false, "Use this flag to prepend and \"export \" before every environment variable definition")
79+
showQuotes := showFlags.Bool("quotes", false, "Use this flag to put value in quotes")
7080
showRaw := showFlags.Bool("raw", false, "Use this flag to prevent comments output")
7181
showValue := showFlags.Bool("value", false, "Print value only")
7282

@@ -119,9 +129,9 @@ func main() {
119129
}
120130
for k, v := range providedVars[providerSpec] {
121131
if !*showValue {
122-
fmt.Printf("%s%s=%s\n", exportPrefix, k, v)
132+
fmt.Printf("%s%s=%s\n", exportPrefix, k, AddValueQuotes(v, *showQuotes))
123133
} else {
124-
fmt.Printf("%s\n", v)
134+
fmt.Printf("%s\n", AddValueQuotes(v, *showQuotes))
125135
}
126136
}
127137
}
@@ -136,9 +146,9 @@ func main() {
136146
fmt.Printf("# UNDEFINED: %s\n", k)
137147
} else {
138148
if !*showValue {
139-
fmt.Printf("%s%s=%s\n", exportPrefix, k, v)
149+
fmt.Printf("%s%s=%s\n", exportPrefix, k, AddValueQuotes(v, *showQuotes))
140150
} else {
141-
fmt.Printf("%s\n", v)
151+
fmt.Printf("%s\n", AddValueQuotes(v, *showQuotes))
142152
}
143153
}
144154
}

dev.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ PROGRAM_NAME="checkenv_dev"
88
go build -o "$PROGRAM_NAME" .
99

1010
./"$PROGRAM_NAME" "$@"
11-

0 commit comments

Comments
 (0)