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

Enable option to disable/enable check for non-zero values during Bind #55

Open
morganhein opened this issue Mar 23, 2018 · 4 comments
Open

Comments

@morganhein
Copy link

morganhein commented Mar 23, 2018

It would be great if it was possible to disable the non-zero check during a bind, so that we can pre-populate certain values and allow for DocOpt to over-ride when necessary.

My use case is i'm using another library to first parse environment variables, and would like program arguments to over-ride when necessary.

Maybe this logic would break other things, so if there's a better suggestion to combine Environment variables with DocOpt i'd love to hear them!

@Kagami
Copy link

Kagami commented May 2, 2018

Have same issue, want to override options parsed from config. Now I have to create two structs and merge them with some additional code.

The simplest solution is probably to fork docopt.go repo and remove that check. It doesn't seems to update too often anyway.

@KalleDK
Copy link

KalleDK commented May 18, 2020

I use a "hack" where i populate the default values before parsing, this is of course not so clean, but works great for defaults when these are OS specific

defaultConfFile := pathlib.Join(confDir, "naval.conf")

usageTemplate := `Naval
.....
Options:
  -c <path>  Config path [default: %s].
....`

usage := fmt.Sprintf(usageTemplate, defaultConfFile)

opts, err := docopt.ParseDoc(usage)
...

@Kagami
Copy link

Kagami commented May 18, 2020

Interesting. Sprintf is a bit clunky though, you have to list every option you have in config struct, in correct order. This could be error-prone.

@KalleDK
Copy link

KalleDK commented May 18, 2020

Interesting. Sprintf is a bit clunky though, you have to list every option you have in config struct, in correct order. This could be error-prone.

You could use whatever template engine you want :) But as my os specific often only is one or two Sprintf is fine.

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

No branches or pull requests

3 participants