Skip to content

Commit 7dc1089

Browse files
committed
Add loop for create speaker
The `create speaker` command now prompts the user to have the option to add more speakers to the same city. Signed-off-by: Matt Stratton <[email protected]>
1 parent 230d31c commit 7dc1089

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

cmd/prompt.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cmd
2+
3+
import (
4+
"github.com/AlecAivazis/survey"
5+
"github.com/devopsdays/devopsdays-cli/speaker"
6+
)
7+
8+
func createSpeakerPrompt(city, year string) (err error) {
9+
var exitCode = true
10+
11+
for exitCode {
12+
if city == "" {
13+
prompt := &survey.Input{
14+
Message: "Enter the city name:",
15+
}
16+
survey.AskOne(prompt, &city, survey.Required)
17+
}
18+
19+
if year == "" {
20+
prompt := &survey.Input{
21+
Message: "Enter the year:",
22+
}
23+
survey.AskOne(prompt, &year, survey.Required)
24+
}
25+
speaker.CreateSpeaker("", city, year)
26+
prompt := &survey.Confirm{
27+
Message: "Do you want to add another speaker?",
28+
}
29+
survey.AskOne(prompt, &exitCode, nil)
30+
}
31+
return
32+
}

cmd/speaker.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"fmt"
55

6-
"github.com/devopsdays/devopsdays-cli/speaker"
76
"github.com/spf13/cobra"
87
)
98

@@ -36,7 +35,7 @@ var createSpeakerCmd = &cobra.Command{
3635

3736
Args: cobra.MaximumNArgs(1),
3837
Run: func(cmd *cobra.Command, args []string) {
39-
speaker.CreateSpeaker("", City, Year)
38+
createSpeakerPrompt(City, Year)
4039
},
4140
}
4241

speaker/speaker.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,6 @@ func CreateSpeaker(speakerName, city, year string) (err error) {
149149
Talk string
150150
}{}
151151

152-
if city == "" {
153-
prompt := &survey.Input{
154-
Message: "Enter the city name:",
155-
}
156-
survey.AskOne(prompt, &city, survey.Required)
157-
}
158-
159-
if year == "" {
160-
prompt := &survey.Input{
161-
Message: "Enter the year:",
162-
}
163-
survey.AskOne(prompt, &year, survey.Required)
164-
}
165-
166152
surveyErr := survey.Ask(qsCreateSpeaker, &answers)
167153
if surveyErr != nil {
168154
fmt.Println(surveyErr.Error())

0 commit comments

Comments
 (0)