{"id":17449729,"url":"https://github.com/bolner/concontroller","last_synced_at":"2025-04-02T22:25:45.158Z","repository":{"id":148174519,"uuid":"234938179","full_name":"bolner/ConController","owner":"bolner","description":"Controller library for console applications.","archived":false,"fork":false,"pushed_at":"2020-03-12T12:29:43.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T12:46:59.848Z","etag":null,"topics":["cli","console","controller","dotnet-core","parameters","parser"],"latest_commit_sha":null,"homepage":null,"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/bolner.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}},"created_at":"2020-01-19T17:32:18.000Z","updated_at":"2023-02-17T00:00:13.000Z","dependencies_parsed_at":"2023-05-19T09:00:22.920Z","dependency_job_id":null,"html_url":"https://github.com/bolner/ConController","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolner%2FConController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolner%2FConController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolner%2FConController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bolner%2FConController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bolner","download_url":"https://codeload.github.com/bolner/ConController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246901452,"owners_count":20852221,"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":["cli","console","controller","dotnet-core","parameters","parser"],"created_at":"2024-10-17T21:49:20.978Z","updated_at":"2025-04-02T22:25:45.123Z","avatar_url":"https://github.com/bolner.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"ConController\n=============\n\nController library for console applications. You can place the controllers in multiple files / classes, which is ideal for bigger projects. Parameters are converted automatically to the proper types.\n\nNotes:\n- As you'll see in the next examples, the first operand tells, which method to call:\n  - [controller name]/[entry point name]\n- Each method has to be static, but you can freely choose between sync and async modes of operation.\n- All controller classes must extend the `ControllerBase`, because they are identified this way. (You don't have to implement any interface, no worries.)\n\n# NuGet package\n\nAvailable at: https://www.nuget.org/packages/ConController\n\nTo include it in a `.NET Core` project:\n\n```shell\n$ dotnet add package ConController\n```\n\n# Example 1: sync with obligatory parameters\n\n```csharp\n[Controller(Name = \"test\", Description = \"For development purposes\")]\npublic class TestController : ControllerBase {\n    [EntryPoint(Name = \"mult\", Description = \"Multiply two numbers\")]\n    [Parameter(Name = \"left\", Optional = false, Description = \"First number\")]\n    [Parameter(Name = \"right\", Optional = false, Description = \"Second number\")]\n    public static void Multiply(double left, double right) {\n        Console.WriteLine($\"\\n {left} x {right} = {left * right}\\n\");\n    }\n}\n```\n\n```shell\n$ dotnet run test/mult left=34.5 right=2\n\n34.5 x 2 = 69\n```\n\nYou can use classic parameter syntax with double dash:\n\n```shell\n$ dotnet run test/mult --left=34.5 --right=2\n\n34.5 x 2 = 69\n```\n\n# Example 2: async with optional parameter\n\n```csharp\n[Controller(Name = \"test\", Description = \"For development purposes\")]\npublic class TestController : ControllerBase {\n    [EntryPoint(Name = \"out\", Description = \"Output text\")]\n    [Parameter(Name = \"text\", Optional = false, Description = \"Text to output\")]\n    [Parameter(Name = \"repeat\", Optional = true, Description = \"How many times to repeat the text.\")]\n    public static async Task Output(string text, int repeat = 3) {\n        for(int i = 0; i \u003c repeat; i++) {\n            await Console.Out.WriteLineAsync(text);\n        }\n    }\n}\n```\n\n```shell\n$ dotnet run test/out text=\"This is a text\" fileName=output.txt\n\nThis is a text\nThis is a text\nThis is a text\n```\n\nYou can use classic parameter syntax with double dash:\n\n```shell\n$ dotnet run test/out --text=\"This is a text\" --fileName=output.txt\n\nThis is a text\nThis is a text\nThis is a text\n```\n\n# Example entry point: Program.cs\n\n```csharp\nusing System;\nusing System.Threading;\nusing System.Globalization;\nusing System.Threading.Tasks;\n\nnamespace YourNameSpace {\n    public class Program {\n        public static async Task\u003cint\u003e Main(string[] args) {\n            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\n\n            try {\n                return await CLI.Run(args);\n            } catch (CommandParserException ex) {\n                Console.Error.WriteLine($\"\\nError: {ex.Message}\\n\");\n                return 1;\n            }\n        }\n    }\n}\n```\n\nThe error messages from `CommandParserException` are user-friendly. You can display them in themselves without the full stack.\n\n# TODO\n\n- Generate text documentation from the descriptions and argument types.\n- Add more XML docs to the methods\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbolner%2Fconcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbolner%2Fconcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbolner%2Fconcontroller/lists"}