-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (66 loc) · 1.67 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
71
72
73
74
75
76
package main
import (
"fmt"
"os"
"git.sr.ht/~tjex/dotf/cmd"
"git.sr.ht/~tjex/dotf/cmd/dotf"
"git.sr.ht/~tjex/dotf/internal/config"
"github.com/alexflint/go-arg"
)
type smCmd struct {
Prime bool `arg:"-p,--prime" default:"false" help:"add and commit all changes to all submodules"`
List bool `arg:"-l,--list" default:"false" help:"list all tracked submodules"`
Edit bool `arg:"-e, --edit" default:"false" help:"cd into selected submodule via fzf"`
}
type pushCmd struct {
Remote string `arg:"positional"`
}
var args struct {
Push *pushCmd `arg:"subcommand:push" help:"push to origin and mirror concurrently"`
Sm *smCmd `arg:"subcommand:sm" help:"operations for git submodules"`
}
func main() {
config.ReadUserConfig()
stdinArgs := os.Args[1:]
p, err := arg.NewParser(arg.Config{Program: "dotf", Exit: os.Exit}, &args)
if err != nil {
fmt.Println(err)
}
if len(os.Args) < 2 {
// Print dotf help if no subcommands given
p.WriteHelp(os.Stdout)
os.Exit(0)
}
p.Parse(stdinArgs)
switch {
case args.Push != nil:
dotf.Push(args.Push.Remote)
case args.Sm != nil:
// positional flags for `sm`
switch {
case args.Sm.Prime:
dotf.Prime()
case args.Sm.List:
dotf.List()
case args.Sm.Edit:
dotf.Edit()
default:
p.WriteHelp(os.Stdout)
}
default:
// If arguments above aren't called, nor is `--help`
if os.Args[1] != "--help" && os.Args[1] != "-h" {
cmd.DotfExecute(stdinArgs)
} else {
var choice string
fmt.Println("dotf wraps around git. \nDisplay help for dotf (d) or git (g)?")
fmt.Scan(&choice)
switch {
case choice == "d":
p.WriteHelp(os.Stdout)
case choice == "g":
cmd.DotfExecute(stdinArgs)
}
}
}
}