github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/cmd/juju/unset.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package main 5 6 import ( 7 "errors" 8 9 "github.com/juju/cmd" 10 11 "github.com/juju/juju/cmd/envcmd" 12 "github.com/juju/juju/cmd/juju/block" 13 ) 14 15 // UnsetCommand sets configuration values of a service back 16 // to their default. 17 type UnsetCommand struct { 18 envcmd.EnvCommandBase 19 ServiceName string 20 Options []string 21 } 22 23 const unsetDoc = ` 24 Set one or more configuration options for the specified service to their 25 default. See also the set commmand to set one or more configuration options for 26 a specified service. 27 ` 28 29 func (c *UnsetCommand) Info() *cmd.Info { 30 return &cmd.Info{ 31 Name: "unset", 32 Args: "<service> name ...", 33 Purpose: "set service config options back to their default", 34 Doc: unsetDoc, 35 } 36 } 37 38 func (c *UnsetCommand) Init(args []string) error { 39 if len(args) == 0 { 40 return errors.New("no service name specified") 41 } 42 c.ServiceName = args[0] 43 c.Options = args[1:] 44 if len(c.Options) == 0 { 45 return errors.New("no configuration options specified") 46 } 47 return nil 48 } 49 50 // Run resets the configuration of a service. 51 func (c *UnsetCommand) Run(ctx *cmd.Context) error { 52 apiclient, err := c.NewAPIClient() 53 if err != nil { 54 return err 55 } 56 defer apiclient.Close() 57 return block.ProcessBlockedError(apiclient.ServiceUnset(c.ServiceName, c.Options), block.BlockChange) 58 }