Skip to content

Commit e67504c

Browse files
Fail to Defeat. Closes #25
Signed-off-by: Chris Cummer <[email protected]>
1 parent 6a91aaa commit e67504c

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

til.go

+27-27
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func main() {
117117
// Every non-dash argument is considered a part of the title. If there are no arguments, we have no title
118118
// Can't have a page without a title
119119
if len(os.Args[1:]) < 1 {
120-
Fail(errors.New(errNoTitle))
120+
Defeat(errors.New(errNoTitle))
121121
}
122122

123123
title := strings.Title(strings.Join(os.Args[1:], " "))
@@ -162,7 +162,7 @@ func getConfigDir() string {
162162

163163
dir, err := os.UserHomeDir()
164164
if err != nil {
165-
Fail(errors.New(errConfigExpandPath))
165+
Defeat(errors.New(errConfigExpandPath))
166166
}
167167

168168
return filepath.Join(dir, cDir[1:])
@@ -182,7 +182,7 @@ func makeConfigDir() {
182182
if _, err := os.Stat(cDir); os.IsNotExist(err) {
183183
err := os.MkdirAll(cDir, os.ModePerm)
184184
if err != nil {
185-
Fail(errors.New(errConfigDirCreate))
185+
Defeat(errors.New(errConfigDirCreate))
186186
}
187187

188188
Progress(fmt.Sprintf("created %s", cDir))
@@ -202,27 +202,27 @@ func makeConfigFile() {
202202
_, err = os.Create(cPath)
203203
if err != nil {
204204
// That was not fine
205-
Fail(errors.New(errConfigFileCreate))
205+
Defeat(errors.New(errConfigFileCreate))
206206
}
207207

208208
} else {
209209
// But wait, it's some kind of other error. What kind?
210210
// I dunno, but it's probably bad so die
211-
Fail(err)
211+
Defeat(err)
212212
}
213213
}
214214

215215
// Let's double-check that the file's there now
216216
fileInfo, err := os.Stat(cPath)
217217
if err != nil {
218-
Fail(errors.New(errConfigFileAssert))
218+
Defeat(errors.New(errConfigFileAssert))
219219
}
220220

221221
// Write the default config, but only if the file is empty.
222222
// Don't want to stop on any non-default values the user has written in there
223223
if fileInfo.Size() == 0 {
224224
if ioutil.WriteFile(cPath, []byte(defaultConfig), 0600) != nil {
225-
Fail(errors.New(errConfigFileWrite))
225+
Defeat(errors.New(errConfigFileWrite))
226226
}
227227

228228
Progress(fmt.Sprintf("created %s", cPath))
@@ -236,7 +236,7 @@ func readConfigFile() {
236236

237237
cfg, err := config.ParseYamlFile(cPath)
238238
if err != nil {
239-
Fail(err)
239+
Defeat(err)
240240
}
241241

242242
globalConfig = cfg
@@ -253,7 +253,7 @@ func buildTargetDirectory() {
253253
if _, err := os.Stat(tDir); os.IsNotExist(err) {
254254
err := os.MkdirAll(tDir, os.ModePerm)
255255
if err != nil {
256-
Fail(errors.New(errTargetDirCreate))
256+
Defeat(errors.New(errTargetDirCreate))
257257
}
258258
}
259259
}
@@ -268,7 +268,7 @@ func getTargetDir(withDocsDir bool) string {
268268

269269
tDir, err := globalConfig.String("targetDirectory")
270270
if err != nil {
271-
Fail(err)
271+
Defeat(err)
272272
}
273273

274274
if tDir[0] != '~' {
@@ -277,7 +277,7 @@ func getTargetDir(withDocsDir bool) string {
277277

278278
dir, err := os.UserHomeDir()
279279
if err != nil {
280-
Fail(errors.New(errConfigExpandPath))
280+
Defeat(errors.New(errConfigExpandPath))
281281
}
282282

283283
return filepath.Join(dir, tDir[1:], docsBit)
@@ -323,7 +323,7 @@ func buildIndexPage(pages []*Page, tagMap *TagMap) {
323323

324324
err := ioutil.WriteFile(filePath, []byte(content), 0644)
325325
if err != nil {
326-
Fail(err)
326+
Defeat(err)
327327
}
328328

329329
Progress(filePath)
@@ -362,7 +362,7 @@ func buildTagPages(pages []*Page) *TagMap {
362362

363363
err := ioutil.WriteFile(filePath, []byte(content), 0644)
364364
if err != nil {
365-
Fail(err)
365+
Defeat(err)
366366
}
367367

368368
Progress(filePath)
@@ -400,7 +400,7 @@ func createNewPage(title string) string {
400400

401401
err := ioutil.WriteFile(filePath, []byte(content), 0644)
402402
if err != nil {
403-
Fail(err)
403+
Defeat(err)
404404
}
405405

406406
// Tell the OS to open the newly-created page in the editor (as specified in the config)
@@ -413,7 +413,7 @@ func createNewPage(title string) string {
413413
cmd := exec.Command(editor, filePath)
414414
err = cmd.Run()
415415
if err != nil {
416-
Fail(err)
416+
Defeat(err)
417417
}
418418

419419
return filePath
@@ -472,12 +472,12 @@ func push() {
472472

473473
r, err := git.PlainOpen(tDir)
474474
if err != nil {
475-
Fail(err)
475+
Defeat(err)
476476
}
477477

478478
err = r.Push(&git.PushOptions{})
479479
if err != nil {
480-
Fail(err)
480+
Defeat(err)
481481
}
482482
}
483483

@@ -488,12 +488,12 @@ func readPage(filePath string) *Page {
488488

489489
data, err := ioutil.ReadFile(filePath)
490490
if err != nil {
491-
Fail(err)
491+
Defeat(err)
492492
}
493493

494494
err = frontmatter.Unmarshal(data, page)
495495
if err != nil {
496-
Fail(err)
496+
Defeat(err)
497497
}
498498

499499
page.FilePath = filePath
@@ -509,24 +509,24 @@ func save(commitMsg string) {
509509

510510
r, err := git.PlainOpen(tDir)
511511
if err != nil {
512-
Fail(err)
512+
Defeat(err)
513513
}
514514

515515
w, err := r.Worktree()
516516
if err != nil {
517-
Fail(err)
517+
Defeat(err)
518518
}
519519

520520
_, err = w.Add(".")
521521
if err != nil {
522-
Fail(err)
522+
Defeat(err)
523523
}
524524

525525
defaultCommitMsg, err1 := globalConfig.String("commitMessage")
526526
defaultCommitEmail, err2 := globalConfig.String("committerEmail")
527527
defaultCommitName, err3 := globalConfig.String("committerName")
528528
if err1 != nil || err2 != nil || err3 != nil {
529-
Fail(errors.New(errConfigValueRead))
529+
Defeat(errors.New(errConfigValueRead))
530530
}
531531

532532
if commitMsg == "" {
@@ -544,12 +544,12 @@ func save(commitMsg string) {
544544
},
545545
})
546546
if err != nil {
547-
Fail(err)
547+
Defeat(err)
548548
}
549549

550550
obj, err := r.CommitObject(commit)
551551
if err != nil {
552-
Fail(err)
552+
Defeat(err)
553553
}
554554

555555
Info(fmt.Sprintf("committed with '%s' (%.7s)", obj.Message, obj.Hash.String()))
@@ -566,8 +566,8 @@ func Colour(colorString string) func(...interface{}) string {
566566
return sprint
567567
}
568568

569-
// Fail writes out an error message
570-
func Fail(err error) {
569+
// Defeat writes out an error message
570+
func Defeat(err error) {
571571
ll.Fatal(fmt.Sprintf("%s %s", Red("✘"), err.Error()))
572572
}
573573

0 commit comments

Comments
 (0)