Skip to content

Commit

Permalink
Revert "Merge pull request #90 from yatagarasu25/params_arguments_patch"
Browse files Browse the repository at this point in the history
This reverts commit 4a19ccb.
neuecc committed Oct 5, 2022
1 parent 4a19ccb commit 57240a5
Showing 3 changed files with 13 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/ConsoleAppFramework/CommandHelpBuilder.cs
Original file line number Diff line number Diff line change
@@ -305,24 +305,24 @@ internal CommandHelpDefinition CreateCommandHelpDefinition(CommandDescriptor des
var isFlag = item.ParameterType == typeof(bool);

var defaultValue = default(string);
if (item.HasDefaultValue())
if (item.HasDefaultValue)
{
if (option?.DefaultValue != null)
{
defaultValue = option.DefaultValue;
}
else
{
defaultValue = (item.DefaultValue()?.ToString() ?? "null");
defaultValue = (item.DefaultValue?.ToString() ?? "null");
}
if (isFlag)
{
if (item.DefaultValue() is true)
if (item.DefaultValue is true)
{
// bool option with true default value is not flag.
isFlag = false;
}
else if (item.DefaultValue() is false)
else if (item.DefaultValue is false)
{
// false default value should be omitted for flag.
defaultValue = null;
25 changes: 9 additions & 16 deletions src/ConsoleAppFramework/ConsoleAppEngine.cs
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ public async Task RunAsync()
if (commandDescriptor.CommandType == CommandType.DefaultCommand && args.Length == 0)
{
var p = commandDescriptor.MethodInfo.GetParameters();
if (p.Any(x => !(x.ParameterType == typeof(ConsoleAppContext) || isService.IsService(x.ParameterType) || x.HasDefaultValue())))
if (p.Any(x => !(x.ParameterType == typeof(ConsoleAppContext) || isService.IsService(x.ParameterType) || x.HasDefaultValue)))
{
options.CommandDescriptors.TryGetHelpMethod(out commandDescriptor);
}
@@ -294,7 +294,7 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
{
if (optionByIndex.Count <= option.Index)
{
if (!item.HasDefaultValue())
if (!item.HasDefaultValue)
{
throw new InvalidOperationException($"Required argument {option.Index} was not found in specified arguments.");
}
@@ -346,20 +346,13 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
var elemType = UnwrapCollectionElementType(parameters[i].ParameterType);
if (elemType == typeof(string))
{
if (parameters.Length == i + 1)
{
v = "[" + string.Join(",", optionByIndex.Skip(parameters[i].Position).Select(x => "\"" + x.Value + "\"")) + "]";
if (!(v.StartsWith("\"") && v.EndsWith("\"")))
{
v = "[" + string.Join(",", v.Split(' ', ',').Select(x => "\"" + x + "\"")) + "]";
}
else
{
if (!(v.StartsWith("\"") && v.EndsWith("\"")))
{
v = "[" + string.Join(",", v.Split(' ', ',').Select(x => "\"" + x + "\"")) + "]";
}
else
{
v = "[" + v + "]";
}
{
v = "[" + v + "]";
}
}
else
@@ -408,9 +401,9 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
}
}

if (item.HasDefaultValue())
if (item.HasDefaultValue)
{
invokeArgs[i] = item.DefaultValue();
invokeArgs[i] = item.DefaultValue;
}
else if (item.ParameterType == typeof(bool))
{
18 changes: 0 additions & 18 deletions src/ConsoleAppFramework/ParameterInfoExtensions.cs

This file was deleted.

0 comments on commit 57240a5

Please sign in to comment.