From ac898fb345286dad4e75fe586657ad0b83a6bf4b Mon Sep 17 00:00:00 2001 From: dedouwe26 <63008025+dedouwe26@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:21:54 +0200 Subject: [PATCH] Add docs: 4.0.0 --- Terminal/Arguments/Argument.cs | 37 ++++++++++++++++++++++++ Terminal/Arguments/ArgumentParameter.cs | 15 ++++++++++ Terminal/Arguments/ArgumentParser.cs | 8 ++--- Terminal/Arguments/Delegates.cs | 12 ++++++++ Terminal/Arguments/PositionalArgument.cs | 16 ++++++++++ Terminal/Terminal.csproj | 6 ++-- 6 files changed, 87 insertions(+), 7 deletions(-) diff --git a/Terminal/Arguments/Argument.cs b/Terminal/Arguments/Argument.cs index 689cf2f..ff3dc42 100644 --- a/Terminal/Arguments/Argument.cs +++ b/Terminal/Arguments/Argument.cs @@ -16,32 +16,69 @@ public class Argument : ICloneable, IEquatable { /// The description of this argument. /// public string? description = null; + /// + /// Creates an argument. + /// + /// The key of this argument. + /// The description of this argument (optional). + /// The parameters of this argument (default: empty). public Argument(string key, string? description = null, IEnumerable? parameters = null) { keys = [key]; this.description = description; this.parameters = parameters == null ? [] : [.. parameters]; } + /// + /// Creates an argument. + /// + /// The keys of this argument. + /// The description of this argument (optional). + /// The parameters of this argument (default: empty). public Argument(IEnumerable keys, string? description = null, IEnumerable? parameters = null) { this.keys = [.. keys]; this.description = description; this.parameters = parameters == null ? [] : [.. parameters]; } + /// + /// Sets the key of this argument. + /// + /// The new key. + /// This argument. public Argument Key(string key) { keys = [key]; return this; } + /// + /// Sets the keys of this argument. + /// + /// The new keys. + /// This argument. public Argument Keys(IEnumerable keys) { this.keys = [.. keys]; return this; } + /// + /// Sets the description of this argument. + /// + /// The new description. + /// This argument. public Argument Description(string? description) { this.description = description; return this; } + /// + /// Sets the parameters of this argument. + /// + /// The new parameters. + /// This argument. public Argument Parameters(IEnumerable parameters) { this.parameters = [.. parameters]; return this; } + /// + /// Adds a parameter to this argument. + /// + /// The parameter to add. + /// This argument. public Argument AddParameter(ArgumentParameter parameter) { parameters = [.. parameters, parameter]; return this; diff --git a/Terminal/Arguments/ArgumentParameter.cs b/Terminal/Arguments/ArgumentParameter.cs index d7e6bb1..c23555e 100644 --- a/Terminal/Arguments/ArgumentParameter.cs +++ b/Terminal/Arguments/ArgumentParameter.cs @@ -28,14 +28,29 @@ public string Value { get { throw new InvalidOperationException("This argument parameter has not been parsed."); } } } + /// + /// Creates an argument parameter. + /// + /// The name of this parameter. + /// The description of this parameter (optional). public ArgumentParameter(string name, string? description = null) { this.name = name; this.description = description; } + /// + /// Sets the name of this parameter. + /// + /// The new name of this parameter. + /// This parameter. public ArgumentParameter Name(string name) { this.name = name; return this; } + /// + /// Sets the description of this parameter. + /// + /// The new description of this parameter. + /// This parameter. public ArgumentParameter Description(string? description) { this.description = description; return this; diff --git a/Terminal/Arguments/ArgumentParser.cs b/Terminal/Arguments/ArgumentParser.cs index 82173a9..a7d1224 100644 --- a/Terminal/Arguments/ArgumentParser.cs +++ b/Terminal/Arguments/ArgumentParser.cs @@ -175,7 +175,7 @@ public void WriteVersion() } private static string GetArgumentHelp(PositionalArgument arg, bool isRed = false) { - return $"{(isRed ? Color.LightRed.ToForegroundANSI() : Color.Orange.ToForegroundANSI())}\u2520{ANSI.Styles.ResetAll} {arg.name}: {arg.description}"; + return $"{(isRed ? Color.LightRed.ToForegroundANSI() : Color.Orange.ToForegroundANSI())}\u2520{ANSI.Styles.ResetAll} {arg.name}{(arg.description == null ? "" : ": "+arg.description)}\n"; } private static string GetArgumentHelpName(string[] keys) { @@ -194,10 +194,10 @@ private static string GetArgumentHelpName(string[] keys) } private static string GetArgumentHelp(Argument arg) { - string result = $"{Color.DarkGreen.ToForegroundANSI()}\u2520{ANSI.Styles.ResetAll} {GetArgumentHelpName(arg.keys)}: {arg.description}\n"; + string result = $"{Color.DarkGreen.ToForegroundANSI()}\u2520{ANSI.Styles.ResetAll} {GetArgumentHelpName(arg.keys)}{(arg.description == null ? "" : ": "+arg.description)}\n"; foreach (ArgumentParameter para in arg.parameters) { - result += $"{Color.DarkGreen.ToForegroundANSI()}\u2503 \u2560{ANSI.Styles.ResetAll} {para.name}: {para.description}\n"; + result += $"{Color.DarkGreen.ToForegroundANSI()}\u2503 \u2560{ANSI.Styles.ResetAll} {para.name}{(para.description == null ? "" : ": "+para.description)}\n"; } return result; } @@ -221,7 +221,7 @@ private string GetHelp(bool showDescription = true, bool showVersion = false, in } } - result += "\n\n"; + result += "\n"; } if (arguments.Count > 0 || helpArgument != null || versionArgument != null) { diff --git a/Terminal/Arguments/Delegates.cs b/Terminal/Arguments/Delegates.cs index 1f44a44..58d6c9d 100644 --- a/Terminal/Arguments/Delegates.cs +++ b/Terminal/Arguments/Delegates.cs @@ -1,5 +1,17 @@ namespace OxDED.Terminal.Arguments; +/// +/// An callback for when an argument has been parsed. +/// +/// The argument that has been parsed. public delegate void ArgumentCallback(Argument argument); +/// +/// An callback for when an postitional argument has been parsed. +/// +/// The positional argument that has been parsed. public delegate void PositionalArgumentCallback(PositionalArgument argument); +/// +/// An callback for when the parsing has failed. +/// +/// The message to describe what failed. public delegate void InvalidFormatCallback(string message); \ No newline at end of file diff --git a/Terminal/Arguments/PositionalArgument.cs b/Terminal/Arguments/PositionalArgument.cs index 86fabbf..a152f96 100644 --- a/Terminal/Arguments/PositionalArgument.cs +++ b/Terminal/Arguments/PositionalArgument.cs @@ -28,14 +28,29 @@ public string Value { get { throw new InvalidOperationException("This positional argument has not been parsed."); } } } + /// + /// Creates a positional argument. + /// + /// The name of this positional argument. + /// The description of this positional argument (optional). public PositionalArgument(string name, string? description = null) { this.name = name; this.description = description; } + /// + /// Sets the name of this positional argument. + /// + /// The new name of this positional argument. + /// This positional argument. public PositionalArgument Name(string name) { this.name = name; return this; } + /// + /// Sets the description of this positional argument. + /// + /// The new description of this positional argument. + /// This positional argument. public PositionalArgument Description(string? description) { this.description = description; return this; @@ -45,6 +60,7 @@ public PositionalArgument Description(string? description) { /// /// Calls . /// + public object Clone() { return ClonePositionalArgument(); } diff --git a/Terminal/Terminal.csproj b/Terminal/Terminal.csproj index 1097666..258d7c3 100644 --- a/Terminal/Terminal.csproj +++ b/Terminal/Terminal.csproj @@ -7,12 +7,12 @@ true true 0xDED.Terminal - 3.1.4 + 4.0.0 0xDED MIT README.md - Terminal;library;console;logging;keyboard;ansi - Terminal is a C# library for managing everything in the terminal, it's an alternative of Console, and it can be used for tui applications. It also supports logging. + Terminal;library;console;logging;keyboard;ansi;argparser + Terminal is a C# library for managing everything in the terminal, it's an alternative of Console, and it can be used for tui applications. It also supports logging, windowing (experimental) and argument parsing. https://github.com/dedouwe26/Terminal.git true git