github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/cmd/ots/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 8 cmdutil "github.com/leg100/ots/cmd" 9 "github.com/spf13/cobra" 10 ) 11 12 func main() { 13 // Configure ^C to terminate program 14 ctx, cancel := context.WithCancel(context.Background()) 15 cmdutil.CatchCtrlC(cancel) 16 17 if err := Run(ctx, os.Args[1:]); err != nil { 18 fmt.Fprintln(os.Stderr, err) 19 os.Exit(1) 20 } 21 } 22 23 func Run(ctx context.Context, args []string) error { 24 cmd := &cobra.Command{ 25 Use: "ots", 26 SilenceUsage: true, 27 SilenceErrors: true, 28 } 29 cmd.SetArgs(args) 30 31 cmd.AddCommand(LoginCommand(&SystemDirectories{})) 32 cmd.AddCommand(OrganizationCommand()) 33 cmd.AddCommand(WorkspaceCommand()) 34 35 cmdutil.SetFlagsFromEnvVariables(cmd.Flags()) 36 37 if err := cmd.ExecuteContext(ctx); err != nil { 38 return err 39 } 40 return nil 41 }