Skip to content

Commit 6c4fc10

Browse files
committed
Various cobra cleanup and added banner
1 parent 6686a6d commit 6c4fc10

File tree

13 files changed

+111
-169
lines changed

13 files changed

+111
-169
lines changed

banner.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
_ _ _ _
3+
__| | _____ _____ _ __ ___ __| | __ _ _ _ ___ ___| (_)
4+
/ _` |/ _ \ \ / / _ \| '_ \/ __|/ _` |/ _` | | | / __|_____ / __| | |
5+
| (_| | __/\ V / (_) | |_) \__ \ (_| | (_| | |_| \__ \_____| (__| | |
6+
\__,_|\___| \_/ \___/| .__/|___/\__,_|\__,_|\__, |___/ \___|_|_|
7+
|_| |___/

cmd/add.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,12 @@ import (
66

77
// addCmd represents the add command
88
var addCmd = &cobra.Command{
9-
Use: "add [thing]",
10-
Short: "Add a thing to another thing",
11-
Long: `Use this to add sponsors to events, etc.`,
12-
// Args: cobra.MinimumNArgs(1),
13-
// Run: func(cmd *cobra.Command, args []string) {
14-
// // TODO: Work your own magic here
15-
// fmt.Println("add called")
16-
// },
9+
Use: "add [item]",
10+
Short: "Add items to talks, programs, or events",
11+
Long: `Use this to add sponsors to events, talks to programs, etc.`,
1712
}
1813

1914
func init() {
2015
RootCmd.AddCommand(addCmd)
2116

22-
// Here you will define your flags and configuration settings.
23-
24-
// Cobra supports Persistent Flags which will work for this command
25-
// and all subcommands, e.g.:
26-
// addCmd.PersistentFlags().String("foo", "", "A help for foo")
27-
28-
// Cobra supports local flags which will only run when this command
29-
// is called directly, e.g.:
30-
// addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
31-
3217
}

cmd/create.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,12 @@ import (
66

77
// createCmd represents the create command
88
var createCmd = &cobra.Command{
9-
Use: "create [thing]",
10-
Short: "Make a new thing",
9+
Use: "create [item]",
10+
Short: "Create a new event, organizer, program, speaker, sponsor, or talk",
1111
Long: `Use this to create events, sponsors, talks, etc`,
12-
// Args: cobra.MinimumNArgs(1),
13-
// Run: func(cmd *cobra.Command, args []string) {
14-
// // TODO: Work your own magic here
15-
// fmt.Println("create called")
16-
// },
1712
}
1813

1914
func init() {
2015
RootCmd.AddCommand(createCmd)
2116

22-
// Here you will define your flags and configuration settings.
23-
24-
// Cobra supports Persistent Flags which will work for this command
25-
// and all subcommands, e.g.:
26-
// createCmd.PersistentFlags().String("foo", "", "A help for foo")
27-
28-
// Cobra supports local flags which will only run when this command
29-
// is called directly, e.g.:
30-
// createCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
31-
3217
}

cmd/edit.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,12 @@ import (
66

77
// editCmd represents the edit command
88
var editCmd = &cobra.Command{
9-
Use: "edit [thing]",
10-
Short: "Edit an existing thing",
9+
Use: "edit [item]",
10+
Short: "Edit an existing item",
1111
Long: `Use this to edit events, talks, organizers, etc.`,
12-
// Args: cobra.MinimumNArgs(1),
13-
// Run: func(cmd *cobra.Command, args []string) {
14-
// // TODO: Work your own magic here
15-
// fmt.Println("edit called")
16-
// },
1712
}
1813

1914
func init() {
2015
RootCmd.AddCommand(editCmd)
2116

22-
// Here you will define your flags and configuration settings.
23-
24-
// Cobra supports Persistent Flags which will work for this command
25-
// and all subcommands, e.g.:
26-
// editCmd.PersistentFlags().String("foo", "", "A help for foo")
27-
28-
// Cobra supports local flags which will only run when this command
29-
// is called directly, e.g.:
30-
// editCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
31-
3217
}

cmd/event.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ to quickly create a Cobra application.`,
6060
Run: func(cmd *cobra.Command, args []string) {
6161
// TODO: Work your own magic here
6262
// TODO: Check for args first
63-
city := cityFlag
64-
year := yearFlag
63+
city := ""
64+
year := ""
6565
if city != "" {
6666
if helpers.CheckEvent(city, year) == false {
6767
log.Fatal("That city does not exist.")
@@ -106,15 +106,12 @@ func init() {
106106
editCmd.AddCommand(editEventCmd)
107107
showCmd.AddCommand(showEventCmd)
108108

109-
// Here you will define your flags and configuration settings.
110-
111-
// Cobra supports Persistent Flags which will work for this command
112-
// and all subcommands, e.g.:
113-
// eventCmd.PersistentFlags().String("foo", "", "A help for foo")
114-
115-
// Cobra supports local flags which will only run when this command
116-
// is called directly, e.g.:
117-
// eventCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
109+
createEventCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
110+
createEventCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
111+
editEventCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
112+
editEventCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
113+
showEventCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
114+
showEventCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
118115

119116
}
120117

cmd/organizer.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ func init() {
7676
removeCmd.AddCommand(removeOrganizerCmd)
7777
showCmd.AddCommand(showOrganizerCmd)
7878

79-
// Here you will define your flags and configuration settings.
80-
81-
// Cobra supports Persistent Flags which will work for this command
82-
// and all subcommands, e.g.:
83-
// OrganizerCmd.PersistentFlags().String("foo", "", "A help for foo")
84-
85-
// Cobra supports local flags which will only run when this command
86-
// is called directly, e.g.:
87-
// OrganizerCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
79+
createOrganizerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
80+
createOrganizerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
81+
editOrganizerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
82+
editOrganizerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
83+
removeOrganizerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
84+
removeOrganizerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
85+
showOrganizerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
86+
showOrganizerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
87+
showOrganizerCmd.Flags().BoolVarP(&All, "all", "a", false, "show all")
8888

8989
}
9090

cmd/remove.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,12 @@ import (
66

77
// addCmd represents the remove command
88
var removeCmd = &cobra.Command{
9-
Use: "remove [thing]",
10-
Short: "Remove a thing from another thing",
11-
Long: `Use this to remove sponsors to events, etc.`,
12-
// Args: cobra.MinimumNArgs(1),
13-
// Run: func(cmd *cobra.Command, args []string) {
14-
// // TODO: Work your own magic here
15-
// fmt.Println("remove called")
16-
// },
9+
Use: "remove [item]",
10+
Short: "Remove items from an event, a talk, or a program",
11+
Long: `Use this to remove sponsors from events, etc.`,
1712
}
1813

1914
func init() {
2015
RootCmd.AddCommand(removeCmd)
2116

22-
// Here you will define your flags and configuration settings.
23-
24-
// Cobra supports Persistent Flags which will work for this command
25-
// and all subcommands, e.g.:
26-
// addCmd.PersistentFlags().String("foo", "", "A help for foo")
27-
28-
// Cobra supports local flags which will only run when this command
29-
// is called directly, e.g.:
30-
// addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
31-
3217
}

cmd/root.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@ var webdir = setWebdir()
1717
// const webdir = "/Users/mattstratton/src/devopsdays-web"
1818

1919
var cfgFile string
20-
var cityFlag string
21-
var yearFlag string
20+
21+
// Debug means should we run in debug mode. Duh.
22+
var Debug bool
23+
24+
// City is the city we will be using - obtained via local flag
25+
var City string
26+
27+
// Year is the year we will be using - obtained via local flag
28+
var Year string
29+
30+
// All is used by a flag on Show commands to represent showing all of a thing
31+
var All bool
2232

2333
// RootCmd represents the base command when called without any subcommands
2434
var RootCmd = &cobra.Command{
2535
Use: "devopsdays-cli",
2636
Short: "Run maintenance tasks for the devopsdays.org website",
27-
Long: `Command-line utilities for the devopsdays.org website
37+
Long: `
38+
Command-line utilities for the devopsdays.org website
2839
built with love by mattstratton in Go.
2940
3041
Complete documentation is available at https://github.com/devopsdays/devopsdays-cli`,
@@ -41,17 +52,8 @@ func Execute() {
4152

4253
func init() {
4354
cobra.OnInitialize(initConfig)
44-
RootCmd.PersistentFlags().StringVarP(&cityFlag, "city", "c", "", "city name")
45-
RootCmd.PersistentFlags().StringVarP(&yearFlag, "year", "y", "", "year")
46-
47-
// Here you will define your flags and configuration settings.
48-
// Cobra supports Persistent Flags, which, if defined here,
49-
// will be global for your application.
55+
RootCmd.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "enable debug mode")
5056

51-
// RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.devopsdays.yaml)")
52-
// Cobra also supports local flags, which will only run
53-
// when this action is called directly.
54-
// RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
5557
}
5658

5759
// initConfig reads in config file and ENV variables if set.

cmd/show.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,12 @@ import (
66

77
// showCmd represents the show command
88
var showCmd = &cobra.Command{
9-
Use: "show",
10-
Short: "Show details about a thing",
9+
Use: "show [item]",
10+
Short: "Show details about various items",
1111
Long: `The show command displays information about events, sponsors, talks, configuration, etc.`,
12-
// Run: func(cmd *cobra.Command, args []string) {
13-
// // TODO: Work your own magic here
14-
// fmt.Println("show called")
15-
// },
1612
}
1713

1814
func init() {
1915
RootCmd.AddCommand(showCmd)
2016

21-
// Here you will define your flags and configuration settings.
22-
23-
// Cobra supports Persistent Flags which will work for this command
24-
// and all subcommands, e.g.:
25-
// showCmd.PersistentFlags().String("foo", "", "A help for foo")
26-
27-
// Cobra supports local flags which will only run when this command
28-
// is called directly, e.g.:
29-
// showCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
30-
3117
}

cmd/speaker.go

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
var addSpeakerCmd = &cobra.Command{
1212
Use: "speaker",
1313
Short: "Add a speaker to an existing talk",
14-
Long: `Add a speaker to an existing talk
15-
16-
You can provide the speaker's name as an argument to this command, but it must be in quotes. For example:
17-
devopsdays-cli create speaker "George Bluth"`,
14+
Long: `Add a speaker to an existing talk.
15+
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name.
16+
`,
17+
Example: ` devopsdays-cli add speaker george-bluth
18+
devopsdays-cli add speaker --city new-york
19+
devopsdays-cli add speaker george-bluth -c "New York" --year "2017"`,
1820
Args: cobra.MaximumNArgs(1),
1921
Run: func(cmd *cobra.Command, args []string) {
2022
// TODO: Work your own magic here
@@ -26,10 +28,13 @@ You can provide the speaker's name as an argument to this command, but it must b
2628
var createSpeakerCmd = &cobra.Command{
2729
Use: "speaker",
2830
Short: "Creates a new speaker for an event",
29-
Long: `Creates a new speaker for an event
31+
Long: `Creates a new speaker for an event.
32+
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name.
33+
`,
34+
Example: ` devopsdays-cli create speaker george-bluth
35+
devopsdays-cli create speaker --city new-york
36+
devopsdays-cli create speaker george-bluth -c "New York" --year "2017"`,
3037

31-
You can provide the speaker's name as an argument to this command, but it must be in quotes. For example:
32-
devopsdays-cli create speaker "George Bluth"`,
3338
Args: cobra.MaximumNArgs(1),
3439
Run: func(cmd *cobra.Command, args []string) {
3540
if len(args) > 0 {
@@ -44,11 +49,12 @@ devopsdays-cli create speaker "George Bluth"`,
4449
var editSpeakerCmd = &cobra.Command{
4550
Use: "speaker",
4651
Short: "Edit an event's speaker",
47-
Long: `Edit an event's speaker
48-
49-
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name. For example:
50-
51-
devopsdays-cli edit speaker george-bluth`,
52+
Long: `Edit an event's speaker.
53+
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name.
54+
`,
55+
Example: ` devopsdays-cli edit speaker george-bluth
56+
devopsdays-cli edit speaker --city new-york
57+
devopsdays-cli edit speaker george-bluth -c "New York" --year "2017"`,
5258
Args: cobra.MaximumNArgs(1),
5359
Run: func(cmd *cobra.Command, args []string) {
5460
if len(args) > 0 {
@@ -63,10 +69,12 @@ You can provide the speaker's name as an argument to this command, but it must b
6369
var removeSpeakerCmd = &cobra.Command{
6470
Use: "speaker",
6571
Short: "Remove a speaker from an event",
66-
Long: `Remove a speaker from an event
67-
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name. For example:
68-
69-
devopsdays-cli remove speaker george-bluth`,
72+
Long: `Remove a speaker from an event.
73+
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name.
74+
`,
75+
Example: ` devopsdays-cli remove speaker george-bluth
76+
devopsdays-cli remove speaker --city new-york
77+
devopsdays-cli remove speaker george-bluth -c "New York" --year "2017"`,
7078
Args: cobra.MaximumNArgs(1),
7179
Run: func(cmd *cobra.Command, args []string) {
7280
// TODO: Work your own magic here
@@ -78,10 +86,12 @@ You can provide the speaker's name as an argument to this command, but it must b
7886
var showSpeakerCmd = &cobra.Command{
7987
Use: "speaker",
8088
Short: "Show a speaker from an event",
81-
Long: `Show a speaker from an event
82-
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name. For example:
83-
84-
devopsdays-cli show speaker george-bluth`,
89+
Long: `Show a speaker from an event.
90+
You can provide the speaker's name as an argument to this command, but it must be the "cleaned" name.
91+
`,
92+
Example: ` devopsdays-cli remove speaker george-bluth
93+
devopsdays-cli show speaker --city new-york --year 2017 --all
94+
devopsdays-cli remove speaker george-bluth -c "New York" --year "2017"`,
8595
Args: cobra.MaximumNArgs(1),
8696
Run: func(cmd *cobra.Command, args []string) {
8797
// TODO: Work your own magic here
@@ -96,15 +106,17 @@ func init() {
96106
removeCmd.AddCommand(removeSpeakerCmd)
97107
showCmd.AddCommand(showSpeakerCmd)
98108

99-
// Here you will define your flags and configuration settings.
100-
101-
// Cobra supports Persistent Flags which will work for this command
102-
// and all subcommands, e.g.:
103-
// speakerCmd.PersistentFlags().String("foo", "", "A help for foo")
104-
105-
// Cobra supports local flags which will only run when this command
106-
// is called directly, e.g.:
107-
// speakerCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
109+
addSpeakerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
110+
addSpeakerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
111+
createSpeakerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
112+
createSpeakerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
113+
editSpeakerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
114+
editSpeakerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
115+
removeSpeakerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
116+
removeSpeakerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
117+
showSpeakerCmd.Flags().StringVarP(&City, "city", "c", "", "city to use")
118+
showSpeakerCmd.Flags().StringVarP(&Year, "year", "y", "", "year to use")
119+
showSpeakerCmd.Flags().BoolVarP(&All, "all", "a", false, "show all")
108120

109121
}
110122

0 commit comments

Comments
 (0)