GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bytecode-api/BytecodeApi.CommandLineParser at master · bytecode77/bytecode-api

Expand file tree

/

BytecodeApi.CommandLineParser

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

BytecodeApi.CommandLineParser

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
.nuget
.nuget
 
 
Properties
Properties
 
 
BytecodeApi.CommandLineParser.csproj
BytecodeApi.CommandLineParser.csproj
 
 
CommandLineParserError.cs
CommandLineParserError.cs
 
 
CommandLineParserException.cs
CommandLineParserException.cs
 
 
Option.cs
Option.cs
 
 
OptionSet.cs
OptionSet.cs
 
 
ParsedOption.cs
ParsedOption.cs
 
 
ParsedOptionSet.cs
ParsedOptionSet.cs
 
 
README.md
README.md
 
 

README.md

Outline

BytecodeApi.CommandLineParser

Library for commandline parsing and handling.

Examples

BytecodeApi.CommandLineParser

OptionSet

An OptionSet is the definition of all possible commandline options.

new OptionSet("-", "--")
	.Add(new[] { "c" }, new[] { "command" })
	.Add(new[] { "h" }, new[] { "help" })

- is the prefix and -- is the alternative prefix. In this example, following options are configured:

  • -c
  • --command
  • -h
  • --help

Each option can have multiple parameters. Example:

-f file1.txt file2.txt -o output.txt
ParsedOptionSet

After the OptionSet.Parse method comes the handling of user provided commandline arguments.

The handler executes the Action<string[]> with the arguments after the commandline, i.e.

CommandLine: -c arg1 arg2
Output: -c executed with arg1 arg2

new OptionSet("-", "--")
	.Add(new[] { "c" }, new[] { "command" })
	.Add(new[] { "h" }, new[] { "help" })
	.Parse(args) // From Main() method
	.Handle("c", arguments =>
	{
		Console.WriteLine("-c executed with " + string.Join(" ", arguments));
	});
ParsedOptionSet.Validate

Validate provides a callback that is invoked, if a specific validation rule is not met.

If none of the existing validation rules satisfy your requirements, use Validate.Custom to implement a custom validation rule.

new OptionSet("-", "--")
	.Add(new[] { "c" }, new[] { "command" })
	.Add(new[] { "h" }, new[] { "help" })
	.Parse(args)
	.Validate.OptionRequired("c", () =>
	{
		Console.WriteLine("-c is mandatory");
	})
	.Handle(
		// ...
	);
ParsedOptionSet.Assert

Assert works similar to Validate, however instead of callbacks, a CommandLineParserException is thrown.

Use assertion, if an exception is sufficient and manual error handling is not required.

new OptionSet("-", "--")
	.Add(new[] { "c" }, new[] { "command" })
	.Add(new[] { "h" }, new[] { "help" })
	.Parse(args)
	.Assert.OptionRequired("c")
	.Handle(
		// ...
	);

Changelog

5.0.0 (15.02.2026)

  • change: Targeting .NET 10.0

4.0.0 (15.09.2025)

  • change: Targeting .NET 9.0

3.0.0 (08.09.2023)

  • Initial release
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.