-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
v1 regression: v1.22.2-and-over skips over flag-like arguments to subcommand string slice flags #1152
Comments
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are two issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are three issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). * Updating github.com/cpuguy83/go-md2man to v2 caused issues with our "go get" invocation. It turns out we were silently adding go-md2man (v1) to our go.mod file each time we ran a Travis build, and the switch to v2 uncovered this issue. This is easily fixed by setting GO111MODULE=off when doing 'go get' in .travis.yml. [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de> asd Signed-off-by: Aleksa Sarai <asarai@suse.de>
We haven't done a dependency bump in quite a while, and there are a fair few fixes and improvements we should get into umoci before the next release. % go get -u go: github.com/apex/log upgrade => v1.4.0 go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0 go: github.com/golang/protobuf upgrade => v1.4.2 go: github.com/klauspost/compress upgrade => v1.10.9 go: github.com/klauspost/cpuid upgrade => v1.3.0 go: github.com/klauspost/pgzip upgrade => v1.2.4 go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.3 go: github.com/opencontainers/go-digest upgrade => v1.0.0 go: github.com/opencontainers/runtime-spec upgrade => v1.0.2 go: github.com/pkg/errors upgrade => v0.9.1 go: github.com/sirupsen/logrus upgrade => v1.6.0 go: github.com/vbatts/go-mtree upgrade => v0.5.0 go: golang.org/x/crypto upgrade => v0.0.0-20200604202706-70a84ac30bf9 go: golang.org/x/net upgrade => v0.0.0-20200602114024-627f9648deb9 go: golang.org/x/sys upgrade => v0.0.0-20200615200032-f1bc736245b1 go: google.golang.org/protobuf upgrade => v1.24.0 However there are three issues with this update: * We cannot update github.com/urfave/cli to anything later than v1.22.1 because of a bug when it comes to StringSliceFlag parsing that we hit in CI[1] -- hence the new excludes block. * Updating github.com/klauspost/compress to anything later than v1.8.6 causes us to generate different gzip-compressed blobs due to an optimisation in their compression[2]. Since this is generally a good change to have, we have to update our CI so that it works with the newest version (even if it's sub-optimal to generate different bytes between versions). * Updating github.com/cpuguy83/go-md2man to v2 caused issues with our "go get" invocation. It turns out we were silently adding go-md2man (v1) to our go.mod file each time we ran a Travis build, and the switch to v2 uncovered this issue. This is easily fixed by setting GO111MODULE=off when doing 'go get' in .travis.yml. [1]: urfave/cli#1152 [2]: klauspost/compress#105 Signed-off-by: Aleksa Sarai <asarai@suse.de>
Thanks for the well written bug report 👍 we get regressions of this sort fairly frequently, unfortunately. You're free to try your hand at fixing it, but I would just warn you that you'd probably end up creating regression for someone else's case 😅 |
Is it an issue of not enough test cases in For the bug at hand, using the above program, I've bisected it to 7d0751f:
But I think the bug is older and 7d0751f just exposed it by making it so that unknown flags also get re-ordered. It seems to me like the issue is with this check in
So I think that this invocation only happened to work in the past, because the argument re-ordering would re-order all arguments that looked like flags rather than just known arguments (now that known arguments are kept in place, the arguments get re-ordered to Before I go about writing a patch for this, I should probably ask whether As a workaround I can just disable argument re-ordering (which I don't use anyway). |
Ah okay, so the newest version looks a bit different -- I think this line should be
But that will cause issues with boolean flags (or any flag that doesn't take an argument) because you could end up reordering some later argument ( |
It turns out that urfave/cli hasn't been happy with parsing command-lines like [--config.cmd -c] for quite some time, and [1] only just exposed the issue in a test-case. There are loads of more subtle cases where you could see this happened even in the version of urfave/cli we have vendored. Until it's fixed upstream (which might not happen), we have to work around this by disabling argument reordering for 'umoci config' (which is the only command that usually has to deal with such flag arguments, and luckily doesn't take any positional arguments). [1]: urfave/cli#1152 Signed-off-by: Aleksa Sarai <asarai@suse.de>
It turns out that urfave/cli hasn't been happy with parsing command-lines like [--config.cmd -c] for quite some time, and only just exposed the issue in a test-case[1]. There are loads of more subtle cases where you could see this happened even in the version of urfave/cli we have vendored. Until it's fixed upstream (which might not happen), we have to work around this by disabling argument reordering for 'umoci config' (which is the only command that usually has to deal with such flag arguments, and luckily doesn't take any positional arguments). [1]: urfave/cli#1152 Signed-off-by: Aleksa Sarai <asarai@suse.de>
Tests. There's essentially no documentation about this - and I'm willing to bet that writing tests for this is easier than writing documentation.
Which, in case it's not obvious, is a change that itself was fixing a regression: #872.
I don't know what we for this case offhand, but whatever we do now is what we should continue to do. This is exactly the kind of thing that would cause a massive regression in someone's system if it was changed.
There is not. |
Oh, there's also an existing PR working on that exact same area of the code: #1135 |
Yeah this is a duplicate of #1135. |
my urfave/cli version is
v1.22.1
was the last working version, and all versions up tov1.22.4
are broken.Checklist
Dependency Management
Describe the bug
If you try to use a flag-like argument to a string slice argument that is not a valid flag, the argument gets ignored and instead the next argument is used instead (which, if it is a valid string slice argument it is swallowed as a flag value).
To reproduce
First, set up a basic Go dev environment for the test:
And then try to run the following program:
Like so:
% go run main.go config --config.cmd "-c" --config.cmd "ls -la"
Observed behavior
If you use
1.22.2
or later ofgithub.com/urfave/cli
, you find:What appears to be happening is that the
-c
argument to the--config.cmd
flag is being skipped -- though it's not being treated as an unknown flag (there's no error about unknown flags) and instead is being treated as a positional argument. As as result,--config.cmd
is being used as an argument (presumably because it's a known flag?) and the rest of the arguments are treated as positional arguments.However, if you instead call the program like so you get the correct output:
Expected behavior
If you use
1.22.1
or earlier ofgithub.com/urfave/cli
, you find:Additional context
I am trying to update my version of
github.com/urfave/cli
in umoci and this is an issue I hit almost immediately when trying to do the update.N.B. This issue doesn't happen unless you use subcommands. If you try to do this with the top-level
app.Flags
then it works as expected.Run
go version
and paste its output hereRun
go env
and paste its output hereThe text was updated successfully, but these errors were encountered: