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)
|
private void WriteDefaultValue(InputSchema schema)
|
||||||
{
|
{
|
||||||
var defaultValue = context.CommandDefaultValues.GetValueOrDefault(schema);
|
var defaultValue = context.CommandDefaultValues.GetValueOrDefault(schema);
|
||||||
if (defaultValue is null) return;
|
if (defaultValue is null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Non-Scalar
|
// Non-Scalar
|
||||||
if (defaultValue is not string && defaultValue is IEnumerable defaultValues)
|
if (defaultValue is not string && defaultValue is IEnumerable defaultValues)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using CliFx.Utils.Extensions;
|
|||||||
namespace CliFx.Input;
|
namespace CliFx.Input;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes input for a command.
|
/// Input provided by the user for a command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class CommandInput(
|
public partial class CommandInput(
|
||||||
string? commandName,
|
string? commandName,
|
||||||
@@ -16,29 +16,38 @@ public partial class CommandInput(
|
|||||||
IReadOnlyList<EnvironmentVariableInput> environmentVariables
|
IReadOnlyList<EnvironmentVariableInput> environmentVariables
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the requested command.
|
||||||
|
/// </summary>
|
||||||
public string? CommandName { get; } = commandName;
|
public string? CommandName { get; } = commandName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provided directives.
|
||||||
|
/// </summary>
|
||||||
public IReadOnlyList<DirectiveInput> Directives { get; } = directives;
|
public IReadOnlyList<DirectiveInput> Directives { get; } = directives;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provided parameters.
|
||||||
|
/// </summary>
|
||||||
public IReadOnlyList<ParameterInput> Parameters { get; } = parameters;
|
public IReadOnlyList<ParameterInput> Parameters { get; } = parameters;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provided options.
|
||||||
|
/// </summary>
|
||||||
public IReadOnlyList<OptionInput> Options { get; } = options;
|
public IReadOnlyList<OptionInput> Options { get; } = options;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provided environment variables.
|
||||||
|
/// </summary>
|
||||||
public IReadOnlyList<EnvironmentVariableInput> EnvironmentVariables { get; } =
|
public IReadOnlyList<EnvironmentVariableInput> EnvironmentVariables { get; } =
|
||||||
environmentVariables;
|
environmentVariables;
|
||||||
|
|
||||||
public bool HasArguments =>
|
internal bool IsDebugDirectiveSpecified => Directives.Any(d => d.IsDebugDirective);
|
||||||
!string.IsNullOrWhiteSpace(CommandName)
|
|
||||||
|| Directives.Any()
|
|
||||||
|| Parameters.Any()
|
|
||||||
|| Options.Any();
|
|
||||||
|
|
||||||
public bool IsDebugDirectiveSpecified => Directives.Any(d => d.IsDebugDirective);
|
internal bool IsPreviewDirectiveSpecified => Directives.Any(d => d.IsPreviewDirective);
|
||||||
|
|
||||||
public bool IsPreviewDirectiveSpecified => Directives.Any(d => d.IsPreviewDirective);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal partial class CommandInput
|
public partial class CommandInput
|
||||||
{
|
{
|
||||||
private static IReadOnlyList<DirectiveInput> ParseDirectives(
|
private static IReadOnlyList<DirectiveInput> ParseDirectives(
|
||||||
IReadOnlyList<string> commandLineArguments,
|
IReadOnlyList<string> commandLineArguments,
|
||||||
@@ -126,7 +135,7 @@ internal partial class CommandInput
|
|||||||
if (isOptionIdentifier)
|
if (isOptionIdentifier)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
result.Add(new ParameterInput(argument));
|
result.Add(new ParameterInput(index, argument));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -188,7 +197,7 @@ internal partial class CommandInput
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommandInput Parse(
|
internal static CommandInput Parse(
|
||||||
IReadOnlyList<string> commandLineArguments,
|
IReadOnlyList<string> commandLineArguments,
|
||||||
IReadOnlyDictionary<string, string> environmentVariables,
|
IReadOnlyDictionary<string, string> environmentVariables,
|
||||||
IReadOnlyList<string> availableCommandNames
|
IReadOnlyList<string> availableCommandNames
|
||||||
|
|||||||
@@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
namespace CliFx.Input;
|
namespace CliFx.Input;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Input provided by the means of a directive.
|
||||||
|
/// </summary>
|
||||||
public class DirectiveInput(string name)
|
public class DirectiveInput(string name)
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Directive name.
|
||||||
|
/// </summary>
|
||||||
public string Name { get; } = name;
|
public string Name { get; } = name;
|
||||||
|
|
||||||
public bool IsDebugDirective =>
|
internal bool IsDebugDirective =>
|
||||||
string.Equals(Name, "debug", StringComparison.OrdinalIgnoreCase);
|
string.Equals(Name, "debug", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public bool IsPreviewDirective =>
|
internal bool IsPreviewDirective =>
|
||||||
string.Equals(Name, "preview", StringComparison.OrdinalIgnoreCase);
|
string.Equals(Name, "preview", StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,20 @@ using System.IO;
|
|||||||
|
|
||||||
namespace CliFx.Input;
|
namespace CliFx.Input;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Input provided by the means of an environment variable.
|
||||||
|
/// </summary>
|
||||||
public class EnvironmentVariableInput(string name, string value)
|
public class EnvironmentVariableInput(string name, string value)
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Environment variable name.
|
||||||
|
/// </summary>
|
||||||
public string Name { get; } = name;
|
public string Name { get; } = name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Environment variable value.
|
||||||
|
/// </summary>
|
||||||
public string Value { get; } = value;
|
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;
|
namespace CliFx.Input;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes the materialized input for an option of a command.
|
/// Input provided by the means of an option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OptionInput(string identifier, IReadOnlyList<string> values)
|
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;
|
public string Identifier { get; } = identifier;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provided option values.
|
/// Option value(s).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<string> Values { get; } = values;
|
public IReadOnlyList<string> Values { get; } = values;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
namespace CliFx.Input;
|
namespace CliFx.Input;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes the materialized input for a parameter of a command.
|
/// Input provided by the means of a parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ParameterInput(string value)
|
public class ParameterInput(int order, string value)
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Parameter order.
|
||||||
|
/// </summary>
|
||||||
|
public int Order { get; } = order;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parameter value.
|
/// Parameter value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
namespace CliFx.Schema;
|
namespace CliFx.Schema;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes an individual command, with its parameter and option bindings.
|
/// Describes an individual command, along with its parameter and option inputs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CommandSchema(
|
public class CommandSchema(
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
|
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
|
||||||
@@ -27,7 +27,7 @@ public class CommandSchema(
|
|||||||
public string? Name { get; } = name;
|
public string? Name { get; } = name;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this command is the application's default command.
|
/// Whether the command is the application's default command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDefault { get; } = string.IsNullOrWhiteSpace(name);
|
public bool IsDefault { get; } = string.IsNullOrWhiteSpace(name);
|
||||||
|
|
||||||
@@ -37,12 +37,12 @@ public class CommandSchema(
|
|||||||
public string? Description { get; } = description;
|
public string? Description { get; } = description;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Command parameters.
|
/// Parameter inputs of the command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<ParameterSchema> Parameters { get; } = parameters;
|
public IReadOnlyList<ParameterSchema> Parameters { get; } = parameters;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Command options.
|
/// Option inputs of the command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<OptionSchema> Options { get; } = options;
|
public IReadOnlyList<OptionSchema> Options { get; } = options;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using CliFx.Extensibility;
|
|||||||
namespace CliFx.Schema;
|
namespace CliFx.Schema;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes an input binding of a command.
|
/// Describes an input of a command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class InputSchema(
|
public abstract class InputSchema(
|
||||||
PropertyBinding property,
|
PropertyBinding property,
|
||||||
@@ -19,7 +19,7 @@ public abstract class InputSchema(
|
|||||||
public PropertyBinding Property { get; } = property;
|
public PropertyBinding Property { get; } = property;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this input can accept more than one value.
|
/// Whether the input can accept more than one value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSequence { get; } = isSequence;
|
public bool IsSequence { get; } = isSequence;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using CliFx.Extensibility;
|
|||||||
namespace CliFx.Schema;
|
namespace CliFx.Schema;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes an option binding of a command.
|
/// Describes an option input of a command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OptionSchema(
|
public class OptionSchema(
|
||||||
PropertyBinding property,
|
PropertyBinding property,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using CliFx.Extensibility;
|
|||||||
namespace CliFx.Schema;
|
namespace CliFx.Schema;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes a parameter binding of a command.
|
/// Describes a parameter input of a command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ParameterSchema(
|
public class ParameterSchema(
|
||||||
PropertyBinding property,
|
PropertyBinding property,
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ using System.Linq;
|
|||||||
namespace CliFx.Schema;
|
namespace CliFx.Schema;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a CLR property binding.
|
/// Represents a wrapper around a CLR property that provides read and write access to its value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PropertyBinding(
|
public class PropertyBinding(
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods)]
|
[DynamicallyAccessedMembers(
|
||||||
|
DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods
|
||||||
|
)]
|
||||||
Type type,
|
Type type,
|
||||||
Func<object, object?> getValue,
|
Func<object, object?> getValue,
|
||||||
Action<object, object?> setValue
|
Action<object, object?> setValue
|
||||||
@@ -18,7 +20,9 @@ public class PropertyBinding(
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Underlying CLR type of the property.
|
/// Underlying CLR type of the property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods)]
|
[DynamicallyAccessedMembers(
|
||||||
|
DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods
|
||||||
|
)]
|
||||||
public Type Type { get; } = type;
|
public Type Type { get; } = type;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,7 +31,7 @@ public class PropertyBinding(
|
|||||||
public object? GetValue(object instance) => getValue(instance);
|
public object? GetValue(object instance) => getValue(instance);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the value of the property on the specified instance.
|
/// Sets the current value of the property on the specified instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetValue(object instance, object? value) => setValue(instance, value);
|
public void SetValue(object instance, object? value) => setValue(instance, value);
|
||||||
|
|
||||||
@@ -40,7 +44,7 @@ public class PropertyBinding(
|
|||||||
Type.GetEnumValuesAsUnderlyingType();
|
Type.GetEnumValuesAsUnderlyingType();
|
||||||
#else
|
#else
|
||||||
// AOT-compatible APIs are not available here, but it's unlikely
|
// 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();
|
Type.GetEnumValues();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user