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

Options.Default should be ignored for Flag #98

Closed
jasonwee opened this issue Apr 20, 2022 · 4 comments · Fixed by #99
Closed

Options.Default should be ignored for Flag #98

jasonwee opened this issue Apr 20, 2022 · 4 comments · Fixed by #99

Comments

@jasonwee
Copy link

jasonwee commented Apr 20, 2022

package main

import (
	"fmt"
	"github.com/akamensky/argparse"
	"os"
)

func main() {
   parser := argparse.NewParser("accounts", "Prints provided string to stdout")
   noTest := parser.Flag("n", "no-test", &argparse.Options{Help: "boolean true/false", Default: true})

   err := parser.Parse(os.Args)
   if err != nil {
      fmt.Print(parser.Usage(err))
   }
   fmt.Println(*noTest)
}

why is this always true? the second should be false?

$ go run main.go 
true
$ go run main.go -n
true
$
@akamensky
Copy link
Owner

akamensky commented Apr 20, 2022

Using Options.Default with Flag doesn't make much sense.

If flag is not provided it is false (default boolean value), if provided it is true.

Setting default to true makes it to be always true.

I agree it can be improved by simply ignoring Options.Default for Flag.

@akamensky akamensky changed the title why flag is always true? Setting Options.Default for Flag to true causes it to always be true Apr 20, 2022
@jasonwee
Copy link
Author

Thanks for considering

@akamensky akamensky changed the title Setting Options.Default for Flag to true causes it to always be true Options.Default should be ignored for Flag Apr 20, 2022
@akamensky
Copy link
Owner

Resolved in #103

@jasonwee
Copy link
Author

will upgrade and test this feature, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants