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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Meziantou.Framework.CommandLine" Version="3.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.CommandLine" Version="3.0.8" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.CommandLine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Meziantou.Framework.CommandLine --version 3.0.8
                    
#r "nuget: Meziantou.Framework.CommandLine, 3.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Meziantou.Framework.CommandLine@3.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Meziantou.Framework.CommandLine&version=3.0.8
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.CommandLine&version=3.0.8
                    
Install as a Cake Tool

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=value or -name=value
  • Named with colon: /name:value or -name:value
  • Named without value: /verbose or -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?

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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