-
Notifications
You must be signed in to change notification settings - Fork 491
/
state-delete.go
64 lines (55 loc) · 1.49 KB
/
state-delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuc
import (
"github.com/juju/cmd/v3"
jujucmd "github.com/juju/juju/cmd"
)
// StateDeleteCommand implements the state-delete command.
type StateDeleteCommand struct {
cmd.CommandBase
ctx Context
Key string // The key to delete
}
// NewStateDeleteCommand returns a state-delete command.
func NewStateDeleteCommand(ctx Context) (cmd.Command, error) {
return &StateDeleteCommand{ctx: ctx}, nil
}
// Info returns information about the Command.
// Info implements part of the cmd.Command interface.
func (c *StateDeleteCommand) Info() *cmd.Info {
doc := `
state-delete deletes the value of the server side state specified by key.
See also:
state-get
state-set
`
return jujucmd.Info(&cmd.Info{
Name: "state-delete",
Args: "<key>",
Purpose: "delete server-side-state key value pair",
Doc: doc,
})
}
// Init initializes the Command before running.
// Init implements part of the cmd.Command interface.
func (c *StateDeleteCommand) Init(args []string) error {
if args == nil {
return nil
}
c.Key = args[0]
return cmd.CheckEmpty(args[1:])
}
// Run will execute the Command as directed by the options and positional
// arguments passed to Init.
// Run implements part of the cmd.Command interface.
func (c *StateDeleteCommand) Run(ctx *cmd.Context) error {
if c.Key == "" {
return nil
}
err := c.ctx.DeleteCharmStateValue(c.Key)
if err != nil {
return err
}
return nil
}