56
56
func (c *GetEnvironmentCommand) Run(ctx *cmd.Context) error {
57
conn, err := juju.NewConnFromName(c.EnvName)
63
// Get the existing environment config from the state.
64
config, err := conn.State.EnvironConfig()
68
attrs := config.AllAttrs()
70
// If no key specified, write out the whole lot.
72
return c.out.Write(ctx, attrs)
75
value, found := attrs[c.key]
77
return c.out.Write(ctx, value)
80
return fmt.Errorf("Key %q not found in %q environment.", c.key, config.Name())
57
client, err := juju.NewAPIClientFromName(c.EnvName)
63
attrs, err := client.EnvironmentGet()
69
if value, found := attrs[c.key]; found {
70
return c.out.Write(ctx, value)
72
return fmt.Errorf("Key %q not found in %q environment.", c.key, attrs["name"])
74
// If key is empty, write out the whole lot.
75
return c.out.Write(ctx, attrs)
83
78
type attributes map[string]interface{}
132
127
func (c *SetEnvironmentCommand) Run(ctx *cmd.Context) error {
133
conn, err := juju.NewConnFromName(c.EnvName)
128
client, err := juju.NewAPIClientFromName(c.EnvName)
139
// Here is the magic around setting the attributes:
140
// TODO(thumper): get this magic under test somewhere, and update other call-sites to use it.
141
// Get the existing environment config from the state.
142
oldConfig, err := conn.State.EnvironConfig()
146
// Apply the attributes specified for the command to the state config.
147
newConfig, err := oldConfig.Apply(c.values)
151
// Now validate this new config against the existing config via the provider.
152
provider := conn.Environ.Provider()
153
newProviderConfig, err := provider.Validate(newConfig, oldConfig)
157
// Now try to apply the new validated config.
158
return conn.State.SetEnvironConfig(newProviderConfig)
134
return client.EnvironmentSet(c.values)