{"id":37530360,"url":"https://github.com/mgrosperrin/commandlineparser","last_synced_at":"2026-01-16T08:31:34.645Z","repository":{"id":21919744,"uuid":"25243964","full_name":"mgrosperrin/commandlineparser","owner":"mgrosperrin","description":"MGR.CommandLineParser is a multi-command line parser. It uses System.ComponentModel.DataAnnotations to declare and validate the commands.","archived":false,"fork":false,"pushed_at":"2025-11-09T13:59:52.000Z","size":2678,"stargazers_count":12,"open_issues_count":8,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-11-09T15:22:17.394Z","etag":null,"topics":["commandlineparser"],"latest_commit_sha":null,"homepage":"http://mgrosperrin.github.io/commandlineparser/","language":"C#","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/mgrosperrin.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-10-15T07:37:57.000Z","updated_at":"2025-11-09T13:59:55.000Z","dependencies_parsed_at":"2024-03-08T11:34:17.028Z","dependency_job_id":"c63a34cc-ec4d-4d24-9bb9-efdf8e3b01bd","html_url":"https://github.com/mgrosperrin/commandlineparser","commit_stats":{"total_commits":124,"total_committers":6,"mean_commits":"20.666666666666668","dds":0.4032258064516129,"last_synced_commit":"10f39c3e976db83c06a091abca88bd8e28460ed9"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/mgrosperrin/commandlineparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgrosperrin%2Fcommandlineparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgrosperrin%2Fcommandlineparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgrosperrin%2Fcommandlineparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgrosperrin%2Fcommandlineparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgrosperrin","download_url":"https://codeload.github.com/mgrosperrin/commandlineparser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgrosperrin%2Fcommandlineparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: 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":["commandlineparser"],"created_at":"2026-01-16T08:31:34.551Z","updated_at":"2026-01-16T08:31:34.629Z","avatar_url":"https://github.com/mgrosperrin.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"MGR.Commandlineparser\n=================\n\n_**Build status**_\n\n[![CI][build-ci-status_img]][build-ci-status_url]\n[![CodeQL][build-codeql-status_img]][build-codeql-status_url]\n\n\n***MyGet*** *(preview bits)*:\n\n| MGR.CommandLineParser | [![MyGet package version][myget_commandlineparser_img]][myget_commandlineparser_url] | [![Number of MyGet downloads][myget-download_commandlineparser_img]][myget-download_commandlineparser_url] |\n|-|-|-|\n| **MGR.CommandLineParser.Command.Lambda** | [![MyGet package version][myget_commandlineparser-command-lambda_img]][myget_commandlineparser-command-lambda_url] | [![Number of MyGet downloads][myget-download_commandlineparser-command-lambda_img]][myget-download_commandlineparser-command-lambda_url] |\n| **MGR.CommandLineParser.Hosting** | [![MyGet package version][myget_commandlineparser-hosting_img]][myget_commandlineparser-hosting_url] | [![Number of MyGet downloads][myget-download_commandlineparser-hosting_img]][myget-download_commandlineparser-hosting_url] |\n\n***Nuget***:\n\n| MGR.CommandLineParser | [![NuGet package version][nuget_commandlineparser_img]][nuget_commandlineparser_url] | [![Number of NuGet downloads][nuget-download_commandlineparser_img]][nuget-download_commandlineparser_url] |\n|-|-|-|\n| **MGR.CommandLineParser.Command.Lambda** | [![NuGet package version][nuget_commandlineparser-command-lambda_img]][nuget_commandlineparser-command-lambda_url] | [![Number of NuGet downloads][nuget-download_commandlineparser-command-lambda_img]][nuget-download_commandlineparser-command-lambda_url] |\n| **MGR.CommandLineParser.Hosting** | [![NuGet package version][nuget_commandlineparser-hosting_img]][nuget_commandlineparser-hosting_url] | [![Number of NuGet downloads][nuget-download_commandlineparser-hosting_img]][nuget-download_commandlineparser-hosting_url] |\n\n[![Number of open issues][github-issues_img]][github-issues_url]\n[![Number of open PR][github-pr_img]][github-pr_url]\n\nMGR.CommandLineParser is a multi-command line parser. It uses [System.ComponentModel.DataAnnotations](http://msdn.microsoft.com/fr-fr/library/system.componentmodel.dataannotations.aspx) to declare and validate the commands.\n\n# How to use it ?\nYou can find **more docs [here](docs/index.md)**\n\n**1. Install MGR.CommandLineParser**\n\nMGR.CommandLineParser is available through [NuGet][nuget_commandlineparser_url]:\n\n    PM\u003e Install-Package MGR.CommandLineParser\n\n**2. Declare your own commands**\n\nAfter adding `MGR.CommandLineParser` to your project, you have to define your own commands:\n\n* by implementing the interface `MGR.CommandLineParser.Command.ICommand`;\n* by extending the abstract class `MGR.CommandLineParser.Command.CommandBase`.\n\nTo personnalize your commands, you add some properties to your class, and implement `Execute` (if you directly implement `ICommand`), or override `ExecuteCommand` (if you override `CommandBase`).\n\nFor example:\n\nvia `MGR.CommandLineParser.Command.ICommand`:\n\n``` c#\npublic class HelloWorldCommand : ICommand\n{\n    [Display(ShortName = \"n\", Description = \"The name to display\")]\n    [Required]\n    public string Name {get; set;}\n\n    public IList\u003cstring\u003e Arguments {get; set;}\n\n    public Task\u003cint\u003e ExecuteAsync()\n    {\n        Console.WriteLine(\"Hello world {0} !\", Name);\n        if(Arguments.Count \u003e 0)\n        {\n            Console.WriteLine(\"Arguments: {0}\", string.Join(\",\", Arguments));\n        }\n        return Task.FromResult(0);\n    }\n}\n```\n\nVia `MGR.CommandLineParser.Command.CommandBase`:\n\n```c#\npublic class HelloWorldCommand : CommandBase\n{\n    [Display(ShortName = \"n\", Description = \"The name to display\")]\n    [Required]\n    public string Name {get; set;}\n\n    protected override Task\u003cint\u003e ExecuteCommandAsync()\n    {\n        Console.WriteLine(\"Hello world {0} !\", Name);\n        if(Arguments.Count \u003e 0)\n        {\n            Console.WriteLine(\"Arguments: {0}\", string.Join(\",\", Arguments));\n        }\n        return Task.FromResult(0);\n    }\n}\n```\n\n**3. Parse the command line**\n\nThe simplest way to parse the command line is to call the `Parse` method on a `IParser` instance:\n```c#\nvar parserBuilder = new ParserBuilder(new ParserOptions())\n                .AddCommands(builder =\u003e builder.AddCommands\u003cHelloWorldCommand\u003e());\nIParser parser = parserBuilder.BuildParser();\nCommandResult\u003cICommand\u003e commandResult = await parser.Parse(args);\nif(commandResult.IsValid)\n{\n    return await commandResult.ExecuteAsync();\n}\nreturn commandResult.ReturnCode;\n```\n\nOr if you have define only one command for your program:\n```c#\nvar parserBuilder = new ParserBuilder(new ParserOptions())\n                .AddCommands(builder =\u003e builder.AddCommands\u003cHelloWorldCommand\u003e());\nIParser parser = parserBuilder.BuildParser();\nCommandResult\u003cHelloWorldCommand\u003e commandResult = await parser.Parse\u003cHelloWorldCommand\u003e(args);\nif(commandResult.IsValid)\n{\n    return await commandResult.ExecuteAsync();\n}\nreturn commandResult.ReturnCode;\n```\n\nIn the first case, the first item in the `args` parameter must be the name of the command (the name of the type, minus the suffix `Command` if present).\nIn the other case, the name of the command should be omitted.\n\nDepending on the value of `args`, the result will be (when not providing the type of the command to the `Parse` method):\n\n| Value of args | Result |\n|------|--------|\n|`null`|return code is `CommandResultCode.NoArgs` (-100)|\n|empty enumeration of string|return code is `CommandResultCode.NoCommandName` (-200) and the global help is printed to the console|\n|doesn't begin by `HelloWorld` or `Help` (the default help command)|return code is `CommandResultCode.NoCommandFound` (-300) and the global help is printed to the console|\n|`HelloWorld`|return code is `CommandResultCode.CommandParameterNotValid` (-400) and the help for the `HelloWorldCommand` is printed to the console|\n|`HelloWorld --name Matthias` or `HelloWorld -n Matthias`|return code is `CommandResultCode.Ok` (0) and `Hello world Matthias !` is printed to the console|\n\n\n   [build-ci-status_img]: https://github.com/mgrosperrin/commandlineparser/actions/workflows/ci.yml/badge.svg?branch=main\n   [build-ci-status_url]: https://github.com/mgrosperrin/commandlineparser/actions/workflows/ci.yml\n   [build-codeql-status_img]: https://github.com/mgrosperrin/commandlineparser/actions/workflows/codeql-analysis.yml/badge.svg?branch=main\n   [build-codeql-status_url]: https://github.com/mgrosperrin/commandlineparser/actions/workflows/codeql-analysis.yml\n   [myget_commandlineparser_img]: https://img.shields.io/myget/mgrosperrin/vpre/MGR.CommandLineParser.svg\n   [myget_commandlineparser_url]: https://www.myget.org/feed/mgrosperrin/package/nuget/MGR.CommandLineParser/\n   [myget-download_commandlineparser_img]: https://img.shields.io/myget/mgrosperrin/dt/MGR.CommandLineParser.svg\n   [myget-download_commandlineparser_url]: https://www.myget.org/feed/mgrosperrin/package/nuget/MGR.CommandLineParser/\n   [myget_commandlineparser-command-lambda_img]: https://img.shields.io/myget/mgrosperrin/vpre/MGR.CommandLineParser.Command.Lambda.svg\n   [myget_commandlineparser-command-lambda_url]: https://www.myget.org/feed/mgrosperrin/package/nuget/MGR.CommandLineParser.Command.Lambda/\n   [myget-download_commandlineparser-command-lambda_img]: https://img.shields.io/myget/mgrosperrin/dt/MGR.CommandLineParser.Command.Lambda.svg\n   [myget-download_commandlineparser-command-lambda_url]: https://www.myget.org/feed/mgrosperrin/package/nuget/MGR.CommandLineParser.Command.Lambda/\n   [myget_commandlineparser-hosting_img]: https://img.shields.io/myget/mgrosperrin/vpre/MGR.CommandLineParser.Hosting.svg\n   [myget_commandlineparser-hosting_url]: https://www.myget.org/feed/mgrosperrin/package/nuget/MGR.CommandLineParser.Hosting/\n   [myget-download_commandlineparser-hosting_img]: https://img.shields.io/myget/mgrosperrin/dt/MGR.CommandLineParser.Hosting.svg\n   [myget-download_commandlineparser-hosting_url]: https://www.myget.org/feed/mgrosperrin/package/nuget/MGR.CommandLineParser.Hosting/\n   [nuget_commandlineparser_img]: https://img.shields.io/nuget/v/MGR.CommandLineParser.svg\n   [nuget_commandlineparser_url]: https://www.nuget.org/packages/MGR.CommandLineParser/\n   [nuget-download_commandlineparser_img]: https://img.shields.io/nuget/dt/MGR.CommandLineParser.svg\n   [nuget-download_commandlineparser_url]: https://www.nuget.org/stats/packages/MGR.CommandLineParser?groupby=Version\n   [nuget_commandlineparser-command-lambda_img]: https://img.shields.io/nuget/v/MGR.CommandLineParser.Command.Lambda.svg\n   [nuget_commandlineparser-command-lambda_url]: https://www.nuget.org/packages/MGR.CommandLineParser.Command.Lambda/\n   [nuget-download_commandlineparser-command-lambda_img]: https://img.shields.io/nuget/dt/MGR.CommandLineParser.Command.Lambda.svg\n   [nuget-download_commandlineparser-command-lambda_url]: https://www.nuget.org/stats/packages/MGR.CommandLineParser.Command.Lambda?groupby=Version\n   [nuget_commandlineparser-hosting_img]: https://img.shields.io/nuget/v/MGR.CommandLineParser.Hosting.svg\n   [nuget_commandlineparser-hosting_url]: https://www.nuget.org/packages/MGR.CommandLineParser.Hosting/\n   [nuget-download_commandlineparser-hosting_img]: https://img.shields.io/nuget/dt/MGR.CommandLineParser.Hosting.svg\n   [nuget-download_commandlineparser-hosting_url]: https://www.nuget.org/stats/packages/MGR.CommandLineParser.Hosting?groupby=Version\n   [github-issues_img]: http://img.shields.io/github/issues/mgrosperrin/commandlineparser.svg\n   [github-issues_url]: https://github.com/mgrosperrin/commandlineparser/issues\n   [github-pr_img]: http://img.shields.io/github/issues-pr/mgrosperrin/commandlineparser.svg\n   [github-pr_url]: https://github.com/mgrosperrin/commandlineparser/pulls\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgrosperrin%2Fcommandlineparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgrosperrin%2Fcommandlineparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgrosperrin%2Fcommandlineparser/lists"}