-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
37 lines (31 loc) · 772 Bytes
/
root.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
package command
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "qwertysynth",
Short: "Qwertysynth is a silly little computer keyboard synth",
Long: `Qwertysynth is a silly little computer keyboard synth written entirely in Go`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Usage()
},
}
func Execute() {
cmd, args, err := rootCmd.Find(os.Args[1:])
if err == nil && cmd == rootCmd {
// assume play command if command argument not provided
os.Args = append([]string{os.Args[0], "play"}, args...)
cmd = playCmd
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := cmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}