-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (62 loc) · 1.08 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
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"os"
dirp "github.com/avindra/dirp/src"
)
func driller(path string) {
cfg := dirp.FindDirs(path)
dirp.Selector(cfg)
}
func main() {
args := os.Args
args = args[1:]
if len(args) > 0 {
// compat with go run . --
if args[0] == "--" {
args = args[1:]
if len(args) == 0 {
goto NOARGS
}
}
arg0 := args[0]
if dirp.IsDir(arg0) {
driller(arg0)
} else if arg0 == "hook" {
if len(args) >= 2 {
switch args[1] {
case "fish":
dirp.PrintFishHook()
case "es":
dirp.PrintEsHook()
case "rc":
dirp.PrintRcHook()
default:
panic("I don't know about " + args[1])
}
} else {
dirp.PrintHook()
}
} else if arg0 == "cfg" {
fmt.Print(dirp.GetConfigPath())
os.Exit(2)
}
return
}
NOARGS:
var cfg dirp.ConfigSelection
if dirp.InputHasData() {
cfg = dirp.ReadConfig(os.Stdin)
} else {
f, err := os.Open(dirp.GetConfigPath())
if err == nil {
cfg = dirp.ReadConfig(f)
}
}
if len(cfg) > 0 {
dirp.Selector(cfg)
} else {
// No config detected, default to driller
driller(".")
}
}