Skip to content

Commit

Permalink
Add docs: 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dedouwe26 committed Jun 5, 2024
1 parent 473c071 commit ac898fb
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
37 changes: 37 additions & 0 deletions Terminal/Arguments/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,69 @@ public class Argument : ICloneable, IEquatable<Argument> {
/// The description of this argument.
/// </summary>
public string? description = null;
/// <summary>
/// Creates an argument.
/// </summary>
/// <param name="key">The key of this argument.</param>
/// <param name="description">The description of this argument (optional).</param>
/// <param name="parameters">The parameters of this argument (default: empty).</param>
public Argument(string key, string? description = null, IEnumerable<ArgumentParameter>? parameters = null) {
keys = [key];
this.description = description;
this.parameters = parameters == null ? [] : [.. parameters];
}
/// <summary>
/// Creates an argument.
/// </summary>
/// <param name="keys">The keys of this argument.</param>
/// <param name="description">The description of this argument (optional).</param>
/// <param name="parameters">The parameters of this argument (default: empty).</param>
public Argument(IEnumerable<string> keys, string? description = null, IEnumerable<ArgumentParameter>? parameters = null) {
this.keys = [.. keys];
this.description = description;
this.parameters = parameters == null ? [] : [.. parameters];
}
/// <summary>
/// Sets the key of this argument.
/// </summary>
/// <param name="key">The new key.</param>
/// <returns>This argument.</returns>
public Argument Key(string key) {
keys = [key];
return this;
}
/// <summary>
/// Sets the keys of this argument.
/// </summary>
/// <param name="keys">The new keys.</param>
/// <returns>This argument.</returns>
public Argument Keys(IEnumerable<string> keys) {
this.keys = [.. keys];
return this;
}
/// <summary>
/// Sets the description of this argument.
/// </summary>
/// <param name="description">The new description.</param>
/// <returns>This argument.</returns>
public Argument Description(string? description) {
this.description = description;
return this;
}
/// <summary>
/// Sets the parameters of this argument.
/// </summary>
/// <param name="parameters">The new parameters.</param>
/// <returns>This argument.</returns>
public Argument Parameters(IEnumerable<ArgumentParameter> parameters) {
this.parameters = [.. parameters];
return this;
}
/// <summary>
/// Adds a parameter to this argument.
/// </summary>
/// <param name="parameter">The parameter to add.</param>
/// <returns>This argument.</returns>
public Argument AddParameter(ArgumentParameter parameter) {
parameters = [.. parameters, parameter];
return this;
Expand Down
15 changes: 15 additions & 0 deletions Terminal/Arguments/ArgumentParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,29 @@ public string Value { get {
throw new InvalidOperationException("This argument parameter has not been parsed.");
}
} }
/// <summary>
/// Creates an argument parameter.
/// </summary>
/// <param name="name">The name of this parameter.</param>
/// <param name="description">The description of this parameter (optional).</param>
public ArgumentParameter(string name, string? description = null) {
this.name = name;
this.description = description;
}
/// <summary>
/// Sets the name of this parameter.
/// </summary>
/// <param name="name">The new name of this parameter.</param>
/// <returns>This parameter.</returns>
public ArgumentParameter Name(string name) {
this.name = name;
return this;
}
/// <summary>
/// Sets the description of this parameter.
/// </summary>
/// <param name="description">The new description of this parameter.</param>
/// <returns>This parameter.</returns>
public ArgumentParameter Description(string? description) {
this.description = description;
return this;
Expand Down
8 changes: 4 additions & 4 deletions Terminal/Arguments/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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)
{
Expand Down
12 changes: 12 additions & 0 deletions Terminal/Arguments/Delegates.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
namespace OxDED.Terminal.Arguments;

/// <summary>
/// An callback for when an argument has been parsed.
/// </summary>
/// <param name="argument">The argument that has been parsed.</param>
public delegate void ArgumentCallback(Argument argument);
/// <summary>
/// An callback for when an postitional argument has been parsed.
/// </summary>
/// <param name="argument">The positional argument that has been parsed.</param>
public delegate void PositionalArgumentCallback(PositionalArgument argument);
/// <summary>
/// An callback for when the parsing has failed.
/// </summary>
/// <param name="message">The message to describe what failed.</param>
public delegate void InvalidFormatCallback(string message);
16 changes: 16 additions & 0 deletions Terminal/Arguments/PositionalArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,29 @@ public string Value { get {
throw new InvalidOperationException("This positional argument has not been parsed.");
}
} }
/// <summary>
/// Creates a positional argument.
/// </summary>
/// <param name="name">The name of this positional argument.</param>
/// <param name="description">The description of this positional argument (optional).</param>
public PositionalArgument(string name, string? description = null) {
this.name = name;
this.description = description;
}
/// <summary>
/// Sets the name of this positional argument.
/// </summary>
/// <param name="name">The new name of this positional argument.</param>
/// <returns>This positional argument.</returns>
public PositionalArgument Name(string name) {
this.name = name;
return this;
}
/// <summary>
/// Sets the description of this positional argument.
/// </summary>
/// <param name="description">The new description of this positional argument.</param>
/// <returns>This positional argument.</returns>
public PositionalArgument Description(string? description) {
this.description = description;
return this;
Expand All @@ -45,6 +60,7 @@ public PositionalArgument Description(string? description) {
/// <remarks>
/// Calls <see cref="ClonePositionalArgument"/>.
/// </remarks>

public object Clone() {
return ClonePositionalArgument();
}
Expand Down
6 changes: 3 additions & 3 deletions Terminal/Terminal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<PublishTrimmed>true</PublishTrimmed>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>0xDED.Terminal</PackageId>
<Version>3.1.4</Version>
<Version>4.0.0</Version>
<Authors>0xDED</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>Terminal;library;console;logging;keyboard;ansi</PackageTags>
<PackageDescription>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.</PackageDescription>
<PackageTags>Terminal;library;console;logging;keyboard;ansi;argparser</PackageTags>
<PackageDescription>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.</PackageDescription>
<RepositoryUrl>https://github.com/dedouwe26/Terminal.git</RepositoryUrl>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit ac898fb

Please sign in to comment.