Skip to content

Commit b39d8b3

Browse files
committed
Add function to show talks
Fixes #59 Signed-off-by: Matt Stratton <[email protected]>
1 parent 64d7599 commit b39d8b3

File tree

9 files changed

+236
-28
lines changed

9 files changed

+236
-28
lines changed

cmd/prompt.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/devopsdays/devopsdays-cli/event"
66
"github.com/devopsdays/devopsdays-cli/speaker"
77
"github.com/devopsdays/devopsdays-cli/sponsor"
8+
"github.com/devopsdays/devopsdays-cli/talk"
89
)
910

1011
func mainPrompt() (err error) {
@@ -18,6 +19,7 @@ func mainPrompt() (err error) {
1819
"Create a new speaker",
1920
"Create a new sponsor",
2021
"Show a speaker",
22+
"Show a talk",
2123
"Quit the application",
2224
},
2325
}
@@ -34,6 +36,8 @@ func mainPrompt() (err error) {
3436
sponsor.CreateSponsor("")
3537
case "Show a speaker":
3638
showSpeakerPrompt("", "")
39+
case "Show a talk":
40+
showTalkPrompt("", "")
3741
}
3842
}
3943

@@ -112,3 +116,35 @@ func showSpeakerPrompt(city, year string) (err error) {
112116
}
113117
return
114118
}
119+
120+
func showTalkPrompt(city, year string) (err error) {
121+
var exitCode = true
122+
for exitCode {
123+
if city == "" {
124+
prompt := &survey.Input{
125+
Message: "Enter the city name:",
126+
}
127+
err := survey.AskOne(prompt, &city, survey.Required)
128+
// handle interrupts
129+
if err != nil {
130+
exitCode = false
131+
break
132+
}
133+
}
134+
135+
if year == "" {
136+
prompt := &survey.Input{
137+
Message: "Enter the year:",
138+
}
139+
err := survey.AskOne(prompt, &year, survey.Required)
140+
// handle interrupts
141+
if err != nil {
142+
exitCode = false
143+
break
144+
}
145+
}
146+
talk.ShowTalks(city, year)
147+
148+
}
149+
return
150+
}

cmd/talk.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55

66
"github.com/spf13/cobra"
7+
8+
"github.com/devopsdays/devopsdays-cli/talk"
79
)
810

