diff --git a/.changelog/2526.txt b/.changelog/2526.txt new file mode 100644 index 00000000000..470a47239ea --- /dev/null +++ b/.changelog/2526.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Fix panic in logs and exec commands +``` \ No newline at end of file diff --git a/internal/cli/base.go b/internal/cli/base.go index 998482aa96e..f4774b78aaa 100644 --- a/internal/cli/base.go +++ b/internal/cli/base.go @@ -240,6 +240,7 @@ func (c *baseCommand) Init(opts ...Option) error { match := reAppTarget.FindStringSubmatch(c.args[0]) if match != nil { // Set our refs + c.refProject = &pb.Ref_Project{Project: match[1]} c.refApp = &pb.Ref_Application{ Project: match[1], Application: match[2], @@ -314,18 +315,17 @@ func (c *baseCommand) Init(opts ...Option) error { c.cfg = cfg if cfg != nil { + project := &pb.Ref_Project{Project: cfg.Project} // If we require a project target and we still haven't set it, // and the user provided it via the CLI, set it now. // If they didn't provide a value via flag, we default to // the project from initConfig. - if (baseCfg.AppOptional || baseCfg.ProjectTargetRequired) && - c.refProject == nil { - if c.flagProject != "" { - c.refProject = &pb.Ref_Project{Project: c.flagProject} - } else { - c.refProject = &pb.Ref_Project{Project: cfg.Project} - } + if baseCfg.ProjectTargetRequired && c.flagProject != "" { + project = &pb.Ref_Project{Project: c.flagProject} + } + if c.refProject == nil { + c.refProject = project } // If we require an app target and we still haven't set it, @@ -336,7 +336,7 @@ func (c *baseCommand) Init(opts ...Option) error { c.refApp == nil && c.flagApp != "" { c.refApp = &pb.Ref_Application{ - Project: c.refProject.Project, + Project: project.Project, Application: c.flagApp, } } @@ -395,19 +395,6 @@ func (c *baseCommand) Init(opts ...Option) error { } } - if baseCfg.ProjectTargetRequired { - if c.refProject == nil { - if len(c.cfg.Project) == 0 { - c.ui.Output(errProjectMode, terminal.WithErrorStyle()) - return ErrSentinel - } - - c.refProject = &pb.Ref_Project{ - Project: c.cfg.Project, - } - } - } - return nil } @@ -761,9 +748,6 @@ This command requires a single targeted app. You have multiple apps defined so you can specify the app to target using the "-app" flag. `) - errProjectMode = strings.TrimSpace(` -This command requires a targeted project.`) - // matches either "project" or "project/app" reAppTarget = regexp.MustCompile(`^(?P[-0-9A-Za-z_]+)/(?P[-0-9A-Za-z_]+)$`)