From cfd28c133ee3dbf68e778a84d2c681aec132d120 Mon Sep 17 00:00:00 2001
From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Date: Sun, 16 Jun 2024 21:09:42 +0300
Subject: [PATCH] asd
---
CliFx/Formatting/HelpConsoleFormatter.cs | 3 ++-
CliFx/Input/CommandInput.cs | 33 +++++++++++++++---------
CliFx/Input/DirectiveInput.cs | 10 +++++--
CliFx/Input/EnvironmentVariableInput.cs | 11 +++++++-
CliFx/Input/OptionInput.cs | 4 +--
CliFx/Input/ParameterInput.cs | 9 +++++--
CliFx/Schema/CommandSchema.cs | 8 +++---
CliFx/Schema/InputSchema.cs | 4 +--
CliFx/Schema/OptionSchema.cs | 2 +-
CliFx/Schema/ParameterSchema.cs | 2 +-
CliFx/Schema/PropertyBinding.cs | 16 +++++++-----
11 files changed, 68 insertions(+), 34 deletions(-)
diff --git a/CliFx/Formatting/HelpConsoleFormatter.cs b/CliFx/Formatting/HelpConsoleFormatter.cs
index 16aaf92..9a4b6e8 100644
--- a/CliFx/Formatting/HelpConsoleFormatter.cs
+++ b/CliFx/Formatting/HelpConsoleFormatter.cs
@@ -308,7 +308,8 @@ internal class HelpConsoleFormatter(ConsoleWriter consoleWriter, HelpContext con
private void WriteDefaultValue(InputSchema schema)
{
var defaultValue = context.CommandDefaultValues.GetValueOrDefault(schema);
- if (defaultValue is null) return;
+ if (defaultValue is null)
+ return;
// Non-Scalar
if (defaultValue is not string && defaultValue is IEnumerable defaultValues)
diff --git a/CliFx/Input/CommandInput.cs b/CliFx/Input/CommandInput.cs
index 796515d..63a98fb 100644
--- a/CliFx/Input/CommandInput.cs
+++ b/CliFx/Input/CommandInput.cs
@@ -6,7 +6,7 @@ using CliFx.Utils.Extensions;
namespace CliFx.Input;
///
-/// Describes input for a command.
+/// Input provided by the user for a command.
///
public partial class CommandInput(
string? commandName,
@@ -16,29 +16,38 @@ public partial class CommandInput(
IReadOnlyList environmentVariables
)
{
+ ///
+ /// Name of the requested command.
+ ///
public string? CommandName { get; } = commandName;
+ ///
+ /// Provided directives.
+ ///
public IReadOnlyList Directives { get; } = directives;
+ ///
+ /// Provided parameters.
+ ///
public IReadOnlyList Parameters { get; } = parameters;
+ ///
+ /// Provided options.
+ ///
public IReadOnlyList Options { get; } = options;
+ ///
+ /// Provided environment variables.
+ ///
public IReadOnlyList EnvironmentVariables { get; } =
environmentVariables;
- public bool HasArguments =>
- !string.IsNullOrWhiteSpace(CommandName)
- || Directives.Any()
- || Parameters.Any()
- || Options.Any();
+ internal bool IsDebugDirectiveSpecified => Directives.Any(d => d.IsDebugDirective);
- public bool IsDebugDirectiveSpecified => Directives.Any(d => d.IsDebugDirective);
-
- public bool IsPreviewDirectiveSpecified => Directives.Any(d => d.IsPreviewDirective);
+ internal bool IsPreviewDirectiveSpecified => Directives.Any(d => d.IsPreviewDirective);
}
-internal partial class CommandInput
+public partial class CommandInput
{
private static IReadOnlyList ParseDirectives(
IReadOnlyList commandLineArguments,
@@ -126,7 +135,7 @@ internal partial class CommandInput
if (isOptionIdentifier)
break;
- result.Add(new ParameterInput(argument));
+ result.Add(new ParameterInput(index, argument));
}
return result;
@@ -188,7 +197,7 @@ internal partial class CommandInput
return result;
}
- public static CommandInput Parse(
+ internal static CommandInput Parse(
IReadOnlyList commandLineArguments,
IReadOnlyDictionary environmentVariables,
IReadOnlyList availableCommandNames
diff --git a/CliFx/Input/DirectiveInput.cs b/CliFx/Input/DirectiveInput.cs
index 12d318a..9e934e7 100644
--- a/CliFx/Input/DirectiveInput.cs
+++ b/CliFx/Input/DirectiveInput.cs
@@ -2,13 +2,19 @@
namespace CliFx.Input;
+///
+/// Input provided by the means of a directive.
+///
public class DirectiveInput(string name)
{
+ ///
+ /// Directive name.
+ ///
public string Name { get; } = name;
- public bool IsDebugDirective =>
+ internal bool IsDebugDirective =>
string.Equals(Name, "debug", StringComparison.OrdinalIgnoreCase);
- public bool IsPreviewDirective =>
+ internal bool IsPreviewDirective =>
string.Equals(Name, "preview", StringComparison.OrdinalIgnoreCase);
}
diff --git a/CliFx/Input/EnvironmentVariableInput.cs b/CliFx/Input/EnvironmentVariableInput.cs
index 4ebd59f..01419f7 100644
--- a/CliFx/Input/EnvironmentVariableInput.cs
+++ b/CliFx/Input/EnvironmentVariableInput.cs
@@ -3,11 +3,20 @@ using System.IO;
namespace CliFx.Input;
+///
+/// Input provided by the means of an environment variable.
+///
public class EnvironmentVariableInput(string name, string value)
{
+ ///
+ /// Environment variable name.
+ ///
public string Name { get; } = name;
+ ///
+ /// Environment variable value.
+ ///
public string Value { get; } = value;
- public IReadOnlyList SplitValues() => Value.Split(Path.PathSeparator);
+ internal IReadOnlyList SplitValues() => Value.Split(Path.PathSeparator);
}
diff --git a/CliFx/Input/OptionInput.cs b/CliFx/Input/OptionInput.cs
index 327a19d..99ed920 100644
--- a/CliFx/Input/OptionInput.cs
+++ b/CliFx/Input/OptionInput.cs
@@ -3,7 +3,7 @@
namespace CliFx.Input;
///
-/// Describes the materialized input for an option of a command.
+/// Input provided by the means of an option.
///
public class OptionInput(string identifier, IReadOnlyList values)
{
@@ -13,7 +13,7 @@ public class OptionInput(string identifier, IReadOnlyList values)
public string Identifier { get; } = identifier;
///
- /// Provided option values.
+ /// Option value(s).
///
public IReadOnlyList Values { get; } = values;
diff --git a/CliFx/Input/ParameterInput.cs b/CliFx/Input/ParameterInput.cs
index d533859..2a1713e 100644
--- a/CliFx/Input/ParameterInput.cs
+++ b/CliFx/Input/ParameterInput.cs
@@ -1,10 +1,15 @@
namespace CliFx.Input;
///
-/// Describes the materialized input for a parameter of a command.
+/// Input provided by the means of a parameter.
///
-public class ParameterInput(string value)
+public class ParameterInput(int order, string value)
{
+ ///
+ /// Parameter order.
+ ///
+ public int Order { get; } = order;
+
///
/// Parameter value.
///
diff --git a/CliFx/Schema/CommandSchema.cs b/CliFx/Schema/CommandSchema.cs
index 68df727..b9fc517 100644
--- a/CliFx/Schema/CommandSchema.cs
+++ b/CliFx/Schema/CommandSchema.cs
@@ -5,7 +5,7 @@ using System.Diagnostics.CodeAnalysis;
namespace CliFx.Schema;
///
-/// Describes an individual command, with its parameter and option bindings.
+/// Describes an individual command, along with its parameter and option inputs.
///
public class CommandSchema(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
@@ -27,7 +27,7 @@ public class CommandSchema(
public string? Name { get; } = name;
///
- /// Whether this command is the application's default command.
+ /// Whether the command is the application's default command.
///
public bool IsDefault { get; } = string.IsNullOrWhiteSpace(name);
@@ -37,12 +37,12 @@ public class CommandSchema(
public string? Description { get; } = description;
///
- /// Command parameters.
+ /// Parameter inputs of the command.
///
public IReadOnlyList Parameters { get; } = parameters;
///
- /// Command options.
+ /// Option inputs of the command.
///
public IReadOnlyList Options { get; } = options;
diff --git a/CliFx/Schema/InputSchema.cs b/CliFx/Schema/InputSchema.cs
index 0401641..4f4e260 100644
--- a/CliFx/Schema/InputSchema.cs
+++ b/CliFx/Schema/InputSchema.cs
@@ -4,7 +4,7 @@ using CliFx.Extensibility;
namespace CliFx.Schema;
///
-/// Describes an input binding of a command.
+/// Describes an input of a command.
///
public abstract class InputSchema(
PropertyBinding property,
@@ -19,7 +19,7 @@ public abstract class InputSchema(
public PropertyBinding Property { get; } = property;
///
- /// Whether this input can accept more than one value.
+ /// Whether the input can accept more than one value.
///
public bool IsSequence { get; } = isSequence;
diff --git a/CliFx/Schema/OptionSchema.cs b/CliFx/Schema/OptionSchema.cs
index c59dce2..493760e 100644
--- a/CliFx/Schema/OptionSchema.cs
+++ b/CliFx/Schema/OptionSchema.cs
@@ -6,7 +6,7 @@ using CliFx.Extensibility;
namespace CliFx.Schema;
///
-/// Describes an option binding of a command.
+/// Describes an option input of a command.
///
public class OptionSchema(
PropertyBinding property,
diff --git a/CliFx/Schema/ParameterSchema.cs b/CliFx/Schema/ParameterSchema.cs
index 15f75db..b52f40d 100644
--- a/CliFx/Schema/ParameterSchema.cs
+++ b/CliFx/Schema/ParameterSchema.cs
@@ -4,7 +4,7 @@ using CliFx.Extensibility;
namespace CliFx.Schema;
///
-/// Describes a parameter binding of a command.
+/// Describes a parameter input of a command.
///
public class ParameterSchema(
PropertyBinding property,
diff --git a/CliFx/Schema/PropertyBinding.cs b/CliFx/Schema/PropertyBinding.cs
index a7a48dc..fa3e651 100644
--- a/CliFx/Schema/PropertyBinding.cs
+++ b/CliFx/Schema/PropertyBinding.cs
@@ -6,11 +6,13 @@ using System.Linq;
namespace CliFx.Schema;
///
-/// Represents a CLR property binding.
+/// Represents a wrapper around a CLR property that provides read and write access to its value.
///
public class PropertyBinding(
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods)]
- Type type,
+ [DynamicallyAccessedMembers(
+ DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods
+ )]
+ Type type,
Func