{"id":28546039,"url":"https://github.com/jbasko/aarghparse","last_synced_at":"2025-10-29T04:02:41.505Z","repository":{"id":57407718,"uuid":"153998052","full_name":"jbasko/aarghparse","owner":"jbasko","description":"A collection of argparse extensions","archived":false,"fork":false,"pushed_at":"2018-11-05T14:30:22.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T17:09:48.808Z","etag":null,"topics":["argparse","cli","command-line","command-line-interface","python36","python37","subcommand","subparsers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbasko.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-21T10:51:14.000Z","updated_at":"2019-05-18T08:05:17.000Z","dependencies_parsed_at":"2022-09-26T17:10:48.589Z","dependency_job_id":null,"html_url":"https://github.com/jbasko/aarghparse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jbasko/aarghparse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbasko%2Faarghparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbasko%2Faarghparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbasko%2Faarghparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbasko%2Faarghparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbasko","download_url":"https://codeload.github.com/jbasko/aarghparse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbasko%2Faarghparse/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264018969,"owners_count":23545033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argparse","cli","command-line","command-line-interface","python36","python37","subcommand","subparsers"],"created_at":"2025-06-09T23:08:53.011Z","updated_at":"2025-10-29T04:02:36.464Z","avatar_url":"https://github.com/jbasko.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"==========\naarghparse\n==========\n\nMotivation\n----------\n\nI was having shower and this name came up.\n\nAt the moment this is a collection of `argparse`_ extensions I have written and found useful in recent times.\n\n..\n    But really I want an ``argparse``-based argument parser which is able to load plugins based on parsed arguments\n    and let those plugins define additional arguments. I have made this work for one of my clients, but it's dirty.\n\n\nFeatures\n--------\n\n* ``@arg_converter`` decorator to write simple argument value parsers without the ``argparse.Action`` boilerplate\n* ``@subcommand`` decorator to save you from all the ``add_subparsers`` and ``set_defaults(func=)``.\n* ``@cli`` decorator to generate a command-line interface.\n\n\n..\n    The dynamic loader mentioned in the Motivation_ isn't available yet.\n\n\n.. _argparse: https://docs.python.org/3/library/argparse.html\n\n\nExample\n-------\n\nThe example below combines all the features, but the tool doesn't enforce it on you.\n\nIf you have an existing ``argparse.ArgumentParser`` definition, you should be able to replace it with ``aarghparse``\nby just changing the initialisation line to ``parser = aarghparse.ArgumentParser(...)``.\n\n.. code-block:: python\n\n    import datetime as dt\n\n    import dateutil.tz\n\n    from aarghparse import ArgumentParser, arg_converter, cli\n\n\n    @cli\n    def calendar_cli(parser: ArgumentParser, subcommand: ArgumentParser.subcommand):\n        \"\"\"\n        Command-line calendar.\n        \"\"\"\n\n        parser.add_argument(\n            '--date-format',\n            default=None,\n        )\n\n        @arg_converter\n        def tz_arg(value):\n            return dateutil.tz.gettz(value)\n\n        @subcommand(\n            name=\"now\",\n            args=[\n                [\"--tz\", {\n                    \"action\": tz_arg,\n                    \"help\": \"Timezone\",\n                }],\n            ],\n        )\n        def now_cmd(args):\n            \"\"\"\n            Prints today's date.\n            \"\"\"\n            date_format = args.date_format or \"%Y-%m-%d %H:%M:%S\"\n            print(dt.datetime.now(tz=args.tz).strftime(date_format))\n\n\n    if __name__ == \"__main__\":\n        calendar_cli.run()\n\n\nIf you install ``python-dateutil`` then you can try the above with:\n\n.. code-block:: shell\n\n    python -m aarghparse.examples.calendar --help\n    python -m aarghparse.examples.calendar now --help\n    python -m aarghparse.examples.calendar now --tz \"Europe/Riga\"\n    python -m aarghparse.examples.calendar --date-format \"%d.%m.%Y.\" now --tz \"Europe/Riga\"\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbasko%2Faarghparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbasko%2Faarghparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbasko%2Faarghparse/lists"}