911
// addTalkCmd represents the "talk add" command
@@ -82,7 +84,7 @@ This application is a tool to generate the needed files
8284
to quickly create a Cobra application.`,
8385
Run: func(cmd *cobra.Command, args []string) {
8486
// TODO: Work your own magic here
85-
showTalk()
87+
showTalkPrompt(City, Year)
8688
},
8789
}
8890

@@ -126,5 +128,9 @@ func removeTalk() {
126128
}
127129

128130
func showTalk() {
131+
err := talk.ShowTalks("Ponyville", "2017")
132+
if err != nil {
133+
fmt.Println("error")
134+
}
129135
fmt.Println("You would have shown a talk if this happened")
130136
}

model/talk.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ package model
44
type Talk struct {
55
Name string
66
Title string
7-
Description string `toml:"description,omitempty"`
8-
Speakers []Speakers
9-
YouTube string `toml:"youtube,omitempty"`
10-
Vimeo string `toml:"vimeo,omitempty"`
11-
Speakerdeck string `toml:"speakerdeck,omitempty"`
12-
Slideshare string `toml:"slideshare,omitempty"`
13-
Googleslides string `toml:"googleslides,omitempty"`
14-
PDF string `toml:"pdf,omitempty"`
15-
Slides string `toml:"slides,omitempty"`
16-
}
17-
18-
// Speakers is the array of speakers on a talk
19-
type Speakers struct {
20-
Name string
7+
Description string `toml:"description,omitempty"`
8+
Speakers []string `toml:"speakers, omitempty"`
9+
YouTube string `toml:"youtube,omitempty"`
10+
Vimeo string `toml:"vimeo,omitempty"`
11+
Speakerdeck string `toml:"speakerdeck,omitempty"`
12+
Slideshare string `toml:"slideshare,omitempty"`
13+
Googleslides string `toml:"googleslides,omitempty"`
14+
PDF string `toml:"pdf,omitempty"`
15+
Slides string `toml:"slides,omitempty"`
16+
Abstract string
2117
}

speaker/speaker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ func CreateSpeaker(speakerName, city, year string) (err error) {
163163

164164
t := ""
165165
if name == true {
166+
myList, _ := talk.GetTalks(city, year)
166167
prompt := &survey.Select{
167168
Message: "Choose a talk:",
168-
Options: talk.GetTalks(city, year),
169+
Options: myList,
169170
}
170171
survey.AskOne(prompt, &t, nil)
171172
color.Yellow("NOT IMPLEMENTED")

speaker/speaker_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func GetSpeakerInfo(file, city, year string) (speaker model.Speaker, err error)
5858
return
5959
}
6060

61-
// TOMLHandler decodes ymal string into a go map[string]interface{}
61+
// TOMLHandler decodes TOML string into a go map[string]interface{}
6262
func TOMLHandler(front string) (map[string]interface{}, error) {
6363

6464
var stuff model.Speaker

talk/get_talk_info.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package talk
2+
3+
import (
4+
"io/ioutil"
5+
"log"
6+
"path/filepath"
7+
"strings"
8+
9+
"github.com/BurntSushi/toml"
10+
"github.com/devopsdays/devopsdays-cli/helpers/paths"
11+
"github.com/devopsdays/devopsdays-cli/model"
12+
"github.com/gernest/front"
13+
"github.com/pkg/errors"
14+
)
15+
16+
// GetTalkInfo loads in a talk file and returns a struct with the information, decoded
17+
// from the TOML in the frontmatter
18+
func GetTalkInfo(file, city, year string) (talk *model.Talk, err error) {
19+
20+
filePath := filepath.Join(paths.EventContentPath(city, year), "program", file)
21+
dat, err := ioutil.ReadFile(filePath)
22+
if err != nil {
23+
return talk, errors.Wrap(err, "load files failed")
24+
}
25+
m := front.NewMatter()
26+
m.Handle("+++", TOMLHandler)
27+
28+
f, body, err := m.Parse(strings.NewReader(string(dat)))
29+
if err != nil {
30+
return talk, errors.Wrap(err, "get list of talks failed")
31+
}
32+
33+
talk = &model.Talk{
34+
Name: file,
35+
Title: f["Title"].(string),
36+
Description: f["Description"].(string),
37+
Speakers: f["Speakers"].([]string),
38+
YouTube: f["YouTube"].(string),
39+
Vimeo: f["Vimeo"].(string),
40+
Speakerdeck: f["Speakerdeck"].(string),
41+
Slideshare: f["Slideshare"].(string),
42+
Googleslides: f["Googleslides"].(string),
43+
PDF: f["PDF"].(string),
44+
Slides: f["Slides"].(string),
45+
Abstract: body,
46+
}
47+
48+
return
49+
}
50+
51+
// TOMLHandler decodes TOML string into a go map[string]interface{}
52+
func TOMLHandler(front string) (map[string]interface{}, error) {
53+
54+
var thisTalk model.Talk
55+
if _, err := toml.Decode(front, &thisTalk); err != nil {
56+
57+
log.Fatal(err)
58+
}
59+
x := map[string]interface{}{
60+
"Name": thisTalk.Name,
61+
"Title": thisTalk.Title,
62+
"Description": thisTalk.Description,
63+
"Speakers": thisTalk.Speakers,
64+
"YouTube": thisTalk.YouTube,
65+
"Vimeo": thisTalk.Vimeo,
66+
"Speakerdeck": thisTalk.Speakerdeck,
67+
"Slideshare": thisTalk.Slideshare,
68+
"Googleslides": thisTalk.Googleslides,
69+
"PDF": thisTalk.PDF,
70+
"Slides": thisTalk.Slides,
71+
"Abstract": thisTalk.Abstract,
72+
}
73+
74+
return x, nil
75+
}

talk/get_talks.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
package talk
22

33
import (
4-
"fmt"
54
"io/ioutil"
65
"path/filepath"
76

87
"github.com/devopsdays/devopsdays-cli/helpers/paths"
8+
"github.com/pkg/errors"
99
)
1010

1111
// GetTalks takes in the city and year and returns a list of the talks
12-
func GetTalks(city, year string) []string {
13-
12+
func GetTalks(city, year string) ([]string, error) {
1413
talksDir := filepath.Join(paths.EventContentPath(city, year), "program")
1514

16-
fmt.Println(talksDir)
15+
files, err := ioutil.ReadDir(talksDir)
16+
17+
if err != nil {
18+
return nil, errors.Wrap(err, "read directory failed")
19+
}
1720

18-
// @TODO implement error checking in helpers.GetTalks
19-
files, _ := ioutil.ReadDir(talksDir)
20-
// if err != nil {
21-
// return nil, err
22-
// }
21+
var s []string
2322

24-
s := make([]string, len(files))
2523
for _, f := range files {
2624
s = append(s, f.Name())
2725
}
28-
return s
26+
return s, nil
2927
}

talk/talk.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,81 @@
11
// Package talk includes the functionality to add, create, edit, remove, and show talks.
22
// It also includes supporting and helper functions that are talk-releated.
33
package talk
4+
5+
import (
6+
"fmt"
7+
"io/ioutil"
8+
"path/filepath"
9+
"reflect"
10+
"strings"
11+
12+
"github.com/AlecAivazis/survey"
13+
"github.com/devopsdays/devopsdays-cli/helpers/paths"
14+
"github.com/devopsdays/devopsdays-cli/model"
15+
"github.com/fatih/color"
16+
"github.com/pkg/errors"
17+
)
18+
19+
func ShowTalks(city, year string) (err error) {
20+
var selection string
21+
22+
myTalks, err := loadTalks(city, year)
23+
24+
var options2 []string
25+
26+
for _, d := range myTalks {
27+
options2 = append(options2, d.Title)
28+
}
29+
options2 = append(options2, "Return to Main Menu")
30+
for selection != "Return to Main Menu" {
31+
prompt := &survey.Select{
32+
Message: "Select a talk:",
33+
Options: options2,
34+
}
35+
survey.AskOne(prompt, &selection, nil)
36+
if selection == "Return to Main Menu" {
37+
return
38+
}
39+
var myTalk *model.Talk
40+
for _, d := range myTalks {
41+
if d.Title == selection {
42+
myTalk = d
43+
break
44+
}
45+
}
46+
s := reflect.ValueOf(myTalk).Elem()
47+
typeOfT := s.Type()
48+
fmt.Println()
49+
color.Cyan("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+")
50+
for i := 0; i < s.NumField(); i++ {
51+
f := s.Field(i)
52+
if (typeOfT.Field(i).Name != "Name") && (f.Interface() != "") {
53+
if f.Type() != reflect.TypeOf("") {
54+
continue
55+
}
56+
str := f.Interface().(string)
57+
str = strings.TrimSpace(str)
58+
fmt.Fprintf(color.Output, "%s: %s\n", color.CyanString(typeOfT.Field(i).Name), color.GreenString(str))
59+
}
60+
}
61+
color.Cyan("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+")
62+
fmt.Println()
63+
64+
}
65+
return
66+
}
67+
68+
func loadTalks(city, year string) (talks []*model.Talk, err error) {
69+
talksDir := filepath.Join(paths.EventContentPath(city, year), "program")
70+
files, err := ioutil.ReadDir(talksDir)
71+
if err != nil {
72+
return nil, errors.Wrap(err, "read directory failed")
73+
}
74+
75+
for _, f := range files {
76+
thisTalk, _ := GetTalkInfo(f.Name(), city, year)
77+
talks = append(talks, thisTalk)
78+
}
79+
80+
return
81+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
+++
2+
Description = ""
3+
City = "Ponyville"
4+
Year = "2017"
5+
date = "2016-07-15T22:06:24-06:00"
6+
Talk_date = ""
7+
Talk_start_time = ""
8+
Talk_end_time = ""
9+
Title = "Continuous Delivery of Ponies"
10+
Type = "talk"
11+
Speakers = ["rainbow-dash","fluttershy"]
12+
Youtube = "emGKB8TABvI"
13+
Vimeo = ""
14+
Slideshare = "https://www.slideshare.net/mattstratton/the-five-love-languages-of-devops-54549536"
15+
Slides = "https://speakerdeck.com/mattstratton/shifting-left-securely"
16+
+++
17+
18+
Ideate actionable insight long shadow driven SpaceTeam ideate user story intuitive bootstrapping. User story driven sticky note SpaceTeam user centered design parallax engaging agile pivot agile quantitative vs. qualitative agile quantitative vs. qualitative. Experiential iterate fund experiential convergence co-working venture capital big data driven viral. Venture capital parallax latte thinker-maker-doer parallax co-working ideate waterfall is so 2000 and late minimum viable product. Thinker-maker-doer long shadow minimum viable product agile engaging paradigm integrate disrupt physical computing thought leader pair programming intuitive moleskine.

0 commit comments

Comments
 (0)