88 "strings"
99)
1010
11- const CHECKENV_VERSION = "v0.0.3 "
11+ const CHECKENV_VERSION = "v0.0.4 "
1212
1313type 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+
5968func 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 showName := showFlags .Bool ("name" , false , "Print name only" )
@@ -126,9 +136,9 @@ func main() {
126136 }
127137 for k , v := range providedVars [providerSpec ] {
128138 if ! * showValue && ! * showName {
129- fmt .Printf ("%s%s=%s\n " , exportPrefix , k , v )
139+ fmt .Printf ("%s%s=%s\n " , exportPrefix , k , AddValueQuotes ( v , * showQuotes ) )
130140 } else if * showValue {
131- fmt .Printf ("%s\n " , v )
141+ fmt .Printf ("%s\n " , AddValueQuotes ( v , * showQuotes ) )
132142 } else if * showName {
133143 fmt .Printf ("%s\n " , k )
134144 }
@@ -145,9 +155,9 @@ func main() {
145155 fmt .Printf ("# UNDEFINED: %s\n " , k )
146156 } else {
147157 if ! * showValue {
148- fmt .Printf ("%s%s=%s\n " , exportPrefix , k , v )
158+ fmt .Printf ("%s%s=%s\n " , exportPrefix , k , AddValueQuotes ( v , * showQuotes ) )
149159 } else {
150- fmt .Printf ("%s\n " , v )
160+ fmt .Printf ("%s\n " , AddValueQuotes ( v , * showQuotes ) )
151161 }
152162 }
153163 }
0 commit comments