Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

cli: set project on cfg #2526

Merged
merged 5 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2526.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cli: Fix panic in logs and exec commands
```
32 changes: 8 additions & 24 deletions internal/cli/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, running waypoint exec bin/bash causes a panic.

Even with this, it's not great behavior, because it parses bin as the project and bash as the app, but it's the same behavior as 0.5.2 and we can address it later.

c.refApp = &pb.Ref_Application{
Project: match[1],
Application: match[2],
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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<project>[-0-9A-Za-z_]+)/(?P<app>[-0-9A-Za-z_]+)$`)

Expand Down