mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
asd
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -6,7 +6,7 @@ using CliFx.Utils.Extensions;
|
||||
namespace CliFx.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Describes input for a command.
|
||||
/// Input provided by the user for a command.
|
||||
/// </summary>
|
||||
public partial class CommandInput(
|
||||
string? commandName,
|
||||
@@ -16,29 +16,38 @@ public partial class CommandInput(
|
||||
IReadOnlyList<EnvironmentVariableInput> environmentVariables
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the requested command.
|
||||
/// </summary>
|
||||
public string? CommandName { get; } = commandName;
|
||||
|
||||
/// <summary>
|
||||
/// Provided directives.
|
||||
/// </summary>
|
||||
public IReadOnlyList<DirectiveInput> Directives { get; } = directives;
|
||||
|
||||
/// <summary>
|
||||
/// Provided parameters.
|
||||
/// </summary>
|
||||
public IReadOnlyList<ParameterInput> Parameters { get; } = parameters;
|
||||
|
||||
/// <summary>
|
||||
/// Provided options.
|
||||
/// </summary>
|
||||
public IReadOnlyList<OptionInput> Options { get; } = options;
|
||||
|
||||
/// <summary>
|
||||
/// Provided environment variables.
|
||||
/// </summary>
|
||||
public IReadOnlyList<EnvironmentVariableInput> 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<DirectiveInput> ParseDirectives(
|
||||
IReadOnlyList<string> 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<string> commandLineArguments,
|
||||
IReadOnlyDictionary<string, string> environmentVariables,
|
||||
IReadOnlyList<string> availableCommandNames
|
||||
|
||||
@@ -2,13 +2,19 @@
|
||||
|
||||
namespace CliFx.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Input provided by the means of a directive.
|
||||
/// </summary>
|
||||
public class DirectiveInput(string name)
|
||||
{
|
||||
/// <summary>
|
||||
/// Directive name.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,20 @@ using System.IO;
|
||||
|
||||
namespace CliFx.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Input provided by the means of an environment variable.
|
||||
/// </summary>
|
||||
public class EnvironmentVariableInput(string name, string value)
|
||||
{
|
||||
/// <summary>
|
||||
/// Environment variable name.
|
||||
/// </summary>
|
||||
public string Name { get; } = name;
|
||||
|
||||
/// <summary>
|
||||
/// Environment variable value.
|
||||
/// </summary>
|
||||
public string Value { get; } = value;
|
||||
|
||||
public IReadOnlyList<string> SplitValues() => Value.Split(Path.PathSeparator);
|
||||
internal IReadOnlyList<string> SplitValues() => Value.Split(Path.PathSeparator);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace CliFx.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Describes the materialized input for an option of a command.
|
||||
/// Input provided by the means of an option.
|
||||
/// </summary>
|
||||
public class OptionInput(string identifier, IReadOnlyList<string> values)
|
||||
{
|
||||
@@ -13,7 +13,7 @@ public class OptionInput(string identifier, IReadOnlyList<string> values)
|
||||
public string Identifier { get; } = identifier;
|
||||
|
||||
/// <summary>
|
||||
/// Provided option values.
|
||||
/// Option value(s).
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Values { get; } = values;
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
namespace CliFx.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Describes the materialized input for a parameter of a command.
|
||||
/// Input provided by the means of a parameter.
|
||||
/// </summary>
|
||||
public class ParameterInput(string value)
|
||||
public class ParameterInput(int order, string value)
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameter order.
|
||||
/// </summary>
|
||||
public int Order { get; } = order;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter value.
|
||||
/// </summary>
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
namespace CliFx.Schema;
|
||||
|
||||
/// <summary>
|
||||
/// Describes an individual command, with its parameter and option bindings.
|
||||
/// Describes an individual command, along with its parameter and option inputs.
|
||||
/// </summary>
|
||||
public class CommandSchema(
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
|
||||
@@ -27,7 +27,7 @@ public class CommandSchema(
|
||||
public string? Name { get; } = name;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this command is the application's default command.
|
||||
/// Whether the command is the application's default command.
|
||||
/// </summary>
|
||||
public bool IsDefault { get; } = string.IsNullOrWhiteSpace(name);
|
||||
|
||||
@@ -37,12 +37,12 @@ public class CommandSchema(
|
||||
public string? Description { get; } = description;
|
||||
|
||||
/// <summary>
|
||||
/// Command parameters.
|
||||
/// Parameter inputs of the command.
|
||||
/// </summary>
|
||||
public IReadOnlyList<ParameterSchema> Parameters { get; } = parameters;
|
||||
|
||||
/// <summary>
|
||||
/// Command options.
|
||||
/// Option inputs of the command.
|
||||
/// </summary>
|
||||
public IReadOnlyList<OptionSchema> Options { get; } = options;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using CliFx.Extensibility;
|
||||
namespace CliFx.Schema;
|
||||
|
||||
/// <summary>
|
||||
/// Describes an input binding of a command.
|
||||
/// Describes an input of a command.
|
||||
/// </summary>
|
||||
public abstract class InputSchema(
|
||||
PropertyBinding property,
|
||||
@@ -19,7 +19,7 @@ public abstract class InputSchema(
|
||||
public PropertyBinding Property { get; } = property;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this input can accept more than one value.
|
||||
/// Whether the input can accept more than one value.
|
||||
/// </summary>
|
||||
public bool IsSequence { get; } = isSequence;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using CliFx.Extensibility;
|
||||
namespace CliFx.Schema;
|
||||
|
||||
/// <summary>
|
||||
/// Describes an option binding of a command.
|
||||
/// Describes an option input of a command.
|
||||
/// </summary>
|
||||
public class OptionSchema(
|
||||
PropertyBinding property,
|
||||
|
||||
@@ -4,7 +4,7 @@ using CliFx.Extensibility;
|
||||
namespace CliFx.Schema;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a parameter binding of a command.
|
||||
/// Describes a parameter input of a command.
|
||||
/// </summary>
|
||||
public class ParameterSchema(
|
||||
PropertyBinding property,
|
||||
|
||||
@@ -6,11 +6,13 @@ using System.Linq;
|
||||
namespace CliFx.Schema;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a CLR property binding.
|
||||
/// Represents a wrapper around a CLR property that provides read and write access to its value.
|
||||
/// </summary>
|
||||
public class PropertyBinding(
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods)]
|
||||
Type type,
|
||||
[DynamicallyAccessedMembers(
|
||||
DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods
|
||||
)]
|
||||
Type type,
|
||||
Func<object, object?> getValue,
|
||||
Action<object, object?> setValue
|
||||
)
|
||||
@@ -18,7 +20,9 @@ public class PropertyBinding(
|
||||
/// <summary>
|
||||
/// Underlying CLR type of the property.
|
||||
/// </summary>
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods)]
|
||||
[DynamicallyAccessedMembers(
|
||||
DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods
|
||||
)]
|
||||
public Type Type { get; } = type;
|
||||
|
||||
/// <summary>
|
||||
@@ -27,7 +31,7 @@ public class PropertyBinding(
|
||||
public object? GetValue(object instance) => getValue(instance);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of the property on the specified instance.
|
||||
/// Sets the current value of the property on the specified instance.
|
||||
/// </summary>
|
||||
public void SetValue(object instance, object? value) => setValue(instance, value);
|
||||
|
||||
@@ -40,7 +44,7 @@ public class PropertyBinding(
|
||||
Type.GetEnumValuesAsUnderlyingType();
|
||||
#else
|
||||
// AOT-compatible APIs are not available here, but it's unlikely
|
||||
// someone will be AOT-compiling a net6.0 or older app anyway.
|
||||
// that someone will be AOT-compiling a net6.0 or older app anyway.
|
||||
Type.GetEnumValues();
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user