mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Add token representation to remaining arguments
Before, when adding parsed information to the IRemainingArguments.Parsed, we used the name of the parsed option ('foo') instead of it's representation ('--foo'). This commit fixes that.
This commit is contained in:

committed by
Patrik Svensson

parent
95bff47b85
commit
71f762f646
@ -302,11 +302,7 @@ internal class CommandTreeParser
|
||||
var valueToken = stream.Peek();
|
||||
if (valueToken?.TokenKind == CommandTreeToken.Kind.String)
|
||||
{
|
||||
var parseValue = true;
|
||||
if (token.TokenKind == CommandTreeToken.Kind.ShortOption && token.IsGrouped)
|
||||
{
|
||||
parseValue = false;
|
||||
}
|
||||
bool parseValue = token is not { TokenKind: CommandTreeToken.Kind.ShortOption, IsGrouped: true };
|
||||
|
||||
if (context.State == State.Normal && parseValue)
|
||||
{
|
||||
@ -333,7 +329,7 @@ internal class CommandTreeParser
|
||||
{
|
||||
value = stream.Consume(CommandTreeToken.Kind.String)?.Value;
|
||||
|
||||
context.AddRemainingArgument(token.Value, value);
|
||||
context.AddRemainingArgument(token.Representation, value);
|
||||
|
||||
// Prevent the option and it's non-boolean value from being added to
|
||||
// mapped parameters (otherwise an exception will be thrown later
|
||||
@ -364,14 +360,14 @@ internal class CommandTreeParser
|
||||
// In relaxed parsing mode?
|
||||
if (context.ParsingMode == ParsingMode.Relaxed)
|
||||
{
|
||||
context.AddRemainingArgument(token.Value, value);
|
||||
context.AddRemainingArgument(token.Representation, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.AddRemainingArgument(token.Value, parseValue ? valueToken.Value : null);
|
||||
context.AddRemainingArgument(token.Representation, parseValue ? valueToken.Value : null);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -379,7 +375,7 @@ internal class CommandTreeParser
|
||||
if (parameter == null && // Only add tokens which have not been matched to a command parameter
|
||||
(context.State == State.Remaining || context.ParsingMode == ParsingMode.Relaxed))
|
||||
{
|
||||
context.AddRemainingArgument(token.Value, null);
|
||||
context.AddRemainingArgument(token.Representation, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ internal static class CommandTreeTokenizer
|
||||
}
|
||||
|
||||
// Encountered a separator?
|
||||
if (current == '=' || current == ':')
|
||||
if (current is '=' or ':')
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -184,7 +184,7 @@ internal static class CommandTreeTokenizer
|
||||
var value = current.ToString(CultureInfo.InvariantCulture);
|
||||
result.Add(result.Count == 0
|
||||
? new CommandTreeToken(CommandTreeToken.Kind.ShortOption, position, value, $"-{value}")
|
||||
: new CommandTreeToken(CommandTreeToken.Kind.ShortOption, position + result.Count, value, value));
|
||||
: new CommandTreeToken(CommandTreeToken.Kind.ShortOption, position + result.Count, value, $"-{value}"));
|
||||
}
|
||||
else if (result.Count == 0 && char.IsDigit(current))
|
||||
{
|
||||
|
Reference in New Issue
Block a user