{"id":18068440,"url":"https://github.com/mhsiddiqui/cmd-manager","last_synced_at":"2025-04-11T23:40:59.657Z","repository":{"id":258284893,"uuid":"874416025","full_name":"mhsiddiqui/cmd-manager","owner":"mhsiddiqui","description":"A package to write management commands for FastAPI, Flask and other similar frameworks using Python Click. Inspired by Django management commands","archived":false,"fork":false,"pushed_at":"2024-10-18T06:51:49.000Z","size":25,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T20:34:55.863Z","etag":null,"topics":["fastapi","flask","management-command","starlette"],"latest_commit_sha":null,"homepage":"https://github.com/mhsiddiqui/cli-manager","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mhsiddiqui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2024-10-17T19:36:56.000Z","updated_at":"2025-02-01T19:02:53.000Z","dependencies_parsed_at":"2024-10-20T06:08:44.233Z","dependency_job_id":null,"html_url":"https://github.com/mhsiddiqui/cmd-manager","commit_stats":null,"previous_names":["mhsiddiqui/cmd-manager","mhsiddiqui/cli-manager"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhsiddiqui%2Fcmd-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhsiddiqui%2Fcmd-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhsiddiqui%2Fcmd-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhsiddiqui%2Fcmd-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhsiddiqui","download_url":"https://codeload.github.com/mhsiddiqui/cmd-manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497901,"owners_count":21113982,"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":["fastapi","flask","management-command","starlette"],"created_at":"2024-10-31T08:06:30.346Z","updated_at":"2025-04-11T23:40:59.630Z","avatar_url":"https://github.com/mhsiddiqui.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/mhsiddiqui/cmd-manager/actions/workflows/build.yml/badge.svg)](https://github.com/mhsiddiqui/cmd-manager/actions/workflows/build.yml)\n# Cli Manager\n\nA Python package that enables you to create and manage custom management commands, similar to Django's management system for FastAPI, Flask and other similar frameworks. This package uses Python's `click` to define, register, and execute commands for your application dynamically.\n\n## Features\n\n- **Dynamic Command Registration:** Automatically discover and register commands located in specific directories.\n- **Class-Based Commands:** Easily define reusable commands by subclassing `BaseCommand`.\n- **Custom Arguments:** Commands can specify their own arguments and options, which will be automatically handled by the command-line interface.\n- **Pluggable and Extendable:** Easily integrate this package with any FastAPI app or third-party package.\n\n## Installation\n\nInstall the package via `pip`:\n\n```bash\npip install cmd-manager\n```\n\n## Usage\n\n### 1. Define Your Command\n\nTo create a custom command, define a Python script in your project and subclass `BaseCommand`. Implement the `run` method to include your logic, and use `get_arguments` to specify any arguments the command will accept.\n\n```python\n# src/scripts/mycommand.py\n\nfrom cmd_manager import BaseCommand, Argument\n\nclass Command(BaseCommand):\n    def get_arguments(self):\n        return [\n            Argument('arg1', is_argument=True),\n            Argument('--n', is_argument=False, type=int),\n        ]\n\n    def run(self, *args, **kwargs):\n        print(f\"Running command with args: {args}, kwargs: {kwargs}\")\n```\n\nTo Argument class accept all the parameters which `click.Argument` and `click.Option` accept. By using `is_argument=True/False`, both type of argument can be differentiated.\n\n\n### 2. Register Commands\n\nIn your main CLI runner file, use the `ManagementCommandSystem` to register and organize all your commands dynamically. This method discovers all commands within a specified package (like `src.scripts`) and registers them.\n\n```python\n# cli_runner.py\n\nfrom cmd_manager import ManagementCommandSystem\n\n# Initialize the management command system\nmanagement_system = ManagementCommandSystem()\n\n# Register all commands in the 'src.scripts' package\nmanagement_system.register(package='src.scripts')\n\n# Create the Click CLI group\ncli = management_system.create_cli()\n\nif __name__ == '__main__':\n    cli()\n```\n\nThis code sets up the command system and links the command logic to a FastAPI instance. All commands from the specified package (`src.scripts`) will automatically become available as CLI commands.\n\n### 3. Run Commands\n\nOnce your commands are registered, you can run them using the CLI:\n\n```bash\npython cli_runner.py mycommand arg1_value --arg2 123\n```\n\nIn this case, `mycommand` is the command name, and `arg1_value` and `--arg2 123` are the arguments passed to the command.\n\n### 4. Using Management Commands from External Packages\n\nIf you have installed another FastAPI package with its own set of management commands, you can also register those commands in your CLI by specifying the package name.\n\n```python\nmanagement_system.register(package='external_package.scripts')\n```\n\nTo avoid command name conflicts between multiple packages, you can apply a prefix:\n\n```python\nmanagement_system.register(prefix='ext-', package='external_package.scripts')\n```\n\nThis way, all commands from `external_package` will be prefixed with `ext-`, avoiding any conflicts with similarly named commands in your project.\n\nHere’s another example where you define a simple `greet` command:\n\n### Example\n\nExample can be seen in example folder. This example can be run by running following command\n\n```bash\npython example_runner.py whats_my_name\n```\n\n## Authors\n[@mhsiddiqui](https://github.com/mhsiddiqui)\n\n## Contributing\nContributions are always welcome!\n\nPlease read contributing.md to get familiar how to get started.\n\nPlease adhere to the project's code of conduct.\n\nFeedback And Support\nPlease open an issue and follow the template, so the community can help you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhsiddiqui%2Fcmd-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhsiddiqui%2Fcmd-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhsiddiqui%2Fcmd-manager/lists"}