57
57
modelcmd.ModelCommandBase
60
action func(*cmd.Context) error // The action which we want to handle, set in cmd.Init.
60
action func(configCommandAPI, *cmd.Context) error // The action which we want to handle, set in cmd.Init.
62
62
reset bool // Flag denoting whether we are resetting the keys provided.
155
155
// getAPI returns the API. This allows passing in a test configCommandAPI
156
156
// implementation.
157
func (c *configCommand) getAPI() error {
157
func (c *configCommand) getAPI() (configCommandAPI, error) {
158
158
if c.api != nil {
162
161
api, err := c.NewAPIRoot()
164
return errors.Annotate(err, "opening API connection")
163
return nil, errors.Annotate(err, "opening API connection")
166
c.api = modelconfig.NewClient(api)
165
client := modelconfig.NewClient(api)
170
169
// Run implements the meaty part of the cmd.Command interface.
171
170
func (c *configCommand) Run(ctx *cmd.Context) error {
171
client, err := c.getAPI()
177
return c.action(client, ctx)
181
180
// reset unsets the keys provided to the command.
182
func (c *configCommand) resetConfig(ctx *cmd.Context) error {
181
func (c *configCommand) resetConfig(client configCommandAPI, ctx *cmd.Context) error {
183
182
// ctx unused in this method
185
184
// extra call to the API to retrieve env config
186
envAttrs, err := c.api.ModelGet()
185
envAttrs, err := client.ModelGet()
204
return block.ProcessBlockedError(c.api.ModelUnset(c.keys...), block.BlockChange)
203
return block.ProcessBlockedError(client.ModelUnset(c.keys...), block.BlockChange)
207
206
// set sets the provided key/value pairs on the model.
208
func (c *configCommand) setConfig(ctx *cmd.Context) error {
207
func (c *configCommand) setConfig(client configCommandAPI, ctx *cmd.Context) error {
209
208
// ctx unused in this method.
210
envAttrs, err := c.api.ModelGet()
209
envAttrs, err := client.ModelGet()
220
return block.ProcessBlockedError(c.api.ModelSet(c.values), block.BlockChange)
219
return block.ProcessBlockedError(client.ModelSet(c.values), block.BlockChange)
223
222
// get writes the value of a single key or the full output for the model to the cmd.Context.
224
func (c *configCommand) getConfig(ctx *cmd.Context) error {
225
attrs, err := c.api.ModelGetWithMetadata()
223
func (c *configCommand) getConfig(client configCommandAPI, ctx *cmd.Context) error {
224
attrs, err := client.ModelGetWithMetadata()