~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/cmd/charm-admin/deletecharm.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-29 11:40:20 UTC
  • mfrom: (23.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140129114020-ejieitm8smtt5vln
Tags: 1.17.1-0ubuntu2
d/tests/local-provider: Don't fail tests if ~/.juju is present as its
created by the juju version command. 

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
        "fmt"
 
8
 
 
9
        "launchpad.net/gnuflag"
 
10
 
 
11
        "launchpad.net/juju-core/charm"
 
12
        "launchpad.net/juju-core/cmd"
 
13
        "launchpad.net/juju-core/store"
 
14
)
 
15
 
 
16
type DeleteCharmCommand struct {
 
17
        ConfigCommand
 
18
        Url string
 
19
}
 
20
 
 
21
func (c *DeleteCharmCommand) Info() *cmd.Info {
 
22
        return &cmd.Info{
 
23
                Name:    "delete-charm",
 
24
                Purpose: "delete a published charm from the charm store",
 
25
        }
 
26
}
 
27
 
 
28
func (c *DeleteCharmCommand) SetFlags(f *gnuflag.FlagSet) {
 
29
        c.ConfigCommand.SetFlags(f)
 
30
        f.StringVar(&c.Url, "url", "", "charm URL")
 
31
}
 
32
 
 
33
func (c *DeleteCharmCommand) Init(args []string) error {
 
34
        // Check flags
 
35
        err := c.ConfigCommand.Init(args)
 
36
        if err != nil {
 
37
                return err
 
38
        }
 
39
        if c.Url == "" {
 
40
                return fmt.Errorf("--url is required")
 
41
        }
 
42
        return nil
 
43
}
 
44
 
 
45
func (c *DeleteCharmCommand) Run(ctx *cmd.Context) error {
 
46
        // Read config
 
47
        err := c.ConfigCommand.ReadConfig(ctx)
 
48
        if err != nil {
 
49
                return err
 
50
        }
 
51
 
 
52
        // Parse the charm URL
 
53
        charmUrl, err := charm.ParseURL(c.Url)
 
54
        if err != nil {
 
55
                return err
 
56
        }
 
57
 
 
58
        // Open the charm store storage
 
59
        s, err := store.Open(c.Config.MongoURL)
 
60
        if err != nil {
 
61
                return err
 
62
        }
 
63
        defer s.Close()
 
64
 
 
65
        // Delete the charm by URL
 
66
        _, err = s.DeleteCharm(charmUrl)
 
67
        if err != nil {
 
68
                return err
 
69
        }
 
70
        fmt.Fprintln(ctx.Stdout, "Charm", charmUrl, "deleted.")
 
71
        return nil
 
72
}
 
73
 
 
74
func (c *DeleteCharmCommand) AllowInterspersedFlags() bool {
 
75
        return true
 
76
}