Skip to content

Commit 53218a3

Browse files
committed
Add interactive prompts
This commit adds a looping prompt to the main root command, and also has create speaker prompt for additional speakers. Fixes #103 Signed-off-by: Matt Stratton <[email protected]>
1 parent 7dc1089 commit 53218a3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

cmd/prompt.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,38 @@ package cmd
22

33
import (
44
"github.com/AlecAivazis/survey"
5+
"github.com/devopsdays/devopsdays-cli/event"
56
"github.com/devopsdays/devopsdays-cli/speaker"
7+
"github.com/devopsdays/devopsdays-cli/sponsor"
68
)
79

10+
func mainPrompt() (err error) {
11+
var selection string
12+
13+
for selection != "Quit the application" {
14+
prompt := &survey.Select{
15+
Message: "Select an action:",
16+
Options: []string{
17+
"Create a new event",
18+
"Create a new speaker",
19+
"Create a new sponsor",
20+
"Quit the application",
21+
},
22+
}
23+
survey.AskOne(prompt, &selection, nil)
24+
switch selection {
25+
case "Create a new event":
26+
event.CreateEvent("", "")
27+
case "Create a new speaker":
28+
createSpeakerPrompt("", "")
29+
case "Create a new sponsor":
30+
sponsor.CreateSponsor("")
31+
}
32+
}
33+
34+
return
35+
}
36+
837
func createSpeakerPrompt(city, year string) (err error) {
938
var exitCode = true
1039

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Command-line utilities for the devopsdays.org website
5050
built with love by mattstratton in Go.
5151
5252
Complete documentation is available at https://github.com/devopsdays/devopsdays-cli`,
53+
Run: func(cmd *cobra.Command, args []string) {
54+
mainPrompt()
55+
},
5356
}
5457

5558
// Execute adds all child commands to the root command sets flags appropriately.

0 commit comments

Comments
 (0)