-
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
String flag cannot be set to "-1" #1092
Comments
😅 looks like it thinks 🙏 PRs are welcome 🙏 |
Did some quick testing to do a minimal reproducer (LOL, I never worked with urfave/cli, so "code by example" 😅); package main
import (
"fmt"
"os"
"strings"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "flagtest"
app.Action = func(c *cli.Context) error {
fmt.Println("opt:", c.String("opt"))
fmt.Println("args:", strings.Join(c.Args(), ","))
return nil
}
app.Commands = []cli.Command{{
Name: "subcommand",
Action: func(c *cli.Context) error {
fmt.Println("opt:", c.String("opt"))
fmt.Println("args:", strings.Join(c.Args(), ","))
return nil
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "opt",
Usage: "opt; set '-1' to disable",
},
},
}}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
} Testing variations; go run flagtest.go subcommand
option:
args:
go run flagtest.go subcommand arg1
opt:
args: arg1
go run flagtest.go subcommand arg1 arg2
opt:
args: arg1,arg2
go run flagtest.go subcommand --opt opt-value
option: opt-value
args:
go run flagtest.go subcommand --opt opt-value arg1
opt: opt-value
args: arg1
go run flagtest.go subcommand --opt opt-value arg1 arg2
opt: opt-value
args: arg1,arg2
go run flagtest.go subcommand arg1 --opt opt-value
opt: opt-value
args: arg1
go run flagtest.go subcommand arg1 --opt opt-value arg2
opt: opt-value
args: arg1,arg2 Using go run flagtest.go subcommand --opt -opt-value
opt: -opt-value
args:
go run flagtest.go subcommand --opt -opt-value arg1
Incorrect Usage: flag provided but not defined: -opt-value
go run flagtest.go subcommand --opt -opt-value arg1 arg2
Incorrect Usage: flag provided but not defined: -opt-value
go run flagtest.go subcommand arg1 --opt -opt-value
Incorrect Usage: flag provided but not defined: -opt-value
go run flagtest.go subcommand arg1 --opt -opt-value arg2
opt: arg2
args: arg1,-opt-value |
And a test-case; func TestParseAndRunHyphenValues(t *testing.T) {
cases := []struct {
testArgs []string
expectedArgs []string
expectedOpt string
}{
{[]string{"foo", "test", "arg1"}, []string{"arg1"}, ""},
{[]string{"foo", "test", "arg1", "arg2"}, []string{"arg1", "arg2"}, ""},
{[]string{"foo", "test", "--opt", "opt-value"}, []string{}, "opt-value"},
{[]string{"foo", "test", "--opt", "opt-value", "arg1"}, []string{"arg1"}, "opt-value"},
{[]string{"foo", "test", "--opt", "opt-value", "arg1", "arg2"}, []string{"arg1", "arg2"}, "opt-value"},
{[]string{"foo", "test", "arg1", "--opt", "opt-value"}, []string{"arg1"}, "opt-value"},
{[]string{"foo", "test", "arg1", "--opt", "opt-value", "arg2"}, []string{"arg1", "arg2"}, "opt-value"},
{[]string{"foo", "test", "--opt", "-opt-value"}, []string{}, "-opt-value"},
{[]string{"foo", "test", "--opt", "-opt-value", "arg1"}, []string{"arg1"}, "-opt-value"},
{[]string{"foo", "test", "--opt", "-opt-value", "arg1", "arg2"}, []string{"arg1", "arg2"}, "-opt-value"},
{[]string{"foo", "test", "arg1", "--opt", "-opt-value"}, []string{"arg1"}, "-opt-value"},
{[]string{"foo", "test", "arg1", "--opt", "-opt-value", "arg2"}, []string{"arg1", "arg2"}, "-opt-value"},
{[]string{"foo", "test", "--opt", "--opt-value"}, []string{}, "--opt-value"},
{[]string{"foo", "test", "--opt", "--opt-value", "arg1"}, []string{"arg1"}, "--opt-value"},
{[]string{"foo", "test", "--opt", "--opt-value", "arg1", "arg2"}, []string{"arg1", "arg2"}, "--opt-value"},
{[]string{"foo", "test", "arg1", "--opt", "--opt-value"}, []string{"arg1"}, "-opt-value"},
{[]string{"foo", "test", "arg1", "--opt", "--opt-value", "arg2"}, []string{"arg1", "arg2"}, "--opt-value"},
}
for _, tc := range cases {
tc := tc
t.Run(strings.Join(tc.testArgs, "_"), func(t *testing.T){
var (
args []string
opt string
)
cmd := Command{
Name: "test",
Usage: "this is for testing",
Description: "testing",
Action: func(c *Context) error {
args = c.Args()
opt = c.String("opt")
return nil
},
Flags: []Flag{StringFlag{
Name: "opt",
Usage: "opt; set '-1' to disable",
}},
}
app := NewApp()
app.Writer = ioutil.Discard
app.ErrWriter = ioutil.Discard
app.Commands = []Command{cmd}
err := app.Run(tc.testArgs)
expect(t, err, nil)
expect(t, args, tc.expectedArgs)
expect(t, opt, tc.expectedOpt)
})
}
} (I'll open a "draft" PR with the test case) |
opened #1135 as a draft; I'll try to do a git-bisect and/or look at a fix, but not sure yet if I find time (thought the test-case would be a start to assist in this); anyone else: feel free to pick up the work if I don't come round to it |
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
no stale |
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
no stale |
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
Arf, trying to find time to work on this again, sorry for it taking so long |
👀 |
Would love to see a fix for this one. |
There is a PR, but not merged yet #1135 |
This is still the case with 1.22.5. |
Is this library still alive? |
Yes, but unfortunately I and other maintainers have not been able to dedicate as much time as we would like to. That said, definitely interested in keeping this alive, especially for bug fixes. From the linked PR, it looks like there are issues with the proposed fix that haven't been addressed. I'm not sure what the best path forward is from here. |
Apologies for that; it had been dropping down my list to spend time on diving into it again, and not sure when I'm able to. I will try to find some time for it, but if someone wants to carry my changes from #1135, feel free to do so (feel free to take my patch as a starting point if that helps) |
IIUC this should now be resolved via #1356 Please holler if that's not true! |
my urfave/cli version is
v1.22.1, v1.22.2, v1.22.3 (broken since v1.22.2)
Checklist
Dependency Management
Describe the bug
This flag can be set to "-1" on v1.22.1 but cannot be set since v1.22.2.
https://github.com/opencontainers/runc/blob/be51398a8af0b32b0b580e4da069cc6f704639bf/update.go#L111-L114
Regression in v1.22.1...v1.22.2
To reproduce
Specify
urfave/cli
version ingo.mod
in the runc tree, rungo mod tidy
,go mod vendor
, andmake integration
.Observed behavior
Expected behavior
It should not fail.
Additional context
opencontainers/runc#2268 (comment)
Run
go version
and paste its output hereFor vendoring:
For running the containerized test suite:
The text was updated successfully, but these errors were encountered: