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

feature request: support "count" action #102

Open
Spectre5 opened this issue Jan 22, 2022 · 2 comments
Open

feature request: support "count" action #102

Spectre5 opened this issue Jan 22, 2022 · 2 comments

Comments

@Spectre5
Copy link
Contributor

I'd like to be able to use the argparase "count" action. A common use for this is something like program -v to enable verbose message and then program -vv or program -v -v to increase the verbosity.

Is there a simple way to achieve this with a custom parser? It wouldn't actually accept a string, so maybe not. I have no tried that though.

I suppose this could use the same solution as proposed in #95. I've added another comment there.

@Spectre5 Spectre5 changed the title feature request: support "count" feature request: support "count" action Jan 22, 2022
@anntzer
Copy link
Owner

anntzer commented Jan 22, 2022

I don't think this is possible right now. Something like #95 is perhaps possible. Alternatively I thought that we may be able to introduce a type alias like defopt.Count = int and special-case those, but type aliases don't exist at runtime; or a NewType (defopt.Count = NewType("Count", int)) but I think that would prevent (from a mypy PoV) from directly calling the function with an int, which may or may not be a problem?

@Spectre5
Copy link
Contributor Author

Spectre5 commented Jan 22, 2022

Ya, I had considered some sort of custom type too, but I had the same concern with mypy. Perhaps a solution could be found in a union type with a custom one (considered first) or an int (i.e. Union[CustomInt, int]). With that said, at this point we're changing the function anyway and then the solution in #95 is better and could cover this use case.

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

2 participants