Skip to content

Commit 6b2fc08

Browse files
committed
Refactor out almost all of the helpers package
Signed-off-by: Matt Stratton <[email protected]>
1 parent 60c9d57 commit 6b2fc08

23 files changed

+69
-55
lines changed

cmd/editEvent.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/davecgh/go-spew/spew"
1313
"github.com/devopsdays/devopsdays-cli/helpers"
14+
"github.com/devopsdays/devopsdays-cli/helpers/paths"
1415
"github.com/devopsdays/devopsdays-cli/model"
1516
"gopkg.in/yaml.v2"
1617
)
@@ -155,7 +156,7 @@ func editEvent(event model.Event) (err error) {
155156

156157
func eventStruct(city, year string) (event model.Event) {
157158
// var event Event
158-
yamlFile, err := ioutil.ReadFile(helpers.EventDataPath(webdir, city, year))
159+
yamlFile, err := ioutil.ReadFile(paths.EventDataPath(webdir, city, year))
159160
err = yaml.Unmarshal(yamlFile, &event)
160161
if err != nil {
161162
panic(err)
@@ -203,7 +204,7 @@ func editField(event model.Event, field, value string) {
203204
// f := reflect.Indirect(r).FieldByName(field)
204205
reflect.ValueOf(&event).Elem().FieldByName(field).SetString(value)
205206
y, _ := yaml.Marshal(&event)
206-
ioutil.WriteFile((helpers.EventDataPath(webdir, event.City, event.Year)), y, 0755)
207+
ioutil.WriteFile((paths.EventDataPath(webdir, event.City, event.Year)), y, 0755)
207208
return
208209
}
209210

@@ -216,7 +217,7 @@ func updateOrganizer(event model.Event, name, field, value string) {
216217
fmt.Println(r)
217218
spew.Dump(event.TeamMembers)
218219
y, _ := yaml.Marshal(&event)
219-
ioutil.WriteFile((helpers.EventDataPath(webdir, event.City, event.Year)), y, 0755)
220+
ioutil.WriteFile((paths.EventDataPath(webdir, event.City, event.Year)), y, 0755)
220221
}
221222
}
222223
}

cmd/event.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
rice "github.com/GeertJohan/go.rice"
1414
"github.com/devopsdays/devopsdays-cli/event"
1515
"github.com/devopsdays/devopsdays-cli/helpers"
16+
"github.com/devopsdays/devopsdays-cli/helpers/paths"
1617
"github.com/spf13/cobra"
1718
)
1819

