-
Notifications
You must be signed in to change notification settings - Fork 0
/
createlistcommand.go
53 lines (39 loc) · 1.13 KB
/
createlistcommand.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
package main
import (
"fmt"
"io"
)
//CreateListCommand is a struct that
//facilitates the deletion of lists.
type CreateListCommand struct {
definition string
description string
List string
}
//NewCreateListCommand creates a command that
//can be used to Create the specified list.
func NewCreateListCommand(list string) *CreateListCommand {
command := new(CreateListCommand)
command.definition = "goboom <list>"
command.description = "Creates the specified list."
command.List = list
return command
}
//GetDescription retrieves a description of what the command does.
func (c *CreateListCommand) GetDescription() string {
return c.description
}
//GetDefinition retrieves definition to use for this command.
func (c *CreateListCommand) GetDefinition() string {
return c.definition
}
//Execute runs the current command.
func (c *CreateListCommand) Execute(w io.Writer, s Storage) {
list := make(map[string][]map[string]string, 1)
list[c.List] = make([]map[string]string, 0)
s.Lists = append(s.Lists, list)
//Persist our data back.
s.Save()
//Notify the user.
fmt.Fprintf(w, "List '%v' successfully Created!\n", c.List)
}