-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (49 loc) · 881 Bytes
/
main.go
File metadata and controls
57 lines (49 loc) · 881 Bytes
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
package main
import (
"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 {
handleNoArgs()
return
}
arg0 := args[0]
if dirp.IsDir(arg0) {
driller(arg0)
} else if arg0 == "hook" {
if len(args) >= 2 {
dirp.PrintShellHook(args[1])
} else {
dirp.PrintShellHook("sh")
}
} else if arg0 == "cfg" {
os.Stdout.WriteString(dirp.GetConfigPath())
os.Exit(2)
} else {
handleNoArgs()
}
}
func handleNoArgs() {
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(".")
}
}