Title: Allow choices restriction · Issue #384 · google/python-fire · GitHub
Open Graph Title: Allow choices restriction · Issue #384 · google/python-fire
X Title: Allow choices restriction · Issue #384 · google/python-fire
Description: Hello, and thank you for this great CLI! Recently I get to a situation when I would like to restrict the options for a given argument similar to build-in argparse does with its option choices (see docs: https://docs.python.org/3/library/...
Open Graph Description: Hello, and thank you for this great CLI! Recently I get to a situation when I would like to restrict the options for a given argument similar to build-in argparse does with its option choices (see ...
X Description: Hello, and thank you for this great CLI! Recently I get to a situation when I would like to restrict the options for a given argument similar to build-in argparse does with its option choices (see ...
Opengraph URL: https://github.com/google/python-fire/issues/384
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow choices restriction","articleBody":"Hello, and thank you for this great CLI!\r\nRecently I get to a situation when I would like to restrict the options for a given argument similar to build-in `argparse` does with its option `choices` (see docs: https://docs.python.org/3/library/argparse.html#choices). Then I was checking Fire docs but could not find anything similar to it...\r\nChecking alternative CLI packages I found a way that is quite simple but still elegant and would well fit the Fire style. It is leveraging python `Enum` class:\r\n```py\r\nfrom enum import Enum\r\nimport fire\r\n\r\nclass Direction(str, Enum):\r\n up = \"up\"\r\n down = \"down\"\r\n left = \"left\"\r\n right = \"right\"\r\n\r\n\r\ndef main(move: Direction = Direction.left):\r\n print(f\"Moving in given direction: {move.value}\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n fire.Fire(main)\r\n```\r\nFor clarification, the example above is borrowed and adjusted from [Typer/enum](https://typer.tiangolo.com/tutorial/parameter-types/enum/)","author":{"url":"https://github.com/Borda","@type":"Person","name":"Borda"},"datePublished":"2022-02-08T22:25:00Z","url":"https://github.com/google/python-fire/issues/384"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:71ca23b9-b887-2dbb-7c5f-677f972d3418 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E83A:73851:6DD445:980E80:6B002101 |
| html-safe-nonce | fabd1047489c30db0482a7d6b42ffeac46a9cdb5baf0ecd1c8fb916de06e718b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODNBOjczODUxOjZERDQ0NTo5ODBFODA6NkIwMDIxMDEiLCJ2aXNpdG9yX2lkIjoiODQ4MTIwNzY1OTkwNTY4NzgwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1c49f4b330e816203cec16370aba933ab83df7349b6ebfca4694837a318e5f9c |
| hovercard-subject-tag | issue:1127823009 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/google/python-fire/384/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b190e2cb3e5d7ac587cb1faa624ed27d742d8e86fe6f1f211d8bee417c2f6ea9/google/python-fire/issues/384 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b190e2cb3e5d7ac587cb1faa624ed27d742d8e86fe6f1f211d8bee417c2f6ea9/google/python-fire/issues/384 |
| og:image:alt | Hello, and thank you for this great CLI! Recently I get to a situation when I would like to restrict the options for a given argument similar to build-in argparse does with its option choices (see ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Borda |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/google/python-fire git https://github.com/google/python-fire.git |
| octolytics-dimension-user_id | 1342004 |
| octolytics-dimension-user_login | |
| octolytics-dimension-repository_id | 82729529 |
| octolytics-dimension-repository_nwo | google/python-fire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 82729529 |
| octolytics-dimension-repository_network_root_nwo | google/python-fire |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width