• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

astronomer / astro-cli / 3594e26d-8682-4297-8627-84e8d776b975

27 Oct 2025 08:29PM UTC coverage: 38.52% (+0.01%) from 38.51%
3594e26d-8682-4297-8627-84e8d776b975

Pull #1968

circleci

ronidelacruz-astro
Merge branch 'fix-verbosity-issue' of github.com:astronomer/astro-cli into fix-verbosity-issue
Pull Request #1968: Verbosity flag provides no extra information (#1501)

15 of 20 new or added lines in 3 files covered. (75.0%)

46 existing lines in 2 files now uncovered.

24148 of 62689 relevant lines covered (38.52%)

10.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/cmd/root_hooks.go
1
package cmd
2

3
import (
4
        "errors"
5
        "net/http"
6
        "os"
7
        "strings"
8
        "time"
9

10
        astrocore "github.com/astronomer/astro-cli/astro-client-core"
11
        astroplatformcore "github.com/astronomer/astro-cli/astro-client-platform-core"
12
        cloudCmd "github.com/astronomer/astro-cli/cmd/cloud"
13
        softwareCmd "github.com/astronomer/astro-cli/cmd/software"
14
        "github.com/astronomer/astro-cli/config"
15
        "github.com/astronomer/astro-cli/context"
16
        "github.com/astronomer/astro-cli/version"
17
        "github.com/google/go-github/v48/github"
18
        "github.com/spf13/cobra"
19
)
20

21
// SetupLogging is a pre-run hook shared between software & cloud
22
// setting up log verbosity.
23
func SetupLogging(cmd *cobra.Command, _ []string) error {
8✔
24
        // This fixes an issue where the package variable may not be properly bound in some build environments
8✔
25
        level := verboseLevel
8✔
26
        if cmd != nil {
16✔
27
                if flagValue, err := cmd.Flags().GetString("verbosity"); err == nil && flagValue != "" {
15✔
28
                        level = flagValue
7✔
29
                } else if flagValue, err := cmd.Root().PersistentFlags().GetString("verbosity"); err == nil && flagValue != "" {
8✔
NEW
30
                        level = flagValue
×
NEW
31
                }
×
32
        }
33

34
        return softwareCmd.SetUpLogs(os.Stdout, level)
8✔
35
}
36

37
// CreateRootPersistentPreRunE takes clients as arguments and returns a cobra
38
// pre-run hook that sets up the context and checks for the latest version.
39
func CreateRootPersistentPreRunE(astroCoreClient astrocore.CoreClient, platformCoreClient astroplatformcore.CoreClient) func(cmd *cobra.Command, args []string) error {
21✔
40
        return func(cmd *cobra.Command, args []string) error {
28✔
41
                // Check for latest version
7✔
42
                if config.CFG.UpgradeMessage.GetBool() {
14✔
43
                        // create github client with 3 second timeout, setting an aggressive timeout since its not mandatory to get a response in each command execution
7✔
44
                        githubClient := github.NewClient(&http.Client{Timeout: 3 * time.Second})
7✔
45
                        // compare current version to latest
7✔
46
                        err := version.CompareVersions(githubClient, "astronomer", "astro-cli")
7✔
47
                        if err != nil {
7✔
48
                                softwareCmd.InitDebugLogs = append(softwareCmd.InitDebugLogs, "Error comparing CLI versions: "+err.Error())
×
49
                        }
×
50
                }
51
                if context.IsCloudContext() {
13✔
52
                        err := cloudCmd.Setup(cmd, platformCoreClient, astroCoreClient)
6✔
53
                        if err != nil {
6✔
54
                                if strings.Contains(err.Error(), "token is invalid or malformed") {
×
55
                                        return errors.New("API Token is invalid or malformed") //nolint
×
56
                                }
×
57
                                if strings.Contains(err.Error(), "the API token given has expired") {
×
58
                                        return errors.New("API Token is expired") //nolint
×
59
                                }
×
60
                                softwareCmd.InitDebugLogs = append(softwareCmd.InitDebugLogs, "Error during cmd setup: "+err.Error())
×
61
                        }
62
                }
63
                softwareCmd.PrintDebugLogs()
7✔
64
                return nil
7✔
65
        }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc