Skip to content

Commit

Permalink
BOSH_ENVIRONMENT and BOSH_DEPLOYMENT are used
Browse files Browse the repository at this point in the history
Flags override envvars, just like in the bosh cli. `bosh is` users
rejoice.
  • Loading branch information
thomasmitchell committed Oct 9, 2018
1 parent 854b7fc commit 6ace750
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ type compContext struct {
Switches []string
}

func (c *compContext) InsertIfEnvvar(envvar, flag string) {
val := os.Getenv(envvar)
if val != "" {
c.Flags[flag] = append(c.Flags[flag], val)
}
}

func (c compContext) Complete() ([]string, error) {
var compFn compFunc

Expand Down Expand Up @@ -151,5 +158,14 @@ func parseContext(args []string) compContext {
}
}

//Flags override environment variables, so put in env vars last... they would
// become the second flag value, which is typically ignored in the code
ret.InsertIfEnvvar("BOSH_ENVIRONMENT", "--environment")
ret.InsertIfEnvvar("BOSH_DEPLOYMENT", "--deployment")
ret.InsertIfEnvvar("BOSH_CLIENT", "--client")
ret.InsertIfEnvvar("BOSH_CLIENT_SECRET", "--client-secret")
ret.InsertIfEnvvar("BOSH_NON_INTERACTIVE", "--non-interactive")
ret.InsertIfEnvvar("BOSH_CA_CERT", "--ca-cert")

return ret
}
3 changes: 3 additions & 0 deletions testing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
make
unset -f _bosh_comp
eval "$(./bosh-complete --debug bash-source)"

0 comments on commit 6ace750

Please sign in to comment.