Adds Ability to Chain Cobra RunE Commands by schnie · Pull Request #1771 · astronomer/astro-cli

PersistentPreRunE: func(cmd *cobra.Command, args []string) error { // Check for latest version if config.CFG.UpgradeMessage.GetBool() { // create github client with 3 second timeout, setting an aggressive timeout since its not mandatory to get a response in each command execution githubClient := github.NewClient(&http.Client{Timeout: 3 * time.Second}) // compare current version to latest err = version.CompareVersions(githubClient, "astronomer", "astro-cli") if err != nil { softwareCmd.InitDebugLogs = append(softwareCmd.InitDebugLogs, "Error comparing CLI versions: "+err.Error()) } } if isCloudCtx { err = cloudCmd.Setup(cmd, platformCoreClient, astroCoreClient) if err != nil { if strings.Contains(err.Error(), "token is invalid or malformed") { return errors.New("API Token is invalid or malformed") //nolint } if strings.Contains(err.Error(), "the API token given has expired") { return errors.New("API Token is expired") //nolint } softwareCmd.InitDebugLogs = append(softwareCmd.InitDebugLogs, "Error during cmd setup: "+err.Error()) } } // common PersistentPreRunE component between software & cloud // setting up log verbosity and dumping debug logs collected during CLI-initialization if err := softwareCmd.SetUpLogs(os.Stdout, verboseLevel); err != nil { return err } softwareCmd.PrintDebugLogs() return nil },