@@ -117,7 +117,7 @@ func main() {
117
117
// Every non-dash argument is considered a part of the title. If there are no arguments, we have no title
118
118
// Can't have a page without a title
119
119
if len (os .Args [1 :]) < 1 {
120
- Fail (errors .New (errNoTitle ))
120
+ Defeat (errors .New (errNoTitle ))
121
121
}
122
122
123
123
title := strings .Title (strings .Join (os .Args [1 :], " " ))
@@ -162,7 +162,7 @@ func getConfigDir() string {
162
162
163
163
dir , err := os .UserHomeDir ()
164
164
if err != nil {
165
- Fail (errors .New (errConfigExpandPath ))
165
+ Defeat (errors .New (errConfigExpandPath ))
166
166
}
167
167
168
168
return filepath .Join (dir , cDir [1 :])
@@ -182,7 +182,7 @@ func makeConfigDir() {
182
182
if _ , err := os .Stat (cDir ); os .IsNotExist (err ) {
183
183
err := os .MkdirAll (cDir , os .ModePerm )
184
184
if err != nil {
185
- Fail (errors .New (errConfigDirCreate ))
185
+ Defeat (errors .New (errConfigDirCreate ))
186
186
}
187
187
188
188
Progress (fmt .Sprintf ("created %s" , cDir ))
@@ -202,27 +202,27 @@ func makeConfigFile() {
202
202
_ , err = os .Create (cPath )
203
203
if err != nil {
204
204
// That was not fine
205
- Fail (errors .New (errConfigFileCreate ))
205
+ Defeat (errors .New (errConfigFileCreate ))
206
206
}
207
207
208
208
} else {
209
209
// But wait, it's some kind of other error. What kind?
210
210
// I dunno, but it's probably bad so die
211
- Fail (err )
211
+ Defeat (err )
212
212
}
213
213
}
214
214
215
215
// Let's double-check that the file's there now
216
216
fileInfo , err := os .Stat (cPath )
217
217
if err != nil {
218
- Fail (errors .New (errConfigFileAssert ))
218
+ Defeat (errors .New (errConfigFileAssert ))
219
219
}
220
220
221
221
// Write the default config, but only if the file is empty.
222
222
// Don't want to stop on any non-default values the user has written in there
223
223
if fileInfo .Size () == 0 {
224
224
if ioutil .WriteFile (cPath , []byte (defaultConfig ), 0600 ) != nil {
225
- Fail (errors .New (errConfigFileWrite ))
225
+ Defeat (errors .New (errConfigFileWrite ))
226
226
}
227
227
228
228
Progress (fmt .Sprintf ("created %s" , cPath ))
@@ -236,7 +236,7 @@ func readConfigFile() {
236
236
237
237
cfg , err := config .ParseYamlFile (cPath )
238
238
if err != nil {
239
- Fail (err )
239
+ Defeat (err )
240
240
}
241
241
242
242
globalConfig = cfg
@@ -253,7 +253,7 @@ func buildTargetDirectory() {
253
253
if _ , err := os .Stat (tDir ); os .IsNotExist (err ) {
254
254
err := os .MkdirAll (tDir , os .ModePerm )
255
255
if err != nil {
256
- Fail (errors .New (errTargetDirCreate ))
256
+ Defeat (errors .New (errTargetDirCreate ))
257
257
}
258
258
}
259
259
}
@@ -268,7 +268,7 @@ func getTargetDir(withDocsDir bool) string {
268
268
269
269
tDir , err := globalConfig .String ("targetDirectory" )
270
270
if err != nil {
271
- Fail (err )
271
+ Defeat (err )
272
272
}
273
273
274
274
if tDir [0 ] != '~' {
@@ -277,7 +277,7 @@ func getTargetDir(withDocsDir bool) string {
277
277
278
278
dir , err := os .UserHomeDir ()
279
279
if err != nil {
280
- Fail (errors .New (errConfigExpandPath ))
280
+ Defeat (errors .New (errConfigExpandPath ))
281
281
}
282
282
283
283
return filepath .Join (dir , tDir [1 :], docsBit )
@@ -323,7 +323,7 @@ func buildIndexPage(pages []*Page, tagMap *TagMap) {
323
323
324
324
err := ioutil .WriteFile (filePath , []byte (content ), 0644 )
325
325
if err != nil {
326
- Fail (err )
326
+ Defeat (err )
327
327
}
328
328
329
329
Progress (filePath )
@@ -362,7 +362,7 @@ func buildTagPages(pages []*Page) *TagMap {
362
362
363
363
err := ioutil .WriteFile (filePath , []byte (content ), 0644 )
364
364
if err != nil {
365
- Fail (err )
365
+ Defeat (err )
366
366
}
367
367
368
368
Progress (filePath )
@@ -400,7 +400,7 @@ func createNewPage(title string) string {
400
400
401
401
err := ioutil .WriteFile (filePath , []byte (content ), 0644 )
402
402
if err != nil {
403
- Fail (err )
403
+ Defeat (err )
404
404
}
405
405
406
406
// 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 {
413
413
cmd := exec .Command (editor , filePath )
414
414
err = cmd .Run ()
415
415
if err != nil {
416
- Fail (err )
416
+ Defeat (err )
417
417
}
418
418
419
419
return filePath
@@ -472,12 +472,12 @@ func push() {
472
472
473
473
r , err := git .PlainOpen (tDir )
474
474
if err != nil {
475
- Fail (err )
475
+ Defeat (err )
476
476
}
477
477
478
478
err = r .Push (& git.PushOptions {})
479
479
if err != nil {
480
- Fail (err )
480
+ Defeat (err )
481
481
}
482
482
}
483
483
@@ -488,12 +488,12 @@ func readPage(filePath string) *Page {
488
488
489
489
data , err := ioutil .ReadFile (filePath )
490
490
if err != nil {
491
- Fail (err )
491
+ Defeat (err )
492
492
}
493
493
494
494
err = frontmatter .Unmarshal (data , page )
495
495
if err != nil {
496
- Fail (err )
496
+ Defeat (err )
497
497
}
498
498
499
499
page .FilePath = filePath
@@ -509,24 +509,24 @@ func save(commitMsg string) {
509
509
510
510
r , err := git .PlainOpen (tDir )
511
511
if err != nil {
512
- Fail (err )
512
+ Defeat (err )
513
513
}
514
514
515
515
w , err := r .Worktree ()
516
516
if err != nil {
517
- Fail (err )
517
+ Defeat (err )
518
518
}
519
519
520
520
_ , err = w .Add ("." )
521
521
if err != nil {
522
- Fail (err )
522
+ Defeat (err )
523
523
}
524
524
525
525
defaultCommitMsg , err1 := globalConfig .String ("commitMessage" )
526
526
defaultCommitEmail , err2 := globalConfig .String ("committerEmail" )
527
527
defaultCommitName , err3 := globalConfig .String ("committerName" )
528
528
if err1 != nil || err2 != nil || err3 != nil {
529
- Fail (errors .New (errConfigValueRead ))
529
+ Defeat (errors .New (errConfigValueRead ))
530
530
}
531
531
532
532
if commitMsg == "" {
@@ -544,12 +544,12 @@ func save(commitMsg string) {
544
544
},
545
545
})
546
546
if err != nil {
547
- Fail (err )
547
+ Defeat (err )
548
548
}
549
549
550
550
obj , err := r .CommitObject (commit )
551
551
if err != nil {
552
- Fail (err )
552
+ Defeat (err )
553
553
}
554
554
555
555
Info (fmt .Sprintf ("committed with '%s' (%.7s)" , obj .Message , obj .Hash .String ()))
@@ -566,8 +566,8 @@ func Colour(colorString string) func(...interface{}) string {
566
566
return sprint
567
567
}
568
568
569
- // Fail writes out an error message
570
- func Fail (err error ) {
569
+ // Defeat writes out an error message
570
+ func Defeat (err error ) {
571
571
ll .Fatal (fmt .Sprintf ("%s %s" , Red ("✘" ), err .Error ()))
572
572
}
573
573
0 commit comments