-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroot.go
96 lines (92 loc) · 2.86 KB
/
root.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package bump
import "github.com/spf13/cobra"
type Bumper interface {
Bump() error
WithRepository(repository string) error
WithDraft()
WithPrerelease()
WithDiscussionCategory(category string)
WithGenerateNotes()
WithNotes(notes string)
WithNotesFile(filename string)
WithTitle(title string)
WithTarget(target string)
WithAssetFiles(files []string)
WithBumpType(bumpType string) error
WithYes()
}
func NewRootCmd(bumper Bumper) *cobra.Command {
var (
repository string
isDraft bool
isPrerelease bool
discussionCategory string
generateNotes bool
notes string
notesFile string
target string
title string
assetFiles []string
bumpType string
yes bool
)
cmd := &cobra.Command{
Use: "bump",
Short: "bump version of a given repository",
RunE: func(cmd *cobra.Command, args []string) error {
if err := bumper.WithRepository(repository); err != nil {
return err
}
if isDraft {
bumper.WithDraft()
}
if isPrerelease {
bumper.WithPrerelease()
}
if discussionCategory != "" {
bumper.WithDiscussionCategory(discussionCategory)
}
if generateNotes {
bumper.WithGenerateNotes()
}
if notes != "" {
bumper.WithNotes(notes)
}
if notesFile != "" {
bumper.WithNotesFile(notesFile)
}
if target != "" {
bumper.WithTarget(target)
}
if title != "" {
bumper.WithTitle(title)
}
if len(assetFiles) > 0 {
bumper.WithAssetFiles(assetFiles)
}
if bumpType != "" {
err := bumper.WithBumpType(bumpType)
if err != nil {
return err
}
}
if yes {
bumper.WithYes()
}
return bumper.Bump()
},
}
cmd.Flags().StringVarP(&repository, "repo", "R", "", "Select another repository using the [HOST/]OWNER/REPO format")
cmd.Flags().BoolVarP(&isDraft, "draft", "d", false, "Save the release as a draft instead of publishing it")
cmd.Flags().BoolVarP(&isPrerelease, "prerelease", "p", false, "Mark the release as a prerelease")
cmd.Flags().StringVar(&discussionCategory, "discussion-category", "", "Start a discussion of the specified category")
cmd.Flags().BoolVarP(&generateNotes, "generate-notes", "g", false, "Automatically generate title and notes for the release")
cmd.Flags().StringVarP(¬es, "notes", "n", "", "Release notes")
cmd.Flags().StringVarP(¬esFile, "notes-file", "F", "", "Read release notes from file")
cmd.Flags().StringVar(&target, "target", "", "Target branch or full commit SHA (default: main branch)")
cmd.Flags().StringVarP(&title, "title", "t", "", "Release title")
cmd.Flags().StringSliceVar(&assetFiles, "asset-files", []string{}, "Asset files to upload")
cmd.Flags().StringVar(&bumpType, "bump-type", "", "Bump type (major, minor or patch)")
cmd.Flags().BoolVarP(&yes, "yes", "y", false, "Answer 'yes' to all questions")
return cmd
}