{"id":19846093,"url":"https://github.com/g4-api/command-bridge","last_synced_at":"2026-02-10T21:32:19.926Z","repository":{"id":242777541,"uuid":"810294121","full_name":"g4-api/command-bridge","owner":"g4-api","description":"A robust and versatile command-line utility framework designed to simplify the creation and management of command-line applications. With its powerful parameter handling and seamless command invocation, CommandBridge allows developers to build intuitive and efficient command-line tools effortlessly.","archived":false,"fork":false,"pushed_at":"2025-02-26T16:56:46.000Z","size":828,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-29T16:16:52.719Z","etag":null,"topics":["cli-framework","cli-utility","command-line","csharp","dotnet"],"latest_commit_sha":null,"homepage":"https://github.com/g4-api/command-bridge","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/g4-api.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"zenodo":null}},"created_at":"2024-06-04T12:17:27.000Z","updated_at":"2025-02-26T16:55:04.000Z","dependencies_parsed_at":"2025-04-13T01:43:52.974Z","dependency_job_id":"25a977a0-94f6-490d-9bfc-679798183d16","html_url":"https://github.com/g4-api/command-bridge","commit_stats":null,"previous_names":["g4-api/command-bridge"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/g4-api/command-bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4-api%2Fcommand-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4-api%2Fcommand-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4-api%2Fcommand-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4-api%2Fcommand-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/g4-api","download_url":"https://codeload.github.com/g4-api/command-bridge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/g4-api%2Fcommand-bridge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29317956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T20:44:44.282Z","status":"ssl_error","status_checked_at":"2026-02-10T20:44:43.393Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cli-framework","cli-utility","command-line","csharp","dotnet"],"created_at":"2024-11-12T13:10:24.969Z","updated_at":"2026-02-10T21:32:19.879Z","avatar_url":"https://github.com/g4-api.png","language":"C#","readme":"# CommandBridge\n\n[![Build, Test \u0026 Release](https://github.com/g4-api/command-bridge/actions/workflows/GithubActions.yml/badge.svg)](https://github.com/g4-api/command-bridge/actions/workflows/GithubActions.yml)\n\nCommandBridge is a versatile and powerful command-line utility framework for .NET, designed to simplify the creation, management, and execution of command-line commands and their associated parameters. This framework provides a structured and extensible way to handle complex command-line interfaces with ease.\n\n## Features\n\n- Simple and intuitive API for defining commands and parameters.\n- Automatic handling of global options like `help`.\n- Extensible base class for creating custom commands.\n- Comprehensive error handling and validation.\n- Easy integration with existing .NET applications.\n- Supports short and long forms of command parameters.\n- Seamless `--help` or `-h` switches to display command help.\n\n## Installation\n\nCommandBridge is available as a NuGet package. You can install it using the NuGet Package Manager or the .NET CLI.\n\n### NuGet Package Manager\n\n```sh\nInstall-Package CommandBridge\n```\n\n### .NET CLI\n\n```sh\ndotnet add package CommandBridge\n```\n\n## Quick Start\n\nHere's a quick example to get you started with CommandBridge.\n\n1. Create a new console application:\n\n```sh\ndotnet new console -n CommandBridgeExample\ncd CommandBridgeExample\n```\n\n2. Install the CommandBridge NuGet package:\n\n```sh\ndotnet add package CommandBridge\n```\n\n3. Define a custom command by inheriting from `CommandBase`:\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing CommandBridge;\n\nnamespace CommandBridgeExample\n{\n    [Command(name: \"greet\", description: \"Greets the user with a message.\")]\n    public class GreetCommand : CommandBase\n    {\n        private static readonly Dictionary\u003cstring, IDictionary\u003cstring, CommandData\u003e\u003e s_commands = new()\n        {\n            [\"greet\"] = new Dictionary\u003cstring, CommandData\u003e(StringComparer.Ordinal)\n            {\n                { \"n\", new() { Name = \"name\", Description = \"The name of the user.\", Mandatory = true } }\n            }\n        };\n\n        public GreetCommand() : base(s_commands) { }\n\n        protected override void OnInvoke(Dictionary\u003cstring, string\u003e parameters)\n        {\n            var name = parameters[\"name\"];\n            Console.WriteLine($\"Hello, {name}!\");\n        }\n    }\n\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            var command = CommandBase.FindCommand(args);\n            command?.Invoke(args);\n        }\n    }\n}\n```\n\n4. Run your application:\n\n```sh\ndotnet run greet -n John\n```\n\nYou should see the output:\n\n```\nHello, John!\n```\n\n## Tutorial\n\n### Step 1: Define Your Commands\n\nTo create a new command, you need to create a class that inherits from `CommandBase` and use the `Command` attribute to specify the command name and description. The commands dictionary supports both short and long forms of the command parameters.\n\n```csharp\nusing CommandBridge;\n\n[Command(name: \"mycommand\", description: \"This is my custom command.\")]\npublic class MyCommand : CommandBase\n{\n    private static readonly Dictionary\u003cstring, IDictionary\u003cstring, CommandData\u003e\u003e s_commands = new()\n    {\n        [\"mycommand\"] = new Dictionary\u003cstring, CommandData\u003e(StringComparer.Ordinal)\n        {\n            { \"p1\", new() { Name = \"Parameter1\", Description = \"Description for parameter 1.\", Mandatory = true } },\n            { \"p2\", new() { Name = \"Parameter2\", Description = \"Description for parameter 2.\", Mandatory = false } }\n        }\n    };\n\n    public MyCommand() : base(s_commands) { }\n\n    protected override void OnInvoke(Dictionary\u003cstring, string\u003e parameters)\n    {\n        // Implement your command logic here\n    }\n}\n```\n\n### Step 2: Implement Command Logic\n\nOverride the `OnInvoke` method to define the behavior of your command.\n\n```csharp\nprotected override void OnInvoke(Dictionary\u003cstring, string\u003e parameters)\n{\n    var param1 = parameters[\"Parameter1\"];\n    var param2 = parameters.ContainsKey(\"Parameter2\") ? parameters[\"Parameter2\"] : \"default value\";\n\n    Console.WriteLine($\"Parameter 1: {param1}\");\n    Console.WriteLine($\"Parameter 2: {param2}\");\n}\n```\n\n### Step 3: Execute Commands\n\nIn your `Main` method, use the `FindCommand` method to locate and execute the appropriate command based on the provided arguments.\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        var command = CommandBase.FindCommand(args);\n        command?.Invoke(args);\n    }\n}\n```\n\n### Step 4: Display Help Information\n\nCommandBridge automatically handles global options like `help`. You can trigger it by passing `--help` or `-h` as an argument.\n\n```sh\ndotnet run mycommand --help\n```\n\n## Basic Implementation\n\nHere's a complete example demonstrating the creation and usage of a simple command with both short and long forms of parameters.\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing CommandBridge;\n\nnamespace CommandBridgeExample\n{\n    [Command(name: \"deploy\", description: \"Deploys an application to the specified environment.\")]\n    public class DeployCommand : CommandBase\n    {\n        private static readonly Dictionary\u003cstring, IDictionary\u003cstring, CommandData\u003e\u003e s_commands = new()\n        {\n            [\"deploy\"] = new Dictionary\u003cstring, CommandData\u003e(StringComparer.Ordinal)\n            {\n                { \"e\", new() { Name = \"env\", Description = \"Specifies the target environment (e.g., production, staging).\", Mandatory = true } },\n                { \"v\", new() { Name = \"version\", Description = \"Specifies the version of the application to deploy.\", Mandatory = true } },\n                { \"c\", new() { Name = \"config\", Description = \"Path to the configuration file.\" } },\n                { \"f\", new() { Name = \"force\", Description = \"Force deploy without confirmation.\", Type = \"Switch\" } }\n            }\n        };\n\n        public DeployCommand() : base(s_commands) { }\n\n        protected override void OnInvoke(Dictionary\u003cstring, string\u003e parameters)\n        {\n            var env = parameters[\"env\"];\n            var version = parameters[\"version\"];\n            var config = parameters.ContainsKey(\"config\") ? parameters[\"config\"] : \"default-config.yml\";\n            var force = parameters.ContainsKey(\"force\");\n\n            Console.WriteLine($\"Deploying version {version} to {env} environment.\");\n            Console.WriteLine($\"Using configuration file: {config}\");\n            if (force)\n            {\n                Console.WriteLine(\"Force deploy enabled.\");\n            }\n        }\n    }\n\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            var command = CommandBase.FindCommand(args);\n            command?.Invoke(args);\n        }\n    }\n}\n```\n\nTo run the example:\n\n```sh\ndotnet run deploy -e production -v 1.0.0 -c config.yml -f\n```\n\nYou should see the output:\n\n```\nDeploying version 1.0.0 to production environment.\nUsing configuration file: config.yml\nForce deploy enabled.\n```\n\n## Contributing\n\nWe welcome contributions to CommandBridge! If you find a bug or have a feature request, please open an issue on our GitHub repository. If you'd like to contribute code, feel free to fork the repository and submit a pull request.\n\n## License\n\nCommandBridge is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n\n---\n\nCommandBridge is designed to make building command-line interfaces in .NET simple and efficient. We hope you find it useful and look forward to your feedback and contributions.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg4-api%2Fcommand-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fg4-api%2Fcommand-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fg4-api%2Fcommand-bridge/lists"}