-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (35 loc) · 720 Bytes
/
main.go
File metadata and controls
44 lines (35 loc) · 720 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
package main
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cycloidio/cycloid-cli/cmd"
)
var (
// Used for flags.
rootCmd *cobra.Command
)
type exitCoder interface {
ExitCode() int
}
func inRed(msg string) string {
return fmt.Sprintf("\033[1;31m%s\033[0m", msg)
}
// Execute runs the CLI root command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
rootCmd.PrintErrln(inRed("Error:"), err.Error())
var codedErr exitCoder
if errors.As(err, &codedErr) {
os.Exit(codedErr.ExitCode())
}
os.Exit(1)
}
}
func main() {
rootCmd = cmd.NewRootCommand()
viper.BindPFlag("api-url", rootCmd.PersistentFlags().Lookup("api-url"))
Execute()
}