Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn when a positional argument might have been a flag #1147

Merged

Conversation

joe-kimmel-vmw
Copy link
Contributor

@joe-kimmel-vmw joe-kimmel-vmw commented Jul 11, 2023

I was tempted to make it a fatal error and exit but honestly someone out there probably has an app called -minuses-are-cool-characters-to-start-my-app-name-with or something.

before

> ./exporter  apps/bash-script -launcher ../lifecycle/out/darwin-amd64/lifecycle/launcher

would result in a bunch of reasonable looking output but end with:

ERROR: failed to export: creating launcher layers: failed to stat launcher at path '/cnb/lifecycle/launcher': stat /cnb/lifecycle/launcher: no such file or directory

because we put the -launcher flag after the app name.
NOTE that this is much harder to notice if there's several other args, especially if the app-name positional arg is preceded by a boolean flag arg such as -daemon.

after
Your stuff will still fail, but there'll be a big warning message towards the top saying something like

Warning: Warning: unconsumed flag-like positional arg:
	-launcher ../lifecycle/out/darwin-amd64/lifecycle/launcher
	 This will not be interpreted as a flag.
	 Did you mean to put this before the first positional argument?

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>
@joe-kimmel-vmw joe-kimmel-vmw requested a review from a team as a code owner July 11, 2023 21:11
@natalieparellano natalieparellano merged commit e18a752 into buildpacks:main Jul 12, 2023
7 checks passed
@natalieparellano natalieparellano deleted the warn-when-flags-become-args branch July 12, 2023 18:12
@@ -57,6 +57,12 @@ func Run(c Command, withPhaseName string, asSubcommand bool) {
}
cmd.DefaultLogger.Debugf("Starting %s...", withPhaseName)

for _, arg := range flagSet.Args() {
if arg[0:1] == "-" {
cmd.DefaultLogger.Warnf("Warning: unconsumed flag-like positional arg: \n\t%s\n\t This will not be interpreted as a flag.\n\t Did you mean to put this before the first positional argument?", arg)
Copy link
Member

Choose a reason for hiding this comment

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

Oh, this was already merged, but I think we could remove the Warning: because we are using Warnf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah... @jjbustamante you're right - it's a "Warning: Warning: " 😅 maybe we say it extra to make up for all the years we were silent about it???

dlion pushed a commit to dlion/lifecycle that referenced this pull request Jul 20, 2023
joe-kimmel-vmw added a commit to joe-kimmel-vmw/lifecycle that referenced this pull request Jul 20, 2023
natalieparellano added a commit that referenced this pull request Aug 9, 2023
* restorer gets layers flag again

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

* add explanatory debug logs so a reader knows why the buildpacks are read twice.

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

* warn when a positional argument might have been a flag (#1147)

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

* Add test for empty digest not returned

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Fix acceptance by providing a base image when we instantiate the remote run image

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* timestamp logs and phase error message cherry-picks (#1164)

* timestamp logs for entry/exit for all the top-level Lifecycle package functions

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

fixing names

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

using defer to make one-liners for fun and profit

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

and today we thank our brave linters for preventing critical defects such as unnecessary trailing newlines from being merged. Its about time somebody thought of the children.

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

* be more helpful when you dont recognize the phase

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

---------

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

* Simplifies target matching logic per spec PR review (#1166)

* Update units without updating code

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Update code

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Unpend test

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add units for rebase without updating code

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Update rebase code

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Fix lint

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When we read the descriptor file, don't fill in "*" as a magic value as missing values are wildcard matches

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Stricter validation for rebase

Signed-off-by: Natalie Arellano <narellano@vmware.com>

---------

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add -daemon to restorer (#1168)

This is needed when extensions were used to switch (but not extend) the run image
and we need to re-read the target data from the image config.

In such cases, we don't need the run image to exist in a registry,
because we don't need a manifest for kaniko.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Remove CNB_TARGET_ID according to buildpacks/spec#374 and buildpacks/spec#375 (#1175)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Field renames per spec review (#1170)

* Rename distributions -> distros in the buildpack spec

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Rename distributions -> distros in the platform spec

Signed-off-by: Natalie Arellano <narellano@vmware.com>

---------

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* force pack acceptance tests to build with a version of go that can still make HTTP requests to docker daemon (#1158)

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>

---------

Signed-off-by: Joe Kimmel <jkimmel@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Co-authored-by: Joe Kimmel <jkimmel@vmware.com>
Co-authored-by: Joe Kimmel <86852107+joe-kimmel-vmw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants