-
Notifications
You must be signed in to change notification settings - Fork 5
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
Flag value same as subcommand name result in error #2
Comments
Yes, it seems a bug. Give me a few days, I'll fix it asap. P.S. Thanks for taking your time and reporting issues. I appreciate it... |
See package main
import (
"fmt"
"log"
"os"
"github.com/devfacet/gocmd"
)
func main() {
fmt.Printf("args: %#v\n", os.Args)
flags := struct {
Command struct{} `command:"command"`
Flag string `short:"f" long:"flag" required:"true"`
}{}
_, err := gocmd.New(gocmd.Options{
Flags: &flags,
AnyError: true,
})
if err != nil {
log.Fatal(err)
}
} $ go run main.go -f command
args: []string{"/var/folders/.../exe/main", "-f", "command"}
2018/03/18 11:59:12 argument -f needs a nonempty value
exit status 1
$ go run main.go -f "command"
args: []string{"/var/folders/.../exe/main", "-f", "command"}
2018/03/18 11:59:17 argument -f needs a nonempty value
exit status 1
$ go run main.go -f 'command'
args: []string{"/var/folders/.../exe/main", "-f", "command"}
2018/03/18 12:07:14 argument -f needs a nonempty value
exit status 1
$ go run main.go -f "\"command\""
args: []string{"/var/folders/.../exe/main", "-f", "\"command\""} As you can see |
I'm not sure I follow you�. Surely the Os args value should strip the citations, that's not the issue. However it should not be interpreted as command as the order of arguments is different. After a flag that takes a string, it should be parsed as that string (as for all other strings), not as a subcommand. This would mean that it would be impossible to run git commit -m "log" just because git log is a command. |
In this case how can I determine whether the command line argument is a "command" or an "argument value" since os.Args values are stripped? See; # -f is an argument flag and bar is a command flag
$ go run main.go -f bar
args: []string{"/var/folders/.../exe/main", "-f", "bar"}
# -f is an argument flag and bar is an argument value
$ go run main.go -f "bar"
args: []string{"/var/folders/.../exe/main", "-f", "bar"} In both cases |
Here is another bug I found
Minimal example:
When running:
The text was updated successfully, but these errors were encountered: