From bd06e37dc9c3e6fbb5b11b8134afb2854a139008 Mon Sep 17 00:00:00 2001 From: jonathanvdc Date: Fri, 27 Mar 2026 00:04:16 -0400 Subject: [PATCH 1/3] Add ergonomic command-line parsing APIs --- Pixie/Options/CommandLine.cs | 304 +++++++++++++++++++++++++++++ Pixie/Options/Option.cs | 147 +++++++++++++- Pixie/Options/OptionForm.cs | 46 ++++- Pixie/Options/OptionParseResult.cs | 149 ++++++++++++++ Pixie/Options/SequenceOption.cs | 51 +++++ Pixie/Options/ValueOption.cs | 42 ++++ Tests/GnuOptionSetParserTests.cs | 186 ++++++++++++++++++ 7 files changed, 923 insertions(+), 2 deletions(-) create mode 100644 Pixie/Options/CommandLine.cs create mode 100644 Pixie/Options/OptionParseResult.cs diff --git a/Pixie/Options/CommandLine.cs b/Pixie/Options/CommandLine.cs new file mode 100644 index 0000000..110a7bf --- /dev/null +++ b/Pixie/Options/CommandLine.cs @@ -0,0 +1,304 @@ +using System.Collections.Generic; +using Pixie.Markup; + +namespace Pixie.Options +{ + /// + /// Defines the options accepted by a command-line program and parses + /// argument lists into an . + /// Use this type when you want one place to describe your options, + /// positional arguments, and common built-in behaviors such as + /// --help and --version. + /// + public sealed class CommandLine + { + /// + /// Creates a command line that accepts only named options. + /// + /// The options accepted by the command line. + public CommandLine(params Option[] options) + : this( + options, + new KeyValuePair[0]) + { } + + /// + /// Creates a command line with one option that also consumes + /// positional arguments. + /// + /// The options accepted by the command line. + /// + /// The option that should consume bare arguments such as file names. + /// + public CommandLine( + IReadOnlyList