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

[BUG] v1.4.0 args does not happened when subcommand exists #115

Open
naughtyGitCat opened this issue Nov 18, 2022 · 0 comments
Open

[BUG] v1.4.0 args does not happened when subcommand exists #115

naughtyGitCat opened this issue Nov 18, 2022 · 0 comments
Assignees
Labels

Comments

@naughtyGitCat
Copy link

naughtyGitCat commented Nov 18, 2022

var cmdRootParser = argparse.NewParser("crank", "cli")
var debugFlag = cmdRootParser.Flag("", "debug", &argparse.Options{Default: false})
var versionFlag = cmdRootParser.Flag("", "version", &argparse.Options{})

var updateCmd = cmdRootParser.NewCommand("update", "update self")
var showCmd = cmdRootParser.NewCommand("show", "show some thing")
var listCmd = cmdRootParser.NewCommand("list", "list some thing")
var eventCmd = cmdRootParser.NewCommand("event", "do with event")

func main() {
	var err = cmdRootParser.Parse(os.Args)
	if err != nil {
		fmt.Println(cmdRootParser.Usage(err))
		return
	}

	if *debugFlag {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.InfoLevel)
	}

	if *versionFlag {
		log.Infof("current version: %s\n", Version)
		log.Infof("git tag: %s\n", GitTag)
		log.Infof("build time: %s\n", BuildTime)
		log.Infof("go version: %s\n", GoVersion)
		log.Infof("commit hash: %s\n", CommitHash)
		return
	}
.....

raises

 ./crank --version
[sub]Command required
usage: crank <Command> [-h|--help] [--debug] [--version]

             sensor cli

Commands:

  update  update self
  show    show some thing
  list    list some thing
  event   do with event

Arguments:

  -h  --help     Print help information
      --debug
      --version


v1.3.1 will not occur this circumstance
v1.4.0 will occur this circumstance

when fmt.Println(os.Args) it turnout [./crank --version]

@akamensky akamensky added the bug label Nov 18, 2022
@vsachs vsachs self-assigned this May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants