~ubuntu-branches/ubuntu/saucy/juju-core/saucy-updates

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cmd/juju/unset.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-03 14:22:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130903142222-9mes2r8wqr0bs7lp
Tags: 1.13.3-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        "launchpad.net/gnuflag"
 
10
 
 
11
        "launchpad.net/juju-core/charm"
 
12
        "launchpad.net/juju-core/cmd"
 
13
        "launchpad.net/juju-core/juju"
 
14
)
 
15
 
 
16
// UnsetCommand sets configuration values of a service back
 
17
// to their default.
 
18
type UnsetCommand struct {
 
19
        cmd.EnvCommandBase
 
20
        ServiceName string
 
21
        Options     []string
 
22
}
 
23
 
 
24
const unsetDoc = `
 
25
Set one or more configuration options for the specified service
 
26
to their default. See also the set commmand to set one or more 
 
27
configuration options for a specified service.
 
28
`
 
29
 
 
30
func (c *UnsetCommand) Info() *cmd.Info {
 
31
        return &cmd.Info{
 
32
                Name:    "unset",
 
33
                Args:    "<service> name ...",
 
34
                Purpose: "set service config options back to their default",
 
35
                Doc:     unsetDoc,
 
36
        }
 
37
}
 
38
 
 
39
func (c *UnsetCommand) SetFlags(f *gnuflag.FlagSet) {
 
40
        c.EnvCommandBase.SetFlags(f)
 
41
}
 
42
 
 
43
func (c *UnsetCommand) Init(args []string) error {
 
44
        if len(args) == 0 {
 
45
                return errors.New("no service name specified")
 
46
        }
 
47
        c.ServiceName = args[0]
 
48
        c.Options = args[1:]
 
49
        return nil
 
50
}
 
51
 
 
52
// Run resets the configuration of a service.
 
53
func (c *UnsetCommand) Run(ctx *cmd.Context) error {
 
54
        conn, err := juju.NewConnFromName(c.EnvName)
 
55
        if err != nil {
 
56
                return err
 
57
        }
 
58
        defer conn.Close()
 
59
        service, err := conn.State.Service(c.ServiceName)
 
60
        if err != nil {
 
61
                return err
 
62
        }
 
63
        if len(c.Options) > 0 {
 
64
                settings := make(charm.Settings)
 
65
                for _, option := range c.Options {
 
66
                        settings[option] = nil
 
67
                }
 
68
                return service.UpdateConfigSettings(settings)
 
69
        } else {
 
70
                return nil
 
71
        }
 
72
}