Meziantou.Framework.CommandLine
3.0.8
Prefix Reserved
dotnet add package Meziantou.Framework.CommandLine --version 3.0.8
NuGet\Install-Package Meziantou.Framework.CommandLine -Version 3.0.8
<PackageReference Include="Meziantou.Framework.CommandLine" Version="3.0.8" />
<PackageVersion Include="Meziantou.Framework.CommandLine" Version="3.0.8" />
<PackageReference Include="Meziantou.Framework.CommandLine" />
paket add Meziantou.Framework.CommandLine --version 3.0.8
#r "nuget: Meziantou.Framework.CommandLine, 3.0.8"
#:package Meziantou.Framework.CommandLine@3.0.8
#addin nuget:?package=Meziantou.Framework.CommandLine&version=3.0.8
#tool nuget:?package=Meziantou.Framework.CommandLine&version=3.0.8
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
CommandLineParser
Parse command-line arguments with support for named arguments (with / or - prefix) and positional arguments.
using Meziantou.Framework;
// Parse current process arguments
var parser = CommandLineParser.Current;
// Or parse custom arguments
var customParser = new CommandLineParser();
customParser.Parse(new[] { "/name=John", "/verbose", "input.txt" });
// Check if an argument exists
if (parser.HasArgument("verbose"))
{
Console.WriteLine("Verbose mode enabled");
}
// Get named argument value
var name = parser.GetArgument("name");
Console.WriteLine($"Name: {name}"); // Output: Name: John
// Get positional argument
var inputFile = parser.GetArgument(2); // Position-based argument
Console.WriteLine($"Input file: {inputFile}"); // Output: Input file: input.txt
// Check if help was requested
if (parser.HelpRequested) // Detects -?, /?, -help, /help, --help
{
ShowHelp();
}
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.
using Meziantou.Framework;
// Quote a single argument for standard Windows applications
var arg = CommandLineBuilder.WindowsQuotedArgument(@"path with spaces\file.txt");
// Returns: "path with spaces\file.txt"
// Quote multiple arguments
var args = CommandLineBuilder.WindowsQuotedArguments("arg1", "path with spaces", "normal");
// Returns: arg1 "path with spaces" normal
// Quote for cmd.exe (handles special characters like &, |, ^, etc.)
var cmdArg = CommandLineBuilder.WindowsCmdArgument(@"malicious argument"" & whoami");
// Returns properly escaped argument safe for cmd.exe
var cmdArgs = CommandLineBuilder.WindowsCmdArguments("echo", "Hello & Goodbye");
// Returns arguments safe for cmd.exe execution
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.
using Meziantou.Framework;
// 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 | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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 |
|---|---|---|
| 3.0.8 | 370 | 11/2/2025 |
| 3.0.7 | 248 | 10/27/2025 |
| 3.0.6 | 224 | 10/19/2025 |
| 3.0.5 | 735 | 9/3/2025 |
| 3.0.4 | 1,172 | 11/17/2024 |
| 3.0.3 | 661 | 11/15/2023 |
| 3.0.2 | 2,538 | 7/14/2021 |
| 3.0.1 | 749 | 4/22/2021 |
| 3.0.0 | 1,096 | 9/24/2020 |
| 2.2.5 | 911 | 8/9/2020 |
| 2.2.4 | 934 | 6/25/2020 |
| 2.2.3 | 1,484 | 10/23/2019 |
| 2.2.2 | 1,484 | 10/21/2018 |
| 2.2.1 | 1,442 | 7/7/2018 |
| 2.2.0 | 1,389 | 6/19/2018 |
| 2.1.0 | 1,446 | 5/26/2018 |
| 2.0.0 | 1,264 | 11/23/2017 |
| 1.0.0 | 1,415 | 11/17/2017 |