-
Notifications
You must be signed in to change notification settings - Fork 402
Separate parse from invocation configurations #2606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bf132ef
58b691e
932fea1
8167444
92b00cd
8685f9d
1737e33
5d2c622
937491a
997cebe
2c6d6a3
9bfecf6
1f37d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<SolutionConfiguration> | ||
<Settings> | ||
<AllowParallelTestExecution>True</AllowParallelTestExecution> | ||
<CustomBuildProperties> | ||
<Value>TargetFrameworks = net8.0</Value> | ||
<Value>TargetFramework = net8.0</Value> | ||
</CustomBuildProperties> | ||
<EnableRDI>False</EnableRDI> | ||
<RdiConfigured>True</RdiConfigured> | ||
<SolutionConfigured>True</SolutionConfigured> | ||
</Settings> | ||
</SolutionConfiguration> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,31 +49,13 @@ | |
public System.Void Add(Option option) | ||
public System.Void Add(Command command) | ||
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context) | ||
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, CommandLineConfiguration configuration = null) | ||
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null) | ||
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, ParserConfiguration configuration = null) | ||
public ParseResult Parse(System.String commandLine, ParserConfiguration configuration = null) | ||
public System.Void SetAction(System.Action<ParseResult> action) | ||
public System.Void SetAction(System.Func<ParseResult,System.Int32> action) | ||
public System.Void SetAction(System.Func<ParseResult,System.Threading.CancellationToken,System.Threading.Tasks.Task> action) | ||
public System.Void SetAction(System.Func<ParseResult,System.Threading.Tasks.Task> action) | ||
public System.Void SetAction(System.Func<ParseResult,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Int32>> action) | ||
public class CommandLineConfiguration | ||
.ctor(Command rootCommand) | ||
public System.Boolean EnableDefaultExceptionHandler { get; set; } | ||
public System.Boolean EnablePosixBundling { get; set; } | ||
public System.IO.TextWriter Error { get; set; } | ||
public System.IO.TextWriter Output { get; set; } | ||
public System.Nullable<System.TimeSpan> ProcessTerminationTimeout { get; set; } | ||
public System.CommandLine.Parsing.TryReplaceToken ResponseFileTokenReplacer { get; set; } | ||
public Command RootCommand { get; } | ||
public System.Int32 Invoke(System.String commandLine) | ||
public System.Int32 Invoke(System.String[] args) | ||
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String commandLine, System.Threading.CancellationToken cancellationToken = null) | ||
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.String[] args, System.Threading.CancellationToken cancellationToken = null) | ||
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args) | ||
public ParseResult Parse(System.String commandLine) | ||
public System.Void ThrowIfInvalid() | ||
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable | ||
.ctor(System.String message) | ||
public static class CompletionSourceExtensions | ||
public static System.Void Add(this System.Collections.Generic.List<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate) | ||
public static System.Void Add(this System.Collections.Generic.List<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.String[] completions) | ||
|
@@ -88,6 +70,12 @@ | |
public class EnvironmentVariablesDirective : Directive | ||
.ctor() | ||
public System.CommandLine.Invocation.CommandLineAction Action { get; set; } | ||
public class InvocationConfiguration | ||
.ctor() | ||
public System.Boolean EnableDefaultExceptionHandler { get; set; } | ||
public System.IO.TextWriter Error { get; set; } | ||
public System.IO.TextWriter Output { get; set; } | ||
public System.Nullable<System.TimeSpan> ProcessTerminationTimeout { get; set; } | ||
public abstract class Option : Symbol | ||
public System.CommandLine.Invocation.CommandLineAction Action { get; set; } | ||
public System.Collections.Generic.ICollection<System.String> Aliases { get; } | ||
|
@@ -115,11 +103,19 @@ | |
public static Option<System.IO.DirectoryInfo> AcceptExistingOnly(this Option<System.IO.DirectoryInfo> option) | ||
public static Option<System.IO.FileSystemInfo> AcceptExistingOnly(this Option<System.IO.FileSystemInfo> option) | ||
public static Option<T> AcceptExistingOnly<T>(this Option<T> option) | ||
public class ParserConfiguration | ||
.ctor() | ||
public System.Boolean EnablePosixBundling { get; set; } | ||
public System.CommandLine.Parsing.TryReplaceToken ResponseFileTokenReplacer { get; set; } | ||
public System.Void ThrowIfInvalid(Command command) | ||
public class ParserConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable | ||
.ctor(System.String message) | ||
public class ParseResult | ||
public System.CommandLine.Invocation.CommandLineAction Action { get; } | ||
public System.CommandLine.Parsing.CommandResult CommandResult { get; } | ||
public CommandLineConfiguration Configuration { get; } | ||
public ParserConfiguration Configuration { get; } | ||
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.ParseError> Errors { get; } | ||
public InvocationConfiguration InvocationConfiguration { get; } | ||
public System.CommandLine.Parsing.CommandResult RootCommandResult { get; } | ||
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.Token> Tokens { get; } | ||
public System.Collections.Generic.IReadOnlyList<System.String> UnmatchedTokens { get; } | ||
|
@@ -138,7 +134,9 @@ | |
public T GetValue<T>(Option<T> option) | ||
public T GetValue<T>(System.String name) | ||
public System.Int32 Invoke() | ||
public System.Int32 Invoke(InvocationConfiguration configuration) | ||
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.Threading.CancellationToken cancellationToken = null) | ||
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(InvocationConfiguration configuration, System.Threading.CancellationToken cancellationToken = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or should we change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If consistency is important here, another reason we might consider consolidating by splitting out Parse into two overloads ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I strongly believe that we should not do that. IIRC this shape was approved in the API Design, it would be another breaking change and also another public API. Last, but not least my goal with exposing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is very good point. However, from my observation it seems that users hardly ever provide |
||
public System.String ToString() | ||
public class RootCommand : Command, System.Collections.IEnumerable | ||
public static System.String ExecutableName { get; } | ||
|
@@ -212,8 +210,8 @@ System.CommandLine.Parsing | |
public System.Void OnlyTake(System.Int32 numberOfTokens) | ||
public System.String ToString() | ||
public static class CommandLineParser | ||
public static System.CommandLine.ParseResult Parse(System.CommandLine.Command command, System.Collections.Generic.IReadOnlyList<System.String> args, System.CommandLine.CommandLineConfiguration configuration = null) | ||
public static System.CommandLine.ParseResult Parse(System.CommandLine.Command command, System.String commandLine, System.CommandLine.CommandLineConfiguration configuration = null) | ||
public static System.CommandLine.ParseResult Parse(System.CommandLine.Command command, System.Collections.Generic.IReadOnlyList<System.String> args, System.CommandLine.ParserConfiguration configuration = null) | ||
public static System.CommandLine.ParseResult Parse(System.CommandLine.Command command, System.String commandLine, System.CommandLine.ParserConfiguration configuration = null) | ||
public static System.Collections.Generic.IEnumerable<System.String> SplitCommandLine(System.String commandLine) | ||
public class CommandResult : SymbolResult | ||
public System.Collections.Generic.IEnumerable<SymbolResult> Children { get; } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost forgot about #1909. Should we simply remove this custom exception type and throw something defined by the BCL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought. I'd love suggestions on what would be an appropriate exception type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KalleOlaviNiemitalo has a very good breakdown here: #1909 (comment)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InvalidOperationException
would be my best bet for now.Or... even just removing
ThrowIfInvalid
? We don't use it anywhere outside of tests and it can be implemented with the public APIs we provide. It's also a bit confusing that it's part of theConfig
class, while what it does it checks the symbol hierarchy (andRootCommand
is no longer part of the config)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this suggestion. This method has always been awkward.
We used to do this validation at runtime. Then we decided it was too performance-intensive so we said it should be used only in tests. My worry has been that people will assume the parser will catch these kinds of mistakes automatically, and it's not intuitive to implement some of the checks. (And I'm pretty sure we missed some cases.) Of course, ASP.NET left the analogous issue (routing validation) as an exercise for the user, so probably System.CommandLine should do the same.