Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Clap | 11,013 | 7,669 | 8,840 | 2 days ago | 288 | September 21, 2022 | 221 | apache-2.0 | Rust | |
A full featured, fast Command Line Argument Parser for Rust | ||||||||||
Picocli | 4,173 | 209 | 250 | 3 days ago | 78 | February 09, 2022 | 108 | apache-2.0 | Java | |
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc. | ||||||||||
Commandline | 3,916 | 2,956 | 421 | 8 days ago | 97 | May 17, 2022 | 280 | mit | C# | |
The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support | ||||||||||
Caporal.js | 3,353 | 669 | 482 | a month ago | 17 | May 11, 2020 | 56 | mit | TypeScript | |
A full-featured framework for building command line applications (cli) with node.js | ||||||||||
Command Line Api | 3,029 | 27 | 105 | a day ago | 29 | February 17, 2022 | 454 | mit | C# | |
Command line parsing, invocation, and rendering of terminal output. | ||||||||||
Clikt | 2,025 | 29 | 25 | 19 days ago | 16 | June 20, 2020 | 18 | apache-2.0 | Kotlin | |
Multiplatform command line interface parsing for Kotlin | ||||||||||
Argh | 1,048 | 5 months ago | 14 | bsd-3-clause | C++ | |||||
Argh! A minimalist argument handler. | ||||||||||
Command Line Args | 578 | 7,499 | 2,116 | a year ago | 73 | January 29, 2022 | 7 | mit | JavaScript | |
A mature, feature-complete library to parse command-line options. | ||||||||||
Argparse | 443 | 16 | 61 | 8 months ago | 11 | August 08, 2022 | 4 | mit | Go | |
Argparse for golang. Just because `flag` sucks | ||||||||||
Argc | 427 | 1 | a day ago | 18 | September 29, 2022 | 1 | apache-2.0 | Rust | ||
An elegant command-line options, arguments and sub-commands parser for bash. |
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
The 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.
C:\Project> NuGet Install CommandLineParser
Nightly version of the CommandLineParser can be downloaded from github Releases.
The Last new features and fixes, read changelog
NOTE: Mentioned F# Support is provided via CommandLineParser.FSharp
package with FSharp dependencies.
This library provides hassle free command line parsing with a constantly updated API since 2005.
CommandLine.Parser.Default.ParseArguments(...)
and three overload methods.HelpText.AutoBuild(...)
.--help
, --version
, version
and help [verb]
by default with customization.IEnumerable<T>
and similar) and scalar types, including Enums and Nullable<T>
.System.Uri
) for reference and value types.git commit -a
.CommandLine.Parser.Default.FormatCommandLine<T>(T options)
.option<'a>
, see demo. NOTE: This is a separate NuGet package.
You can utilize the parser library in several ways:
C# Quick Start:
using System;
using CommandLine;
namespace QuickStart
{
class Program
{
public class Options
{
[Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
public bool Verbose { get; set; }
}
static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(o =>
{
if (o.Verbose)
{
Console.WriteLine($"Verbose output enabled. Current Arguments: -v {o.Verbose}");
Console.WriteLine("Quick Start Example! App is in Verbose mode!");
}
else
{
Console.WriteLine($"Current Arguments: -v {o.Verbose}");
Console.WriteLine("Quick Start Example!");
}
});
}
}
}
class Options
{
[Option('r', "read", Required = true, HelpText = "Input files to be processed.")]
public IEnumerable<string> InputFiles { get; set; }
// Omitting long name, defaults to name of property, ie "--verbose"
[Option(
Default = false,
HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; }
[Option("stdin",
Default = false,
HelpText = "Read from stdin")]
public bool stdin { get; set; }
[Value(0, MetaName = "offset", HelpText = "File offset.")]
public long? Offset { get; set; }
}
static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed(RunOptions)
.WithNotParsed(HandleParseError);
}
static void RunOptions(Options opts)
{
//handle options
}
static void HandleParseError(IEnumerable<Error> errs)
{
//handle errors
}
Demo to show IEnumerable options and other usage: Online Demo
type options = {
[<Option('r', "read", Required = true, HelpText = "Input files.")>] files : seq<string>;
[<Option(HelpText = "Prints all messages to standard output.")>] verbose : bool;
[<Option(Default = "русский", HelpText = "Content language.")>] language : string;
[<Value(0, MetaName="offset", HelpText = "File offset.")>] offset : int64 option;
}
let main argv =
let result = CommandLine.Parser.Default.ParseArguments<options>(argv)
match result with
| :? Parsed<options> as parsed -> run parsed.Value
| :? NotParsed<options> as notParsed -> fail notParsed.Errors
Class Options
<CommandLine.Option('r', "read", Required := true,
HelpText:="Input files to be processed.")>
Public Property InputFiles As IEnumerable(Of String)
' Omitting long name, defaults to name of property, ie "--verbose"
<CommandLine.Option(
HelpText:="Prints all messages to standard output.")>
Public Property Verbose As Boolean
<CommandLine.Option(Default:="中文",
HelpText:="Content language.")>
Public Property Language As String
<CommandLine.Value(0, MetaName:="offset",
HelpText:="File offset.")>
Public Property Offset As Long?
End Class
Sub Main(ByVal args As String())
CommandLine.Parser.Default.ParseArguments(Of Options)(args) _
.WithParsed(Function(opts As Options) RunOptionsAndReturnExitCode(opts)) _
.WithNotParsed(Function(errs As IEnumerable(Of [Error])) 1)
End Sub
[Verb("add", HelpText = "Add file contents to the index.")]
class AddOptions {
//normal options here
}
[Verb("commit", HelpText = "Record changes to the repository.")]
class CommitOptions {
//commit options here
}
[Verb("clone", HelpText = "Clone a repository into a new directory.")]
class CloneOptions {
//clone options here
}
int Main(string[] args) {
return CommandLine.Parser.Default.ParseArguments<AddOptions, CommitOptions, CloneOptions>(args)
.MapResult(
(AddOptions opts) => RunAddAndReturnExitCode(opts),
(CommitOptions opts) => RunCommitAndReturnExitCode(opts),
(CloneOptions opts) => RunCloneAndReturnExitCode(opts),
errs => 1);
}
<CommandLine.Verb("add", HelpText:="Add file contents to the index.")>
Public Class AddOptions
'Normal options here
End Class
<CommandLine.Verb("commit", HelpText:="Record changes to the repository.")>
Public Class CommitOptions
'Normal options here
End Class
<CommandLine.Verb("clone", HelpText:="Clone a repository into a new directory.")>
Public Class CloneOptions
'Normal options here
End Class
Function Main(ByVal args As String()) As Integer
Return CommandLine.Parser.Default.ParseArguments(Of AddOptions, CommitOptions, CloneOptions)(args) _
.MapResult(
(Function(opts As AddOptions) RunAddAndReturnExitCode(opts)),
(Function(opts As CommitOptions) RunCommitAndReturnExitCode(opts)),
(Function(opts As CloneOptions) RunCloneAndReturnExitCode(opts)),
(Function(errs As IEnumerable(Of [Error])) 1)
)
End Function
open CommandLine
[<Verb("add", HelpText = "Add file contents to the index.")>]
type AddOptions = {
// normal options here
}
[<Verb("commit", HelpText = "Record changes to the repository.")>]
type CommitOptions = {
// normal options here
}
[<Verb("clone", HelpText = "Clone a repository into a new directory.")>]
type CloneOptions = {
// normal options here
}
[<EntryPoint>]
let main args =
let result = Parser.Default.ParseArguments<AddOptions, CommitOptions, CloneOptions> args
match result with
| :? CommandLine.Parsed<obj> as command ->
match command.Value with
| :? AddOptions as opts -> RunAddAndReturnExitCode opts
| :? CommitOptions as opts -> RunCommitAndReturnExitCode opts
| :? CloneOptions as opts -> RunCloneAndReturnExitCode opts
| :? CommandLine.NotParsed<obj> -> 1
See the changelog
First off, Thank you! All contributions are welcome.
Please consider sticking with the GNU getopt standard for command line parsing.
Additionally, for easiest diff compares, please follow the project's tabs settings. Utilizing the EditorConfig extension for Visual Studio/your favorite IDE is recommended.
And most importantly, please target the develop
branch in your pull requests!