Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions sandbox/CliFrameworkBenchmark/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ValueTask<int> ExecuteWithCliFx()
[Benchmark(Description = "System.CommandLine")]
public int ExecuteWithSystemCommandLine()
{
return SystemCommandLineCommand.Execute(Arguments);
return new SystemCommandLineCommand().Execute(Arguments);
}

//[Benchmark(Description = "McMaster.Extensions.CommandLineUtils")]
Expand Down Expand Up @@ -71,7 +71,7 @@ public int ExecuteWithSystemCommandLine()
[Benchmark(Description = "ConsoleAppFramework v5", Baseline = true)]
public unsafe void ExecuteConsoleAppFramework()
{
ConsoleApp.Run(Arguments, &ConsoleAppFrameworkCommand.Execute);
ConsoleApp.Run(Arguments, &ConsoleAppFrameworkCommandWithCancellationToken.Execute);
}

// for alpha testing
Expand Down
7 changes: 3 additions & 4 deletions sandbox/CliFrameworkBenchmark/CliFrameworkBenchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
<PackageReference Include="CliFx" Version="2.3.6" />
<PackageReference Include="clipr" Version="1.6.1" />
<PackageReference Include="Cocona" Version="2.2.0" />
Expand All @@ -25,9 +25,8 @@
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="PowerArgs" Version="4.0.3" />
<PackageReference Include="Spectre.Console.Cli" Version="0.50.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta5.25306.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta5.25306.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.53.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class Settings : CommandSettings
public bool boolOption { get; init; }
}

public override int Execute(CommandContext context, Settings settings)
public override int Execute(CommandContext context, Settings settings, CancellationToken cancellationToken)
{
return 0;
}
Expand Down
47 changes: 13 additions & 34 deletions sandbox/CliFrameworkBenchmark/Commands/SystemCommandLineCommand.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
using System.CommandLine;
using System.CommandLine.NamingConventionBinder;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.CommandLine;

namespace Cocona.Benchmark.External.Commands;

public class SystemCommandLineCommand
{
public static int ExecuteHandler(string s, int i, bool b) => 0;

public static int Execute(string[] args)
public int Execute(string[] args)
{
var command = new RootCommand
{
new Option<string?>("--str", ["-s"]),
new Option<int>("--int", ["-i"]),
new Option<bool>("--bool", ["-b"]),
};
var stringOption = new Option<string>("--str", "-s");
var intOption = new Option<int>("--int", "-i");
var boolOption = new Option<bool>("--bool", "-b");

command.SetAction(parseResult =>
{
var handler = CommandHandler.Create(ExecuteHandler);
return handler.InvokeAsync(parseResult);
});
var command = new RootCommand { stringOption, intOption, boolOption };

ParseResult parseResult = command.Parse(args);
return parseResult.Invoke();
}

public static Task<int> ExecuteAsync(string[] args)
{
var command = new RootCommand
{
new Option<string?>("--str", ["-s"]),
new Option<int>("--int", ["-i"]),
new Option<bool>("--bool", ["-b"]),
};

command.SetAction((parseResult, cancellationToken) =>
command.SetAction(parseResult =>
{
var handler = CommandHandler.Create(ExecuteHandler);
return handler.InvokeAsync(parseResult);
_ = parseResult.GetValue(stringOption);
_ = parseResult.GetValue(intOption);
_ = parseResult.GetValue(boolOption);
});

ParseResult parseResult = command.Parse(args);
return parseResult.InvokeAsync();
return command.Parse(args).Invoke();
}
}