Public » Fortune Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

master find fortunes relative to executable

Changeset 8bf8a9b3ecff

Parent 08f06e94592b

by Profile picture of Benjamin PollackBenjamin Pollack

Changes to one file · Browse files at 8bf8a9b3ecff Showing diff from parent 08f06e94592b Diff from another changeset...

Change 1 of 2 Show Entire File main.go Stacked
 
7
8
9
 
 
10
11
12
 
45
46
47
 
 
 
 
 
 
 
 
 
 
 
 
48
49
50
51
 
52
53
54
55
56
57
 
58
59
60
 
7
8
9
10
11
12
13
14
 
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
65
66
67
68
69
70
 
71
72
73
74
@@ -7,6 +7,8 @@
  "io"   "math/rand"   "os" + "os/exec" + "path/filepath"   "time"  )   @@ -45,16 +47,28 @@
  return  }   +func executablePath() string { + path, err := exec.LookPath(os.Args[0]) + if err != nil { + panic(err) + } + path, err = filepath.Abs(path) + if err != nil { + panic(err) + } + return filepath.Dir(path) +} +  func main() {   offensive := flag.Bool("o", false, "be offensive")   flag.Parse() - fortunes, err := readFortunes(NORMAL) + fortunes, err := readFortunes(filepath.Join(executablePath(), NORMAL))   if err != nil {   fmt.Fprintf(os.Stderr, "unable to load normal fortunes: %v\n", err)   os.Exit(1)   }   if *offensive { - offensiveFortunes, err := readFortunes(OFFENSIVE) + offensiveFortunes, err := readFortunes(filepath.Join(executablePath(), OFFENSIVE))   if err != nil {   fmt.Fprintf(os.Stderr, "unable to load offensive fortunes: %v\n", err)   os.Exit(1)