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

CLI: Warn if project from flags mismatches project from config #2815

Merged
merged 5 commits into from
Dec 21, 2021

Conversation

izaaklauer
Copy link
Contributor

@izaaklauer izaaklauer commented Dec 7, 2021

What changed

A user can add the -project flag when they're in some other project's directory:

Example:

$ cd ~/projects/project-a
$ cat waypoint.hcl # it exists
$ waypoint deploy -project=project-b

This means one of two things:

1: They added the flag explicitly, and they want to operate against project-b.

2: The user wants to operate against the project that matches the directory they're in, but they've copied the -project flag from some other command/example.

We could just error here, but it feels onerous to force the user from scenario 1 to cd into some safe directory before running their command.

The middle ground here is to continue to allow flags to override config, but issue a warning to help the user from scenario 2. We also force the operation to happen remotely, as the local runner doesn't currently support cloning down some other project's vcs source.

What this looks like

$ waypoint build -project=learn-waypoint-lambda
Warning: Currently in project directory for "example-nginx-ami", but will operate 
against specified project "learn-waypoint-lambda"

» Building learn-waypoint-lambda...

» Cloning data from Git
  URL: https://github.com/hashicorp/waypoint-examples
  Ref: us-east-1
...

@github-actions github-actions bot added the core label Dec 7, 2021
@izaaklauer izaaklauer force-pushed the detect-project-flag-mismatch branch from 7adb147 to 797dbc2 Compare December 7, 2021 21:10
Comment on lines 334 to 335
c.refProject = nil
c.refApps = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It feels a little bit messy to undo the refs that were set in the above config-parsing block - if someday we set more refs up there, we'll have to remember to roll them back here.

Moving this flag mismatch check into the config parsing block feels messy too though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like you could move this into the if !baseCfg.NoConfig block because thats the only place we populate refProject. From there, it feels cleaner to avoid ever setting these extra fields. That way the place where its set is totally just one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, i'm not sure if I entirely follow - we'll still need to set refProject outside of baseCfg.NoConfig, because there may be commands that need a project ref but don't want config parsed. I took another stab at it though, moving more logic up into the baseCfg.NoConfig block to avoid setting the refs in the first place if the config and flag defined project names collide.

Still feels a bit messy, because now we're checking c.flagProject twice - but it's not too bad. Let me know if you see a better pathway.

@izaaklauer izaaklauer marked this pull request as ready for review December 7, 2021 21:13
@izaaklauer izaaklauer requested a review from a team December 7, 2021 21:13
Copy link
Contributor

@krantzinator krantzinator left a comment

Choose a reason for hiding this comment

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

Nice

.changelog/2815.txt Outdated Show resolved Hide resolved
@izaaklauer izaaklauer changed the title Warn if project from flags mismatches project from config CLI: Warn if project from flags mismatches project from config Dec 7, 2021
Comment on lines 334 to 335
c.refProject = nil
c.refApps = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like you could move this into the if !baseCfg.NoConfig block because thats the only place we populate refProject. From there, it feels cleaner to avoid ever setting these extra fields. That way the place where its set is totally just one place.

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

A minor update request in the warning message, but otherwise looks good to me!

Still feels a bit messy, because now we're checking c.flagProject twice - but it's not too bad. Let me know if you see a better pathway.

Tried to catch up on this conversation....from what you have now I think that seems ok to me. The project flag check is mostly for the warning to be displayed if no config, then the second time we check immediately after is for setting project refs.

internal/cli/base.go Show resolved Hide resolved
izaaklauer and others added 5 commits December 20, 2021 17:57
Also force remoteness. If we don't do that, we may spawn a local runner, which will parse the config that we know doesn't match the user's flags.
@izaaklauer izaaklauer force-pushed the detect-project-flag-mismatch branch from 9479571 to 40dcddc Compare December 20, 2021 23:58
@izaaklauer izaaklauer merged commit 886e9e2 into main Dec 21, 2021
@izaaklauer izaaklauer deleted the detect-project-flag-mismatch branch December 21, 2021 00:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants