{"id":13414895,"url":"https://github.com/commandlineparser/commandline","last_synced_at":"2025-05-11T03:42:29.128Z","repository":{"id":37382028,"uuid":"109514840","full_name":"commandlineparser/commandline","owner":"commandlineparser","description":"The best C# command line parser that brings standardized *nix getopt style, for .NET.  Includes F# support","archived":false,"fork":false,"pushed_at":"2024-02-29T17:02:27.000Z","size":11818,"stargazers_count":4697,"open_issues_count":319,"forks_count":481,"subscribers_count":72,"default_branch":"master","last_synced_at":"2025-05-11T03:42:21.904Z","etag":null,"topics":["command-line","dotnet","dotnet-core"],"latest_commit_sha":null,"homepage":"","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/commandlineparser.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"License.md","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":"2017-11-04T17:21:03.000Z","updated_at":"2025-05-10T11:36:53.000Z","dependencies_parsed_at":"2022-07-08T07:39:56.056Z","dependency_job_id":"362c5688-28d5-401b-955e-df32907248bf","html_url":"https://github.com/commandlineparser/commandline","commit_stats":{"total_commits":1692,"total_committers":102,"mean_commits":16.58823529411765,"dds":"0.25531914893617025","last_synced_commit":"1e3607b97af6141743edb3c434c06d5b492f6fb3"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commandlineparser%2Fcommandline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commandlineparser%2Fcommandline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commandlineparser%2Fcommandline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commandlineparser%2Fcommandline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commandlineparser","download_url":"https://codeload.github.com/commandlineparser/commandline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253514553,"owners_count":21920334,"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":["command-line","dotnet","dotnet-core"],"created_at":"2024-07-30T21:00:39.493Z","updated_at":"2025-05-11T03:42:29.084Z","avatar_url":"https://github.com/commandlineparser.png","language":"C#","readme":"[![Build status](https://ci.appveyor.com/api/projects/status/p61dj8udxs2aocmo/branch/master?svg=true)](https://ci.appveyor.com/project/commandlineparser/commandline/branch/master)\n[![NuGet](https://img.shields.io/nuget/dt/commandlineparser.svg)](http://nuget.org/packages/commandlineparser)\n[![NuGet](https://img.shields.io/nuget/v/commandlineparser.svg)](https://www.nuget.org/packages/CommandLineParser/)\n[![NuGet](https://img.shields.io/nuget/vpre/commandlineparser.svg)](https://www.nuget.org/packages/CommandLineParser/)\n[![Join the Gitter chat!](https://badges.gitter.im/gsscoder/commandline.svg)](https://gitter.im/gsscoder/commandline?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n# Command Line Parser Library for CLR and NetStandard\n\n**Note:** the API surface has changed since v1.9.x and earlier. If you are looking for documentation on v1.9.x, please see [stable-1.9.71.2](https://github.com/gsscoder/commandline/tree/stable-1.9.71.2)\n\nThe Command Line Parser Library offers CLR applications a clean and concise API for manipulating command line arguments and related tasks, such as defining switches, options and verb commands. It allows you to display a help screen with a high degree of customization and a simple way to report syntax errors to the end user.\n\n```\nC:\\Project\u003e NuGet Install CommandLineParser\n```\n\n# Nightly Build\n\nNightly version of the CommandLineParser can be downloaded from github [Releases](https://github.com/commandlineparser/commandline/releases). \n\nThe Last new features and fixes, read [changelog](https://github.com/commandlineparser/commandline/blob/master/CHANGELOG.md)\n\n\n_NOTE: Mentioned F# Support is provided via ```CommandLineParser.FSharp``` package with FSharp dependencies._\n\n__This library provides _hassle free_ command line parsing with a constantly updated API since 2005.__\n\n# At a glance:\n\n- Compatible with __.NET Framework 4.0+__, __Mono 2.1+ Profile__, __.NET Standard__ and __.NET Core__\n- Doesn't depend on other packages (No dependencies beyond standard base libraries)\n- One line parsing using default singleton: `CommandLine.Parser.Default.ParseArguments(...)` and three overload methods.\n- Automatic or one line help screen generator: `HelpText.AutoBuild(...)`.\n- Supports `--help`, `--version`, `version` and `help [verb]` by default with customization.\n- Map to sequences (via `IEnumerable\u003cT\u003e` and similar) and scalar types, including Enums and `Nullable\u003cT\u003e`.\n- You can also map to every type with a constructor that accepts a string (like `System.Uri`) for reference and value types.\n- Verbs can be array of types collected from Plugins or IoC container.\n- Define [verb commands](https://github.com/commandlineparser/commandline/wiki/Verbs) similar to `git commit -a`.\n- Support default verb.\n- Support Mutable and Immutable types.\n- Support HelpText localization.\n- Support ordering of options in HelpText.\n- Support [Mutually Exclusive Options](https://github.com/commandlineparser/commandline/wiki/Mutually-Exclusive-Options) and [Option groups](https://github.com/commandlineparser/commandline/wiki/Option-Groups).\n- Support named and value options.\n- Support Asynchronous programming with async and await.\n- Unparsing support: `CommandLine.Parser.Default.FormatCommandLine\u003cT\u003e(T options)`.\n- CommandLineParser.FSharp package is F#-friendly with support for `option\u003c'a\u003e`, see [demo](https://github.com/commandlineparser/commandline/blob/master/demo/fsharp-demo.fsx).  _NOTE: This is a separate NuGet package._\n- Include wiki documentation with lot of examples ready to run online.\n- Support Source Link and symbolic nuget package snupkg.\n- Tested in Windows, Linux Ubuntu 18.04 and Mac OS.\n- Most of features applies with a [CoC](http://en.wikipedia.org/wiki/Convention_over_configuration) philosophy.\n- C# demo: source [here](https://github.com/commandlineparser/commandline/tree/master/demo/ReadText.Demo).\n\n# Getting Started with the Command Line Parser Library\n\nYou can utilize the parser library in several ways:\n\n- Install via NuGet/Paket: [https://www.nuget.org/packages/CommandLineParser/](https://www.nuget.org/packages/CommandLineParser/)\n- Integrate directly into your project by copying the .cs files into your project.\n- ILMerge during your build process.\n\n## Quick Start Examples\n\n1. Create a class to define valid options, and to receive the parsed options.\n2. Call ParseArguments with the args string array.\n\nC# Quick Start:\n\n```cs\nusing System;\nusing CommandLine;\n\nnamespace QuickStart\n{\n    class Program\n    {\n        public class Options\n        {\n            [Option('v', \"verbose\", Required = false, HelpText = \"Set output to verbose messages.\")]\n            public bool Verbose { get; set; }\n        }\n\n        static void Main(string[] args)\n        {\n            Parser.Default.ParseArguments\u003cOptions\u003e(args)\n                   .WithParsed\u003cOptions\u003e(o =\u003e\n                   {\n                       if (o.Verbose)\n                       {\n                           Console.WriteLine($\"Verbose output enabled. Current Arguments: -v {o.Verbose}\");\n                           Console.WriteLine(\"Quick Start Example! App is in Verbose mode!\");\n                       }\n                       else\n                       {\n                           Console.WriteLine($\"Current Arguments: -v {o.Verbose}\");\n                           Console.WriteLine(\"Quick Start Example!\");\n                       }\n                   });\n        }\n    }\n}\n```\n\n## C# Examples:\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n```cs\n\nclass Options\n{\n  [Option('r', \"read\", Required = true, HelpText = \"Input files to be processed.\")]\n  public IEnumerable\u003cstring\u003e InputFiles { get; set; }\n\n  // Omitting long name, defaults to name of property, ie \"--verbose\"\n  [Option(\n\tDefault = false,\n\tHelpText = \"Prints all messages to standard output.\")]\n  public bool Verbose { get; set; }\n  \n  [Option(\"stdin\",\n\tDefault = false,\n\tHelpText = \"Read from stdin\")]\n  public bool stdin { get; set; }\n\n  [Value(0, MetaName = \"offset\", HelpText = \"File offset.\")]\n  public long? Offset { get; set; }\n}\n\nstatic void Main(string[] args)\n{\n  CommandLine.Parser.Default.ParseArguments\u003cOptions\u003e(args)\n    .WithParsed(RunOptions)\n    .WithNotParsed(HandleParseError);\n}\nstatic void RunOptions(Options opts)\n{\n  //handle options\n}\nstatic void HandleParseError(IEnumerable\u003cError\u003e errs)\n{\n  //handle errors\n}\n\n```\n\n\u003c/details\u003e\n\nDemo to show IEnumerable  options and other usage:  [Online Demo](https://dotnetfiddle.net/wrcAxr)\n\n## F# Examples:\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n```fsharp\n\ntype options = {\n  [\u003cOption('r', \"read\", Required = true, HelpText = \"Input files.\")\u003e] files : seq\u003cstring\u003e;\n  [\u003cOption(HelpText = \"Prints all messages to standard output.\")\u003e] verbose : bool;\n  [\u003cOption(Default = \"русский\", HelpText = \"Content language.\")\u003e] language : string;\n  [\u003cValue(0, MetaName=\"offset\", HelpText = \"File offset.\")\u003e] offset : int64 option;\n}\n\nlet main argv =\n  let result = CommandLine.Parser.Default.ParseArguments\u003coptions\u003e(argv)\n  match result with\n  | :? Parsed\u003coptions\u003e as parsed -\u003e run parsed.Value\n  | :? NotParsed\u003coptions\u003e as notParsed -\u003e fail notParsed.Errors\n```\n\u003c/details\u003e\n\n## VB.NET Example:\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n```vb\n\nClass Options\n\t\u003cCommandLine.Option('r', \"read\", Required := true,\n\tHelpText:=\"Input files to be processed.\")\u003e\n\tPublic Property InputFiles As IEnumerable(Of String)\n\n\t' Omitting long name, defaults to name of property, ie \"--verbose\"\n\t\u003cCommandLine.Option(\n\tHelpText:=\"Prints all messages to standard output.\")\u003e\n\tPublic Property Verbose As Boolean\n\n\t\u003cCommandLine.Option(Default:=\"中文\",\n\tHelpText:=\"Content language.\")\u003e\n\tPublic Property Language As String\n\n\t\u003cCommandLine.Value(0, MetaName:=\"offset\",\n\tHelpText:=\"File offset.\")\u003e\n\tPublic Property Offset As Long?\nEnd Class\n\nSub Main(ByVal args As String())\n    CommandLine.Parser.Default.ParseArguments(Of Options)(args) _\n        .WithParsed(Function(opts As Options) RunOptionsAndReturnExitCode(opts)) _\n        .WithNotParsed(Function(errs As IEnumerable(Of [Error])) 1)\nEnd Sub\n```\n\u003c/details\u003e\n\n## For verbs:\n\n1. Create separate option classes for each verb.  An options base class is supported.  \n2. Call ParseArguments with all the verb attribute decorated options classes.\n3. Use MapResult to direct program flow to the verb that was parsed.\n\n### C# example:\n\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n```csharp\n[Verb(\"add\", HelpText = \"Add file contents to the index.\")]\nclass AddOptions {\n  //normal options here\n}\n[Verb(\"commit\", HelpText = \"Record changes to the repository.\")]\nclass CommitOptions {\n  //commit options here\n}\n[Verb(\"clone\", HelpText = \"Clone a repository into a new directory.\")]\nclass CloneOptions {\n  //clone options here\n}\n\nint Main(string[] args) {\n  return CommandLine.Parser.Default.ParseArguments\u003cAddOptions, CommitOptions, CloneOptions\u003e(args)\n\t.MapResult(\n\t  (AddOptions opts) =\u003e RunAddAndReturnExitCode(opts),\n\t  (CommitOptions opts) =\u003e RunCommitAndReturnExitCode(opts),\n\t  (CloneOptions opts) =\u003e RunCloneAndReturnExitCode(opts),\n\t  errs =\u003e 1);\n}\n```\n\u003c/details\u003e\n\n### VB.NET example:\n\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n```vb\n\u003cCommandLine.Verb(\"add\", HelpText:=\"Add file contents to the index.\")\u003e\nPublic Class AddOptions\n    'Normal options here\nEnd Class\n\u003cCommandLine.Verb(\"commit\", HelpText:=\"Record changes to the repository.\")\u003e\nPublic Class CommitOptions\n    'Normal options here\nEnd Class\n\u003cCommandLine.Verb(\"clone\", HelpText:=\"Clone a repository into a new directory.\")\u003e\nPublic Class CloneOptions\n    'Normal options here\nEnd Class\n\nFunction Main(ByVal args As String()) As Integer\n    Return CommandLine.Parser.Default.ParseArguments(Of AddOptions, CommitOptions, CloneOptions)(args) _\n          .MapResult(\n              (Function(opts As AddOptions) RunAddAndReturnExitCode(opts)),\n              (Function(opts As CommitOptions) RunCommitAndReturnExitCode(opts)),\n              (Function(opts As CloneOptions) RunCloneAndReturnExitCode(opts)),\n              (Function(errs As IEnumerable(Of [Error])) 1)\n          )\nEnd Function\n```\n\u003c/details\u003e\n\n### F# Example:\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n```fs\nopen CommandLine\n\n[\u003cVerb(\"add\", HelpText = \"Add file contents to the index.\")\u003e]\ntype AddOptions = {\n  // normal options here\n}\n[\u003cVerb(\"commit\", HelpText = \"Record changes to the repository.\")\u003e]\ntype CommitOptions = {\n  // normal options here\n}\n[\u003cVerb(\"clone\", HelpText = \"Clone a repository into a new directory.\")\u003e]\ntype CloneOptions = {\n  // normal options here\n}\n\n[\u003cEntryPoint\u003e]\nlet main args =\n  let result = Parser.Default.ParseArguments\u003cAddOptions, CommitOptions, CloneOptions\u003e args\n  match result with\n  | :? CommandLine.Parsed\u003cobj\u003e as command -\u003e\n\tmatch command.Value with\n\t| :? AddOptions as opts -\u003e RunAddAndReturnExitCode opts\n\t| :? CommitOptions as opts -\u003e RunCommitAndReturnExitCode opts\n\t| :? CloneOptions as opts -\u003e RunCloneAndReturnExitCode opts\n  | :? CommandLine.NotParsed\u003cobj\u003e -\u003e 1\n```\n\u003c/details\u003e\n\n# Release History\n\nSee the [changelog](CHANGELOG.md)\n\n# Contributors\nFirst off, _Thank you!_  All contributions are welcome.  \n\nPlease consider sticking with the GNU getopt standard for command line parsing.  \n\nAdditionally, for easiest diff compares, please follow the project's tabs settings.  Utilizing the EditorConfig extension for Visual Studio/your favorite IDE is recommended.\n\n__And most importantly, please target the ```develop``` branch in your pull requests!__\n\n## Main Contributors (alphabetical order):\n- Alexander Fast (@mizipzor)\n- Dan Nemec (@nemec)\n- Eric Newton (@ericnewton76)\n- Kevin Moore (@gimmemoore)\n- Moh-Hassan (@moh-hassan)\n- Steven Evans\n- Thomas Démoulins (@Thilas)\n\n## Resources for newcomers:\n\n- [Wiki](https://github.com/commandlineparser/commandline/wiki)\n- [GNU getopt](http://www.gnu.org/software/libc/manual/html_node/Getopt.html)\n\n# Contacts:\n\n- Giacomo Stelluti Scala\n  - gsscoder AT gmail DOT com (_use this for everything that is not available via GitHub features_)\n  - GitHub: [gsscoder](https://github.com/gsscoder)\n  - [Blog](http://gsscoder.blogspot.it)\n  - [Twitter](http://twitter.com/gsscoder)\n- Dan Nemec\n- Eric Newton\n  - ericnewton76+commandlineparser AT gmail DOT com\n  - GitHub: [ericnewton76](https://github.com/ericnewton76)\n  - Blog: \n  - Twitter: [enorl76](http://twitter.com/enorl76)\n- Moh-Hassan \n","funding_links":[],"categories":["CLI","dotnet","C#","C# #","C\\#","[Dotnet](https://dotnet.microsoft.com/)","🗒️ Cheatsheets","Additional Languages"],"sub_categories":["📦 Libraries",".NET/C# 🔷"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandlineparser%2Fcommandline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommandlineparser%2Fcommandline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandlineparser%2Fcommandline/lists"}