Created
January 11, 2021 16:31
-
-
Save mcaselli/4b09a1e7476db4c92e90e2eb17813fa7 to your computer and use it in GitHub Desktop.
Optionally override an variable boolean default with plac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import distutils.util | |
import plac | |
VIEW_DEFAULT = False | |
@plac.opt( | |
"view", | |
help="show something", | |
type=str, | |
choices=["True", "False", "true", "false"] | |
) | |
def main(view=VIEW_DEFAULT): | |
"""a simple application | |
if the user provides the `view` argument, its value will override the default, | |
which might itself be configured in some kind of config file | |
""" | |
print(f"VIEW_DEFAULT: {VIEW_DEFAULT}") | |
if isinstance(view, str): | |
view = bool(distutils.util.strtobool(view)) | |
print(f"view: {view}") | |
if __name__ == "__main__": | |
plac.call(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment