|
|
|
@ -10,12 +10,15 @@ import (
|
|
|
|
|
// Env is a shell environment factory for this cluster
|
|
|
|
|
type Env struct { |
|
|
|
|
ZoneIterator |
|
|
|
|
|
|
|
|
|
export bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Env returns a shell environment factory
|
|
|
|
|
func (m *Zones) Env() *Env { |
|
|
|
|
func (m *Zones) Env(export bool) *Env { |
|
|
|
|
return &Env{ |
|
|
|
|
ZoneIterator: m, |
|
|
|
|
export: export, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -63,7 +66,13 @@ func (m *Env) writeEnvVarFn(w io.Writer, fn func(*Env) string, name string, args
|
|
|
|
|
m.writeEnvVar(w, value, name, args...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (*Env) writeEnvVar(w io.Writer, value string, name string, args ...any) { |
|
|
|
|
func (m *Env) writeEnvVar(w io.Writer, value string, name string, args ...any) { |
|
|
|
|
var prefix string |
|
|
|
|
|
|
|
|
|
if m.export { |
|
|
|
|
prefix = "export " |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(args) > 0 { |
|
|
|
|
name = fmt.Sprintf(name, args...) |
|
|
|
|
} |
|
|
|
@ -71,7 +80,7 @@ func (*Env) writeEnvVar(w io.Writer, value string, name string, args ...any) {
|
|
|
|
|
if name != "" { |
|
|
|
|
value = strings.TrimSpace(value) |
|
|
|
|
|
|
|
|
|
_, _ = fmt.Fprintf(w, "%s=%q\n", name, value) |
|
|
|
|
_, _ = fmt.Fprintf(w, "%s%s=%q\n", prefix, name, value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|