You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parser:=argparse.NewParser("...", "...")
verbose:=parser.FlagCounter("v", "verbose", &argparse.Options{})
hosts:=parser.StringList("", "host", &argparse.Options{Required: true})
username:=parser.String("u", "user", &argparse.Options{Required: true})
password:=parser.String("p", "password", &argparse.Options{Required: true})
// preset cmdpresetCmd:=parser.NewCommand("preset", "Get and modify radio presets")
// get preset cmdgetPresetCmd:=presetCmd.NewCommand("get", "Get the current radio preset")
// set preset cmdsetPresetCmd:=presetCmd.NewCommand("set", "Set the current radio preset")
setPresetID:=setPresetCmd.Int("", "id", &argparse.Options{Required: true})
// user cmduserCmd:=parser.NewCommand("user", "User")
getUserCmd:=userCmd.NewCommand("get", "Get all users")
err:=parser.Parse(os.Args)
iferr!=nil {
fmt.Println(parser.Usage(err))
return
}
When I start this with no arguments, I get the expected error message [sub]Command required.
When I start the program with just hosts, username and password, the subcommand is suddenly not needed.
EDIT: After reviewing your example code, the advanced-command example has the exact same bug. Start the example with just the --name argument and you reach
// This should be unreachable
log.Fatal("Uh-oh, something weird happened")
The text was updated successfully, but these errors were encountered:
package main
import (
"fmt""github.com/akamensky/argparse""os"
)
funcmain() {
parser:=argparse.NewParser("...", "...")
_=parser.FlagCounter("v", "verbose", &argparse.Options{})
_=parser.StringList("", "host", &argparse.Options{Required: true})
_=parser.String("u", "user", &argparse.Options{Required: true})
_=parser.String("p", "password", &argparse.Options{Required: true})
// preset cmdpresetCmd:=parser.NewCommand("preset", "Get and modify radio presets")
// get preset cmd_=presetCmd.NewCommand("get", "Get the current radio preset")
// set preset cmdsetPresetCmd:=presetCmd.NewCommand("set", "Set the current radio preset")
_=setPresetCmd.Int("", "id", &argparse.Options{Required: true})
// user cmduserCmd:=parser.NewCommand("user", "User")
_=userCmd.NewCommand("get", "Get all users")
err:=parser.Parse(os.Args)
iferr!=nil {
fmt.Println(parser.Usage(err))
return
}
}
Test cases:
$ go run main.go --host host # Fail, should report that sub command is required, but reports that `user` is required
$ go run main.go --host host -u user # Fail, should report that sub command is required, but reports that `password` is required
Hello, I have following code
When I start this with no arguments, I get the expected error message [sub]Command required.
When I start the program with just hosts, username and password, the subcommand is suddenly not needed.
EDIT: After reviewing your example code, the advanced-command example has the exact same bug. Start the example with just the --name argument and you reach
The text was updated successfully, but these errors were encountered: