()
| 28 | ) |
| 29 | |
| 30 | func main() { |
| 31 | // if there is a missing or invalid .env file anywhere, we don't care, just ignore it |
| 32 | _ = godotenv.Load() |
| 33 | |
| 34 | viper := viper.GetViper() |
| 35 | |
| 36 | if err := config.Setup(viper); err != nil { |
| 37 | fmt.Println(err) |
| 38 | os.Exit(3) |
| 39 | } |
| 40 | arg := os.Args[1:] |
| 41 | |
| 42 | // initialize our wrapper around survey, which is also used as a flag for whether |
| 43 | // we are in interactive mode or automation mode |
| 44 | askProvider := question.NewAskProvider(survey.AskOne) |
| 45 | _, ci := os.LookupEnv("CI") |
| 46 | // TODO move this to some other function and have it look for GITHUB_ACTIONS etc as we learn more about it |
| 47 | if ci { |
| 48 | askProvider.DisableInteractive() |
| 49 | } |
| 50 | |
| 51 | buildVersion := strings.TrimSpace(version.Version) |
| 52 | |
| 53 | clientFactory, err := apiclient.NewClientFactoryFromConfig(askProvider) |
| 54 | if err != nil { |
| 55 | // a small subset of commands can function even if the app doesn't have valid configuration information |
| 56 | if commandDoesNotRequireClient(arg) { |
| 57 | clientFactory = apiclient.NewStubClientFactory() |
| 58 | } else { |
| 59 | // can't possibly work |
| 60 | fmt.Println(err) |
| 61 | os.Exit(3) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | s := spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithColor("cyan")) |
| 66 | |
| 67 | c := config.New(viper) |
| 68 | |
| 69 | terminalOut := terminal.NewAnsiStdout(os.Stdout) |
| 70 | terminalErr := terminal.NewAnsiStderr(os.Stderr) |
| 71 | |
| 72 | serviceMessageProvider := servicemessages.NewProvider(servicemessages.NewOutputPrinter(terminalOut, terminalErr)) |
| 73 | f := factory.New(clientFactory, askProvider, s, buildVersion, c, serviceMessageProvider) |
| 74 | |
| 75 | cmd := root.NewCmdRoot(f, clientFactory, askProvider) |
| 76 | |
| 77 | // if we don't do this then cmd.Print will get sent to stderr |
| 78 | cmd.SetOut(terminalOut) |
| 79 | cmd.SetErr(terminalErr) |
| 80 | |
| 81 | if err := cmd.Execute(); err != nil { |
| 82 | cmd.PrintErr(err) |
| 83 | cmd.Println() |
| 84 | |
| 85 | if usageError, ok := err.(*usage.UsageError); ok { |
| 86 | // if the code returns a UsageError, print the usage information |
| 87 | cmd.Println(usageError.Command().UsageString()) |
nothing calls this directly
no test coverage detected