storj-sim: add option to print a single variable (#1720)

This commit is contained in:
Egon Elbre 2019-04-09 21:16:12 -04:00 committed by GitHub
parent ba891538af
commit f5155aeb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -66,7 +66,7 @@ func main() {
return networkExec(&flags, args, "run")
},
}, &cobra.Command{
Use: "env",
Use: "env [name]",
Short: "print environment variables",
RunE: func(cmd *cobra.Command, args []string) (err error) {
return networkEnv(&flags, args)

View File

@ -70,6 +70,19 @@ func networkEnv(flags *Flags, args []string) error {
}
}
if len(args) == 1 {
envprefix := strings.ToUpper(args[0] + "=")
// find the environment value that the environment variable is set to
for _, env := range processes.Env() {
if strings.HasPrefix(strings.ToUpper(env), envprefix) {
fmt.Println(env[len(envprefix):])
return nil
}
}
return nil
}
for _, env := range processes.Env() {
fmt.Println(env)
}