-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
60 lines (52 loc) · 1.06 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
package main
import (
"flag"
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/coding-socks/matroska/cmd/mkc/internal/cli"
"github.com/coding-socks/matroska/cmd/mkc/internal/extract"
"github.com/coding-socks/matroska/cmd/mkc/internal/list"
"log"
"os"
)
var commands = []*cli.Command{
extract.Cmd,
list.Cmd,
}
func main() {
flag.Parse()
mode := flag.Arg(0)
if mode == "" {
options := make([]string, len(commands))
for i := range commands {
options[i] = commands[i].Flags.Name()
}
modeSelector := &survey.Select{
Message: "Choose a mode:",
Options: options,
}
if err := survey.AskOne(modeSelector, &mode); err != nil {
if err == terminal.InterruptErr {
return
}
log.Fatal(err)
}
}
for _, cmd := range commands {
if cmd.Flags.Name() != mode {
continue
}
args := flag.Args()
if len(args) > 0 {
if err := cmd.Flags.Parse(args[1:]); err != nil {
os.Exit(1)
return
}
}
cmd.Run(cmd.Flags)
return
}
fmt.Printf("Unknown mode: %s\n", mode)
os.Exit(1)
}