jpictl: introduce -e for jpictl env to export variables

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-27 15:26:35 +00:00
parent 864eb02f9d
commit 6ee848e6ca
2 changed files with 21 additions and 4 deletions
+12 -3
View File
@@ -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)
}
}