From d34c5d9f1e044699efc492f7a399ee05caf84ed6 Mon Sep 17 00:00:00 2001 From: Mason Williams Date: Tue, 19 Aug 2025 20:45:28 -0400 Subject: [PATCH] refactor(root): extract auth exemption logic --- cmd/root.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 082f0df..6c4ae23 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,6 +71,20 @@ func getKernelClient(cmd *cobra.Command) kernel.Client { return cmd.Context().Value(KernelClientKey).(kernel.Client) } +// isAuthExempt returns true if the command or any of its parents should skip auth. +func isAuthExempt(cmd *cobra.Command) bool { + for c := cmd; c != nil; c = c.Parent() { + if c == rootCmd { + return true + } + switch c.Name() { + case "login", "logout", "auth", "help", "completion": + return true + } + } + return false +} + func init() { rootCmd.PersistentFlags().BoolP("version", "v", false, "Print the CLI version") rootCmd.PersistentFlags().BoolP("no-color", "", false, "Disable color output") @@ -88,9 +102,8 @@ func init() { pterm.DisableStyling() } - // Check if this command requires authentication - // Skip auth check for root command (help) and commands that don't need it - if cmd == rootCmd || cmd.Name() == "login" || cmd.Name() == "logout" || cmd.Name() == "auth" { + // Skip auth check for commands that don't need it (including children, e.g., "completion zsh") + if isAuthExempt(cmd) { return nil }