Meziantou.Framework.CommandLine
4.0.3
Prefix Reserved
dotnet add package Meziantou.Framework.CommandLine --version 4.0.3
NuGet\Install-Package Meziantou.Framework.CommandLine -Version 4.0.3
<PackageReference Include="Meziantou.Framework.CommandLine" Version="4.0.3" />
<PackageVersion Include="Meziantou.Framework.CommandLine" Version="4.0.3" />
<PackageReference Include="Meziantou.Framework.CommandLine" />
paket add Meziantou.Framework.CommandLine --version 4.0.3
#r "nuget: Meziantou.Framework.CommandLine, 4.0.3"
#:package Meziantou.Framework.CommandLine@4.0.3
#addin nuget:?package=Meziantou.Framework.CommandLine&version=4.0.3
#tool nuget:?package=Meziantou.Framework.CommandLine&version=4.0.3
Meziantou.Framework.CommandLine
A .NET library that provides utilities for working with command-line arguments, including parsing, building/escaping arguments, and creating interactive console prompts.
Features
- CommandLineParser: Parse command-line arguments with support for named and positional arguments
- CommandLineBuilder: Properly escape and quote arguments for Windows command-line and cmd.exe
- Prompt: Create interactive yes/no prompts in console applications
Usage
The types are in the Meziantou.Framework namespace.
CommandLineParser
Parse command-line arguments with support for named arguments (with / or - prefix) and positional arguments.
// Parse current process arguments
var currentParser = CommandLineParser.Current;
Assert.NotNull(currentParser);
// Or parse custom arguments
var parser = new CommandLineParser();
parser.Parse(["/name=John", "/verbose", "input.txt"]);
// Check if an argument exists
Assert.True(parser.HasArgument("verbose"));
// Get named argument value
Assert.Equal("John", parser.GetArgument("name"));
// Get positional argument (the index in the array of arguments)
Assert.Equal("input.txt", parser.GetArgument(2));
// Check if help was requested: detects -?, /?, -help, /help, --help
Assert.False(parser.HelpRequested);
Supported argument formats:
- Named with equals:
/name=valueor-name=value - Named with colon:
/name:valueor-name:value - Named without value:
/verboseor-verbose - Positional: any argument without prefix
CommandLineBuilder
Properly escape and quote arguments for safe command-line execution on Windows.
// Quote a single argument for standard Windows applications
var arg = CommandLineBuilder.WindowsQuotedArgument(@"path with spaces\file.txt");
Assert.Equal(@"""path with spaces\file.txt""", arg);
// Quote multiple arguments
var args = CommandLineBuilder.WindowsQuotedArguments("arg1", "path with spaces", "normal");
Assert.Equal(@"arg1 ""path with spaces"" normal", args);
// Quote for cmd.exe (handles special characters like &, |, ^, etc.)
var cmdArg = CommandLineBuilder.WindowsCmdArgument(@"malicious argument"" & whoami");
Assert.Equal(@"^""malicious argument\^"" ^& whoami^""", cmdArg);
var cmdArgs = CommandLineBuilder.WindowsCmdArguments("echo", "Hello & Goodbye");
Assert.Equal(@"echo ^""Hello ^& Goodbye^""", cmdArgs);
Why use CommandLineBuilder?
- Handles spaces, quotes, and backslashes correctly
- Prevents command injection attacks
WindowsCmdArgumenthandles cmd.exe special characters:(,),%,!,^,",<,>,&,|- Based on Microsoft's article: Everyone quotes command line arguments the wrong way
Prompt
Create interactive yes/no prompts in console applications.
// Simple yes/no prompt with default value
var proceed = Prompt.YesNo("Do you want to continue?", defaultValue: true);
// Displays: Do you want to continue? [Y/n]
// User can press Enter to use default (true)
// Without default value
var confirm = Prompt.YesNo("Are you sure?", defaultValue: null);
// Displays: Are you sure? [y/n]
// User must enter y or n
// Custom yes/no labels
var delete = Prompt.YesNo("Delete file?", "Yes", "No", defaultValue: false);
// Displays: Delete file? [y/N]
// Prompts are case-insensitive and loop until valid input
var result = Prompt.YesNo("Enable feature?", defaultValue: true);
if (result)
{
Console.WriteLine("Feature enabled!");
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Meziantou.Framework.CommandLine:
| Repository | Stars |
|---|---|
|
yoshiask/FluentStore
A unifying frontend for Windows app stores and package managers
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.3 | 284 | 10/21/2026 |
| 4.0.2 | 561 | 9/6/2026 |
| 4.0.1 | 153 | 9/3/2026 |
| 4.0.0 | 970 | 7/5/2026 |
| 3.0.11 | 391 | 6/13/2026 |
| 3.0.10 | 212 | 5/31/2026 |
| 3.0.9 | 296 | 5/24/2026 |
| 3.0.8 | 1,871 | 11/2/2025 |
| 3.0.7 | 323 | 10/27/2025 |
| 3.0.6 | 295 | 10/19/2025 |
| 3.0.5 | 793 | 9/3/2025 |
| 3.0.4 | 1,244 | 11/17/2024 |
| 3.0.3 | 788 | 11/15/2023 |
| 3.0.2 | 2,611 | 7/14/2021 |
| 3.0.1 | 815 | 4/22/2021 |
| 3.0.0 | 1,169 | 9/24/2020 |
| 2.2.5 | 978 | 8/9/2020 |
| 2.2.4 | 999 | 6/25/2020 |
| 2.2.3 | 1,554 | 10/23/2019 |
| 2.2.2 | 1,570 | 10/21/2018 |