-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (51 loc) · 1.4 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"path/filepath"
"leet/api"
)
func Usage() {
fmt.Println("Usage: leet [options]")
fmt.Println("Options:")
fmt.Println(" --dir string defines destination directory (required)")
fmt.Println(" --random selects a random problem (optional)")
fmt.Println(" --slug string selects a problem according to provided slug (optional)")
fmt.Println("Note: You must provide the --dir flag. If no problem flag is provided, it defaults to the daily challenge.")
}
func main() {
flag.Usage = Usage
directory := flag.String("dir", "", "defines destination directory")
randomProblem := flag.Bool("random", false, "selects a random problem")
slug := flag.String("slug", "", "selects a problem according to provided slug")
flag.Parse()
if *directory == "" {
fmt.Println("Error: You must inform a root directory using --dir flag.")
flag.Usage()
return
}
dir, err := filepath.Abs(*directory)
if err != nil {
fmt.Println("Error getting specified directory:", err)
return
}
var question api.Question
switch {
case *randomProblem:
question, err = api.GetRandomQuestion()
case *slug != "":
question, err = api.GetQuestionBySlug(*slug)
default:
question, err = api.GetDailyChallenge()
}
if err != nil {
fmt.Println(err)
return
}
var d string
if d, err = api.SetUpEnv(dir, question); err != nil {
fmt.Println(err)
return
}
fmt.Println(d)
}