Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge remote-tracking branch 'upstream/main' into directives
# Conflicts:
#	src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt
#	src/System.CommandLine.Tests/DirectiveTests.cs
#	src/System.CommandLine/Parsing/StringExtensions.cs
#	src/System.CommandLine/Parsing/SymbolResultExtensions.cs
  • Loading branch information
adamsitnik committed Mar 7, 2023
commit 8f16b15e1140c59639ae6682085908c482a94d23
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ System.CommandLine
public static System.Void Write(this IConsole console, System.String value)
public static System.Void WriteLine(this IConsole console, System.String value)
public class Directive : Symbol
.ctor(System.String name, System.String description = null, System.Action<System.CommandLine.Invocation.InvocationContext> syncHandler = null, System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> asyncHandler = null)
.ctor(System.String name, System.Action<System.CommandLine.Invocation.InvocationContext> syncHandler = null, System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> asyncHandler = null)
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.Void SetAsynchronousHandler(System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> handler)
public System.Void SetSynchronousHandler(System.Action<System.CommandLine.Invocation.InvocationContext> handler)
Expand Down Expand Up @@ -342,6 +342,7 @@ System.CommandLine.Parsing
public System.Collections.Generic.IEnumerable<SymbolResult> Children { get; }
public System.CommandLine.Command Command { get; }
public Token Token { get; }
public System.String ToString()
public class DirectiveResult : SymbolResult
public System.CommandLine.Directive Directive { get; }
public Token Token { get; }
Expand Down
22 changes: 1 addition & 21 deletions src/System.CommandLine/Directive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.CommandLine.Invocation;
using System.Threading.Tasks;
using System.Threading;
using System.CommandLine.Parsing;

namespace System.CommandLine
{
Expand All @@ -22,30 +21,13 @@ public class Directive : Symbol
/// Initializes a new instance of the Directive class.
/// </summary>
/// <param name="name">The name of the directive. It can't contain whitespaces.</param>
/// <param name="description">The description of the directive, shown in help.</param>
/// <param name="syncHandler">The synchronous action that is invoked when directive is parsed.</param>
/// <param name="asyncHandler">The asynchronous action that is invoked when directive is parsed.</param>
public Directive(string name,
string? description = null,
Action<InvocationContext>? syncHandler = null,
Func<InvocationContext, CancellationToken, Task>? asyncHandler = null)
: base(name)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("Name cannot be null, empty, or consist entirely of whitespace.");
}

for (var i = 0; i < name.Length; i++)
{
if (char.IsWhiteSpace(name[i]))
{
throw new ArgumentException($"Name cannot contain whitespace: \"{name}\"", nameof(name));
}
}

Name = name;
Description = description;

if (syncHandler is not null)
{
SetSynchronousHandler(syncHandler);
Expand Down Expand Up @@ -78,8 +60,6 @@ public void SetSynchronousHandler(Action<InvocationContext> handler)

internal ICommandHandler? Handler { get; private set; }

private protected override string DefaultName => throw new NotImplementedException();

public override IEnumerable<CompletionItem> GetCompletions(CompletionContext context)
=> Array.Empty<CompletionItem>();
}
Expand Down
7 changes: 1 addition & 6 deletions src/System.CommandLine/Parsing/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,7 @@ private static Dictionary<string, Token> ValidTokens(this Command command, IRead
}
}

foreach (string commandAlias in command.Aliases)
{
tokens.Add(
commandAlias,
new Token(commandAlias, TokenType.Command, command, Token.ImplicitPosition));
}
AddCommandTokens(tokens, command);

if (command.HasSubcommands)
{
Expand Down
15 changes: 0 additions & 15 deletions src/System.CommandLine/Parsing/SymbolResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,5 @@ internal static IEnumerable<SymbolResult> AllSymbolResults(this CommandResult co
}
}

internal static Token Token(this SymbolResult symbolResult)
{
return symbolResult switch
{
CommandResult commandResult => commandResult.Token,
OptionResult optionResult => optionResult.Token ?? CreateImplicitToken(optionResult.Option),
DirectiveResult directiveResult => directiveResult.Token,
_ => throw new ArgumentOutOfRangeException(nameof(symbolResult))
};

static Token CreateImplicitToken(Option option)
{
return new Token(option.GetLongestAlias(removePrefix: false), TokenType.Option, option, Parsing.Token.ImplicitPosition);
}
}
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.