@@ -62,7 +63,7 @@ to quickly create a Cobra application.`,
6263
city := ""
6364
year := ""
6465
if city != "" {
65-
if helpers.CheckEvent(city, year) == false {
66+
if event.CheckEvent(city, year) == false {
6667
log.Fatal("That city does not exist.")
6768
}
6869
myEvent := eventStruct(city, year)
@@ -73,7 +74,7 @@ to quickly create a Cobra application.`,
7374
city, _ := reader.ReadString('\n')
7475
fmt.Println("Enter the year:")
7576
year, _ := reader.ReadString('\n')
76-
if helpers.CheckEvent(city, year) == false {
77+
if event.CheckEvent(city, year) == false {
7778
log.Fatal("That city does not exist.")
7879
}
7980
myEvent := eventStruct(city, year)
@@ -224,10 +225,10 @@ func createEventFile(city, year, twitter string) (string, error) {
224225
strings.TrimSpace(city),
225226
strings.TrimSpace(year),
226227
slug,
227-
helpers.CityClean(city),
228+
event.CityClean(city),
228229
strings.TrimSpace(twitter),
229230
}
230-
f, err := os.Create(helpers.EventDataPath(webdir, city, year))
231+
f, err := os.Create(paths.EventDataPath(webdir, city, year))
231232
if err != nil {
232233
return "", err
233234
}
@@ -236,13 +237,13 @@ func createEventFile(city, year, twitter string) (string, error) {
236237
if err != nil {
237238
fmt.Println(err)
238239
} else {
239-
fmt.Println("Created event file for", city, "for year", year, "at", helpers.EventDataPath(webdir, city, year))
240+
fmt.Println("Created event file for", city, "for year", year, "at", paths.EventDataPath(webdir, city, year))
240241
}
241242
return city, nil
242243
}
243244

244245
func createEventContentDir(city, year string) (string, error) {
245-
err := os.MkdirAll((helpers.EventContentPath(city, year)), 0755)
246+
err := os.MkdirAll((paths.EventContentPath(city, year)), 0755)
246247
if err != nil {
247248
return "", err
248249
}
@@ -281,9 +282,9 @@ func createEventContentFile(city, year, page string) (string, error) { // add pa
281282
strings.TrimSpace(city),
282283
strings.TrimSpace(year),
283284
slug,
284-
helpers.CityClean(city),
285+
event.CityClean(city),
285286
}
286-
filePath := filepath.Join((helpers.EventContentPath(city, year)), (page + ".md"))
287+
filePath := filepath.Join((paths.EventContentPath(city, year)), (page + ".md"))
287288
f, err := os.Create(filePath)
288289
if err != nil {
289290
return "Cannot create", err

helpers/check_event.go renamed to event/check_event.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
package helpers
1+
package event
22

3-
import "os"
3+
import (
4+
"os"
5+
6+
"github.com/devopsdays/devopsdays-cli/helpers/paths"
7+
)
48

59
// CheckEvent takes in two arguments, the city and the year, and returns true if the city exists.
610
func CheckEvent(city, year string) bool {
7-
if _, err := os.Stat(EventDataPath(GetWebdir(), city, year)); err == nil {
11+
if _, err := os.Stat(paths.EventDataPath(paths.GetWebdir(), city, year)); err == nil {
812
return true
913
}
1014
return false

helpers/check_event_test.go renamed to event/check_event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package helpers
1+
package event
22

33
import (
44
"testing"

helpers/city_clean.go renamed to event/city_clean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package helpers
1+
package event
22

33
import "strings"
44

helpers/city_clean_test.go renamed to event/city_clean_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package helpers
1+
package event
22

33
import (
44
"testing"

event/event.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/alecthomas/template"
1313
helpers "github.com/devopsdays/devopsdays-cli/helpers"
14+
paths "github.com/devopsdays/devopsdays-cli/helpers/paths"
15+
"github.com/devopsdays/devopsdays-cli/images"
1416
"github.com/devopsdays/devopsdays-cli/model"
1517
"github.com/fatih/color"
1618
survey "gopkg.in/AlecAivazis/survey.v1"
@@ -155,10 +157,10 @@ func CreateEvent(city, year string) (err error) {
155157
return
156158
}
157159

158-
orgEmail := []string{"organizers-", strings.Replace(strings.TrimSpace(strings.ToLower(helpers.CityClean(city))), " ", "-", 10), "-", strings.TrimSpace(year), "@devopsdays.org"}
159-
proposalEmail := []string{"proposals-", helpers.CityClean(city), "-", strings.TrimSpace(year), "@devopsdays.org"}
160+
orgEmail := []string{"organizers-", strings.Replace(strings.TrimSpace(strings.ToLower(CityClean(city))), " ", "-", 10), "-", strings.TrimSpace(year), "@devopsdays.org"}
161+
proposalEmail := []string{"proposals-", CityClean(city), "-", strings.TrimSpace(year), "@devopsdays.org"}
160162
myEvent := model.Event{
161-
Name: strings.Join([]string{strings.TrimSpace(year), "-", helpers.CityClean(city)}, ""),
163+
Name: strings.Join([]string{strings.TrimSpace(year), "-", CityClean(city)}, ""),
162164
Year: year,
163165
City: city,
164166
EventTwitter: answers.Twitter,
@@ -173,14 +175,14 @@ func CreateEvent(city, year string) (err error) {
173175
ProposalEmail: strings.Join(proposalEmail, ""),
174176
}
175177

176-
NewEvent(myEvent, helpers.CityClean(city), year)
178+
NewEvent(myEvent, CityClean(city), year)
177179

178180
if answers.LogoPath != "" {
179-
err = EventLogo(answers.LogoPath, helpers.CityClean(city), year)
181+
err = EventLogo(answers.LogoPath, CityClean(city), year)
180182
}
181183

182184
if answers.SquareLogoPath != "" {
183-
err = EventLogoSquare(answers.SquareLogoPath, helpers.CityClean(city), year)
185+
err = EventLogoSquare(answers.SquareLogoPath, CityClean(city), year)
184186
}
185187

186188
return
@@ -195,23 +197,23 @@ func NewEvent(event model.Event, city string, year string) (err error) {
195197
log.Fatal("Parse: ", err)
196198
return
197199
}
198-
f, err := os.Create(helpers.EventDataPath(helpers.GetWebdir(), city, year))
200+
f, err := os.Create(paths.EventDataPath(paths.GetWebdir(), city, year))
199201
defer f.Close()
200202
t.Execute(f, event)
201203

202204
if err != nil {
203205
fmt.Println(err)
204206
} else {
205207
fmt.Fprintf(color.Output, "\n\n\nCreated event file for %s\n", color.GreenString(event.City))
206-
fmt.Fprintf(color.Output, "at %s\n\n\n", color.BlueString(helpers.EventDataPath(helpers.GetWebdir(), city, year)))
208+
fmt.Fprintf(color.Output, "at %s\n\n\n", color.BlueString(paths.EventDataPath(paths.GetWebdir(), city, year)))
207209
}
208210
return
209211
}
210212

211213
// EventLogo takes in a path to an event's main logo and copies/renames it to the proper destination
212214
func EventLogo(srcPath, city, year string) (err error) {
213215

214-
eventStaticPath, err := helpers.EventStaticPath(city, year)
216+
eventStaticPath, err := paths.EventStaticPath(city, year)
215217
if err != nil {
216218
log.Fatal(err)
217219
}
@@ -227,12 +229,12 @@ func EventLogo(srcPath, city, year string) (err error) {
227229

228230
// EventLogoSquare takes in a path the event's square logo, and crops/resizes it and copies it to the proper destination
229231
func EventLogoSquare(srcPath, city, year string) (err error) {
230-
eventStaticPath, err := helpers.EventStaticPath(city, year)
232+
eventStaticPath, err := paths.EventStaticPath(city, year)
231233
if err != nil {
232234
log.Fatal(err)
233235
}
234236
destPath := filepath.Join(eventStaticPath, "logo-square.png")
235-
helpers.ResizeImage(srcPath, destPath, "png", 600, 600)
237+
images.ResizeImage(srcPath, destPath, "png", 600, 600)
236238

237239
// @TODO update helpers.ResizeImage to return error code and do something with it here
238240

helpers/copy_file.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package helpers
22

33
import (
4-
"fmt"
54
"io"
65
"os"
76
)
@@ -27,6 +26,6 @@ func CopyFile(srcPath, destPath string) (err error) {
2726
return err
2827
}
2928

30-
fmt.Printf("Copied %v bytes\n", n)
29+
// fmt.Printf("Copied %v bytes\n", n)
3130
return nil
3231
}

helpers/event_content_path.go renamed to helpers/paths/event_content_path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package helpers
1+
package paths
22

33
import (
44
"log"

helpers/event_content_path_test.go renamed to helpers/paths/event_content_path_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package helpers
1+
package paths
22

33
import (
44
"testing"

0 commit comments

Comments
 (0)