Title: [bug] short flags/arguments does not work with `**kwargs` · Issue #454 · google/python-fire · GitHub
Open Graph Title: [bug] short flags/arguments does not work with `**kwargs` · Issue #454 · google/python-fire
X Title: [bug] short flags/arguments does not work with `**kwargs` · Issue #454 · google/python-fire
Description: Description: Short flags/arguments (e.g. -u for --username) does not work with **kwargs Example that works OK: The following example works ok: import fire def cli(first_arg="left", second_arg="right"): """Prints the 2 arguments separated...
Open Graph Description: Description: Short flags/arguments (e.g. -u for --username) does not work with **kwargs Example that works OK: The following example works ok: import fire def cli(first_arg="left", second_arg="righ...
X Description: Description: Short flags/arguments (e.g. -u for --username) does not work with **kwargs Example that works OK: The following example works ok: import fire def cli(first_arg="left", second...
Opengraph URL: https://github.com/google/python-fire/issues/454
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[bug] short flags/arguments does not work with `**kwargs`","articleBody":"# Description:\r\n\r\nShort flags/arguments (e.g. `-u` for `--username`) does not work with `**kwargs`\r\n\r\n# Example that works OK:\r\n\r\nThe following example works ok:\r\n\r\n```python\r\nimport fire\r\n\r\ndef cli(first_arg=\"left\", second_arg=\"right\"):\r\n \"\"\"Prints the 2 arguments separated by bar\r\n \r\n Parameters\r\n ----------\r\n first_arg : str\r\n the first arg\r\n second_arg : str\r\n the second arg\r\n \"\"\"\r\n print(f\"{first_arg} | {second_arg}\" )\r\n\r\nif __name__ == '__main__':\r\n fire.Fire(cli)\r\n```\r\n## Help output\r\n```sh\r\n❯ python .\\example.py -- --help\r\nNAME\r\n example.py - Prints the 2 arguments separated by bar\r\n\r\nSYNOPSIS\r\n example.py \u003cflags\u003e\r\n\r\nDESCRIPTION\r\n Prints the 2 arguments separated by bar\r\n\r\nFLAGS\r\n -f, --first_arg=FIRST_ARG\r\n Default: 'left'\r\n the first arg\r\n -s, --second_arg=SECOND_ARG\r\n Default: 'right'\r\n the second arg\r\n```\r\n## Usage with short flags\r\n```sh\r\n❯ python .\\example.py -f=\"hello\" -s=\"word\"\r\nhello | word\r\n```\r\n# Example that does not work:\r\n\r\nThe following next example does not work with short flags, **even when they are showing on the help output**.\r\nIt is using `**kwargs`. It seems the short flags are going to the `**kwargs` dictionary.\r\n\r\n```python\r\nimport fire\r\n\r\ndef cli(first_arg=\"left\", second_arg=\"right\", **kwargs):\r\n \"\"\"Prints the 2 arguments separated by bar\r\n \r\n Parameters\r\n ----------\r\n first_arg : str\r\n the first arg\r\n second_arg : str\r\n the second arg\r\n kwargs : str\r\n additional args\r\n \"\"\"\r\n print(f\"{first_arg} | {second_arg}\" )\r\n print(kwargs)\r\n\r\nif __name__ == '__main__':\r\n fire.Fire(cli)\r\n```\r\n## Help output\r\n```sh\r\n❯ python .\\example2.py -- --help\r\nNAME\r\n example2.py - Prints the 2 arguments separated by bar\r\n\r\nSYNOPSIS\r\n example2.py \u003cflags\u003e\r\n\r\nDESCRIPTION\r\n Prints the 2 arguments separated by bar\r\n\r\nFLAGS\r\n -f, --first_arg=FIRST_ARG\r\n Default: 'left'\r\n the first arg\r\n -s, --second_arg=SECOND_ARG\r\n Default: 'right'\r\n the second arg\r\n Additional flags are accepted.\r\n additional args\r\n```\r\n## Usage with short flags\r\n```sh\r\n❯ python .\\example2.py -f=\"hello\" -s=\"word\"\r\nleft | right\r\n{'f': 'hello', 's': 'word'}\r\n```\r\nIn summary: the `-f` and `-s` arguments should be parsing to `--first_arg` and `--second_arg` but they are parsing to `kwargs`","author":{"url":"https://github.com/diogo-rossi","@type":"Person","name":"diogo-rossi"},"datePublished":"2023-05-10T02:58:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/454/python-fire/issues/454"}
| 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:872f6387-9e32-7815-d687-c80ccb49cd80 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5F8:35FB06:8CFBD9:C1605B:6A4DB7F4 |
| html-safe-nonce | aa48ad8ad41f28d65639930a2a4cb72a430162ec42323f317563b05d3952d0df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUY4OjM1RkIwNjo4Q0ZCRDk6QzE2MDVCOjZBNERCN0Y0IiwidmlzaXRvcl9pZCI6Ijc2MjQyMjc1MjY3NDM1Mzc2NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e5510e575e5cfaa4e9ad131a97dfb71f248630b379d73ac63f358c80b14091d5 |
| hovercard-subject-tag | issue:1703035220 |
| 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/454/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b5fdfbe820ebb43e38f51dd9598a63351e29d3ccb9012b128237673e2f404164/google/python-fire/issues/454 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b5fdfbe820ebb43e38f51dd9598a63351e29d3ccb9012b128237673e2f404164/google/python-fire/issues/454 |
| og:image:alt | Description: Short flags/arguments (e.g. -u for --username) does not work with **kwargs Example that works OK: The following example works ok: import fire def cli(first_arg="left", second_arg="righ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | diogo-rossi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| 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 | 32f7b614aca06e6bbd89842b1370df1328264f68 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width