diff --git a/cloud/workspace/workspace.go b/cloud/workspace/workspace.go index a0a75bf56..49d109b11 100644 --- a/cloud/workspace/workspace.go +++ b/cloud/workspace/workspace.go @@ -14,6 +14,7 @@ import ( "github.com/astronomer/astro-cli/context" "github.com/astronomer/astro-cli/pkg/ansi" "github.com/astronomer/astro-cli/pkg/input" + "github.com/astronomer/astro-cli/pkg/logger" "github.com/astronomer/astro-cli/pkg/printutil" ) @@ -54,13 +55,17 @@ func GetCurrentWorkspace() (string, error) { func List(client astrocore.CoreClient, out io.Writer) error { c, err := config.GetCurrentContext() if err != nil { + logger.Debugf("Failed to get current context: %v", err) return err } + logger.Debugf("Current context - Organization: %s, Workspace: %s", c.Organization, c.Workspace) ws, err := GetWorkspaces(client) if err != nil { + logger.Debugf("Failed to fetch workspaces: %v", err) return err } + logger.Debugf("Successfully retrieved %d workspace(s)", len(ws)) tab := newTableOut() for i := range ws { @@ -71,6 +76,7 @@ func List(client astrocore.CoreClient, out io.Writer) error { if c.Workspace == ws[i].Id { color = true + logger.Debugf("Workspace '%s' (ID: %s) is the current workspace", name, workspace) } else { color = false } diff --git a/cmd/root_hooks.go b/cmd/root_hooks.go index b97606c01..2ed9bd76e 100644 --- a/cmd/root_hooks.go +++ b/cmd/root_hooks.go @@ -20,8 +20,18 @@ import ( // SetupLogging is a pre-run hook shared between software & cloud // setting up log verbosity. -func SetupLogging(_ *cobra.Command, _ []string) error { - return softwareCmd.SetUpLogs(os.Stdout, verboseLevel) +func SetupLogging(cmd *cobra.Command, _ []string) error { + // This fixes an issue where the package variable may not be properly bound in some build environments + level := verboseLevel + if cmd != nil { + if flagValue, err := cmd.Flags().GetString("verbosity"); err == nil && flagValue != "" { + level = flagValue + } else if flagValue, err := cmd.Root().PersistentFlags().GetString("verbosity"); err == nil && flagValue != "" { + level = flagValue + } + } + + return softwareCmd.SetUpLogs(os.Stdout, level) } // CreateRootPersistentPreRunE takes clients as arguments and returns a cobra diff --git a/software/workspace/workspace.go b/software/workspace/workspace.go index e022c07d0..9724b6c31 100644 --- a/software/workspace/workspace.go +++ b/software/workspace/workspace.go @@ -9,6 +9,7 @@ import ( "github.com/astronomer/astro-cli/config" "github.com/astronomer/astro-cli/houston" "github.com/astronomer/astro-cli/pkg/input" + "github.com/astronomer/astro-cli/pkg/logger" "github.com/astronomer/astro-cli/pkg/printutil" ) @@ -64,13 +65,17 @@ func Create(label, desc string, client houston.ClientInterface, out io.Writer) e func List(client houston.ClientInterface, out io.Writer) error { ws, err := houston.Call(client.ListWorkspaces)(nil) if err != nil { + logger.Debugf("Failed to fetch workspaces: %v", err) return err } + logger.Debugf("Successfully retrieved %d workspace(s)", len(ws)) c, err := config.GetCurrentContext() if err != nil { + logger.Debugf("Failed to get current context: %v", err) return err } + logger.Debugf("Current context - Workspace: %s", c.Workspace) tab := newTableOut() for i := range ws { @@ -82,6 +87,7 @@ func List(client houston.ClientInterface, out io.Writer) error { if c.Workspace == w.ID { color = true + logger.Debugf("Workspace '%s' (ID: %s) is the current workspace", name, workspace) } else { color = false }