Refactor podmanUnsetScript with a helper function
parent
716d793990
commit
9f983a8f99
|
@ -208,34 +208,7 @@ func podmanSetScript(ec PodmanEnvConfig, w io.Writer) error {
|
|||
|
||||
// podmanUnsetScript writes out a shell-compatible 'podman-env unset' script
|
||||
func podmanUnsetScript(ec PodmanEnvConfig, w io.Writer) error {
|
||||
// podman v1
|
||||
vars1 := []string{
|
||||
constants.PodmanVarlinkBridgeEnv,
|
||||
}
|
||||
// podman v2
|
||||
vars2 := []string{
|
||||
constants.PodmanContainerHostEnv,
|
||||
constants.PodmanContainerSSHKeyEnv,
|
||||
}
|
||||
// common
|
||||
vars0 := []string{
|
||||
constants.MinikubeActivePodmanEnv,
|
||||
}
|
||||
|
||||
var vars []string
|
||||
if ec.client != nil || ec.hostname != "" {
|
||||
// getting ec.varlink needs a running machine
|
||||
if ec.varlink {
|
||||
vars = vars1
|
||||
} else {
|
||||
vars = vars2
|
||||
}
|
||||
} else {
|
||||
// just unset *all* of the variables instead
|
||||
vars = vars1
|
||||
vars = append(vars, vars2...)
|
||||
}
|
||||
vars = append(vars, vars0...)
|
||||
vars := podmanEnvNames(ec)
|
||||
return shell.UnsetScript(ec.EnvConfig, w, vars)
|
||||
}
|
||||
|
||||
|
@ -281,6 +254,39 @@ func podmanEnvVars(ec PodmanEnvConfig) map[string]string {
|
|||
return env
|
||||
}
|
||||
|
||||
// podmanEnvNames gets the necessary podman env variables to reset after using minikube's podman service
|
||||
func podmanEnvNames(ec PodmanEnvConfig) []string {
|
||||
// podman v1
|
||||
vars1 := []string{
|
||||
constants.PodmanVarlinkBridgeEnv,
|
||||
}
|
||||
// podman v2
|
||||
vars2 := []string{
|
||||
constants.PodmanContainerHostEnv,
|
||||
constants.PodmanContainerSSHKeyEnv,
|
||||
}
|
||||
// common
|
||||
vars0 := []string{
|
||||
constants.MinikubeActivePodmanEnv,
|
||||
}
|
||||
|
||||
var vars []string
|
||||
if ec.client != nil || ec.hostname != "" {
|
||||
// getting ec.varlink needs a running machine
|
||||
if ec.varlink {
|
||||
vars = vars1
|
||||
} else {
|
||||
vars = vars2
|
||||
}
|
||||
} else {
|
||||
// just unset *all* of the variables instead
|
||||
vars = vars1
|
||||
vars = append(vars, vars2...)
|
||||
}
|
||||
vars = append(vars, vars0...)
|
||||
return vars
|
||||
}
|
||||
|
||||
func init() {
|
||||
podmanEnvCmd.Flags().StringVar(&shell.ForceShell, "shell", "", "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect")
|
||||
podmanEnvCmd.Flags().BoolVarP(&podmanUnset, "unset", "u", false, "Unset variables instead of setting them")
|
||||
|
|
Loading…
Reference in New Issue