{"id":22870293,"url":"https://github.com/berquerant/pkommand","last_synced_at":"2025-03-31T11:26:11.059Z","repository":{"id":81890014,"uuid":"357612557","full_name":"berquerant/pkommand","owner":"berquerant","description":"small subcommand library","archived":false,"fork":false,"pushed_at":"2024-04-08T09:37:06.000Z","size":336,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-08T10:50:52.068Z","etag":null,"topics":["python"],"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/berquerant.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-04-13T16:03:19.000Z","updated_at":"2024-04-15T10:34:02.735Z","dependencies_parsed_at":"2024-04-15T10:33:59.662Z","dependency_job_id":"907bbf50-5c24-4f2d-b27e-7937d492442c","html_url":"https://github.com/berquerant/pkommand","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berquerant%2Fpkommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berquerant%2Fpkommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berquerant%2Fpkommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berquerant%2Fpkommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/berquerant","download_url":"https://codeload.github.com/berquerant/pkommand/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246460314,"owners_count":20781090,"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":["python"],"created_at":"2024-12-13T13:14:25.876Z","updated_at":"2025-03-31T11:26:11.033Z","avatar_url":"https://github.com/berquerant.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pkommand\n\npkommand is a small subcommand parser library.\n\n## Class-based\n\n``` python\nimport pkommand\n\n\nclass Scan(pkommand.Command):\n    @staticmethod\n    def name():\n        return \"scan\"\n\n    @classmethod\n    def help(cls):\n        return \"do scan\"\n\n    def run(self, args):\n        print(\"run scan {}\".format(args.table))\n\n    @classmethod\n    def register(cls, _):\n        pass\n\n\nclass Query(pkommand.Command):\n    @staticmethod\n    def name():\n        return \"query\"\n\n    @classmethod\n    def help(cls):\n        return \"do query\"\n\n    def run(self, args):\n        print(\"run query {} by {}\".format(args.table, args.key))\n\n    @classmethod\n    def register(cls, parser):\n        parser.add_argument(\"--key\", action=\"store\", type=str)\n\n\np = pkommand.Parser(\"cli\")\np.add_argument(\"--table\", action=\"store\", type=str)\np.add_command_class(Scan)\np.add_command_class(Query)\np.run()\n```\n\nRun like this:\n\n``` shell\n% python example.py --table histories scan\nrun scan histories\n% python example.py --table histories query --key 1984\nrun query histories by 1984\n```\n\n## Function-based\n\n``` python\nfrom pkommand import Parser, Wrapper\n\n\ndef scan(table: str):\n    \"\"\"do scan\"\"\"\n    print(f\"run scan {table}\")\n\n\ndef query(table: str, key: str):\n    \"\"\"do query\"\"\"\n    print(f\"run query {table} by {key}\")\n\n\nw = Wrapper(Parser(\"cli\"))\nw.add(scan)\nw.add(query)\nw.run()\n```\n\nRun like this:\n\n``` shell\n❯ python exmaple.py scan --table histories\nrun scan histories\n❯ python example.py query --table histories --key 1984\nrun query histories by 1984\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberquerant%2Fpkommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fberquerant%2Fpkommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberquerant%2Fpkommand/lists"}