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

Distinguish between blank string flag and absence of flag #239

Closed
Gerg opened this issue Jun 10, 2015 · 4 comments
Closed

Distinguish between blank string flag and absence of flag #239

Gerg opened this issue Jun 10, 2015 · 4 comments

Comments

@Gerg
Copy link

Gerg commented Jun 10, 2015

Feature Request

It would be useful if there was a way to distinguish between passing a string flag a blank string (command -f "") and the absence of the flag (command).

Currently both will return "" from c.String("f")

Our use case:

We have a command to update a resource via an API. Fields that can be updated are represented by different CLI flags. One of the fields on the resource is a string that can be blank. We would like users to be able to set the field to the blank string.

#Setting the field to non-blank string
command -f "string"

#Setting the field to blank string
command -f ""

To do this currently we have to have another flag to reset the field.

command --clear-field

This is annoying because it means we have two flags for a single field and have to handle cases where both flags are passed.

Thanks!

@jszwedko
Copy link
Contributor

@Gerg you should be able to utilize c.IsSet and c.GlobalIsSet for this -- let me know if that helps.

@Gerg
Copy link
Author

Gerg commented Jun 11, 2015

That is exactly what I'm looking for! Thanks 🎉

@Gerg Gerg closed this as completed Jun 11, 2015
@feliksik
Copy link

feliksik commented Nov 5, 2015

c.IsSet() requires you to manually check this and generate an appropiate error message; would it make sense to delegate this to the parser as well, by setting a { Required = true } field in the generator struct of the Flag?

@jszwedko
Copy link
Contributor

@feliksik there has been some talk about required flags, you can see #155 for the latest. Help wanted to take that over the finish line.

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