-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (54 loc) · 1.29 KB
/
main.go
File metadata and controls
61 lines (54 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"aaheen/euler/ans"
"flag"
"fmt"
"os"
"strconv"
)
func main() {
var usage string = `Usage: euler
<p> Run the solution for problem <p>. Directly outputs answer
-i <p> Run the interactive solution session for problem <p>
-g Open this repo on GitHub`
fInter := flag.Bool("i", false, "Run the interactive solution session for problem <p>")
// deprecated
// fWriteup := flag.Bool("s", false, "Open the writeup for problem <p>")
// -s <p> - Open the writeup for problem <p>
fGithub := flag.Bool("g", false, "Open this repo on GitHub")
flag.Parse()
fArgs := flag.Args()
switch len(fArgs) {
case 0: // Either open Github or invalid usage
if *fGithub {
ans.Repo()
} else {
fmt.Println(usage)
}
case 1: // Asking about a specific problem number
p, err := strconv.Atoi(fArgs[0])
if err != nil {
fmt.Println("Error parsing problem ID", fArgs[0])
os.Exit(2)
}
// Recover if Sol, Ask, or solution code panics
defer func() {
if err := recover(); err != nil {
fmt.Println("Error trying to run problem", p, ":\n", err)
os.Exit(1)
}
}()
switch {
case *fInter:
ans.Ask(p)
//case *fWriteup:
// ans.Writeup(p)
case *fGithub:
fmt.Println(usage)
default:
ans.Sol(p)
}
default:
fmt.Println(usage)
}
}