-
Notifications
You must be signed in to change notification settings - Fork 27
/
root.go
56 lines (50 loc) · 1.18 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright © 2022 AssemblyAI support@assemblyai.com
*/
package cmd
import (
"fmt"
"os"
S "github.com/AssemblyAI/assemblyai-cli/schemas"
U "github.com/AssemblyAI/assemblyai-cli/utils"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
)
var VERSION string
var rootCmd = &cobra.Command{
Use: "assemblyai",
Short: "AssemblyAI CLI",
Long: `Please authenticate to use the CLI.
assemblyai config [token]`,
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Run: func(cmd *cobra.Command, args []string) {
versionFlag, _ := cmd.Flags().GetBool("version")
if versionFlag {
fmt.Printf("AssemblyAI CLI %s\n", VERSION)
} else {
cmd.Help()
}
},
}
func Execute() {
if VERSION == "" {
godotenv.Load()
VERSION = os.Getenv("VERSION")
}
U.CheckForUpdates(VERSION)
if err := rootCmd.Execute(); err != nil {
printErrorProps := S.PrintErrorProps{
Error: err,
Message: err.Error(),
}
U.PrintError(printErrorProps)
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().BoolP("version", "v", false, "Check current installed version.")
rootCmd.Flags().Bool("test", false, "Flag for test executing purpose")
rootCmd.Flags().MarkHidden("test")
}