forked from rcmachado/changelog
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
changetype.go
42 lines (33 loc) · 990 Bytes
/
changetype.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
package cmd
import (
"fmt"
"strings"
"github.com/cucumber/changelog/chg"
"github.com/cucumber/changelog/parser"
"github.com/spf13/cobra"
)
func newChangeTypeCmd(iostreams *IOStreams, ct chg.ChangeType) *cobra.Command {
sectionName := ct.String()
return &cobra.Command{
Use: strings.ToLower(sectionName),
Short: fmt.Sprintf("Add item under '%s' section", sectionName),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
changelog := parser.Parse(iostreams.In)
changelog.AddItem(ct, strings.Join(args, " "))
changelog.Render(iostreams.Out)
},
}
}
func newChangeTypeCmds(iostreams *IOStreams) []*cobra.Command {
cmdTypes := []chg.ChangeType{
chg.Added, chg.Changed, chg.Deprecated, chg.Fixed, chg.Removed, chg.Security,
}
allCmds := make([]*cobra.Command, len(cmdTypes))
for idx, changeType := range cmdTypes {
cmdType := changeType
cmd := newChangeTypeCmd(iostreams, cmdType)
allCmds[idx] = cmd
}
return allCmds
}