Skip to content

Commit b541d80

Browse files
committed
Version 2.7.0
- Updated to version 2.0.0-beta7.25380.108 of System.CommandLine.
1 parent c5bb3b4 commit b541d80

File tree

120 files changed

+150
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+150
-158
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<!-- https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#generateassemblyinfo -->
5-
<VersionPrefix>2.6.8</VersionPrefix>
5+
<VersionPrefix>2.7.0</VersionPrefix>
66
<Product>DotMake Command-Line</Product>
77
<Company>DotMake</Company>
88
<!-- Copyright is also used for NuGet metadata -->

src/DotMake.CommandLine/CliContext.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public CliContext(CliBindingContext bindingContext, ParseResult parseResult, Can
3030
Result = new CliResult(bindingContext, parseResult);
3131
this.parseResult = parseResult;
3232

33-
Output = parseResult.Configuration.Output;
34-
Error = parseResult.Configuration.Error;
33+
Output = parseResult.InvocationConfiguration.Output;
34+
Error = parseResult.InvocationConfiguration.Error;
3535
CancellationToken = cancellationToken;
3636
}
3737

@@ -100,25 +100,23 @@ public void ShowHelp()
100100
/// </summary>
101101
public void ShowValues()
102102
{
103-
var output = parseResult.Configuration.Output;
104-
105103
var command = parseResult.CommandResult.Command;
106104
var isRoot = (command.Parents.FirstOrDefault() == null);
107105
var bindingContext = new CliBindingContext();
108106

109-
output.WriteLine($"Command = \"{command.Name}\" [{(isRoot ? "Root command" : "Sub-command")}]");
107+
Output.WriteLine($"Command = \"{command.Name}\" [{(isRoot ? "Root command" : "Sub-command")}]");
110108

111109
foreach (var symbolResult in parseResult.CommandResult.Children)
112110
{
113111
if (symbolResult is ArgumentResult argumentResult)
114112
{
115113
var value = bindingContext.GetValue(parseResult, argumentResult.Argument);
116-
output.WriteLine($"Argument '{argumentResult.Argument.Name}' = {CliStringUtil.FormatValue(value)}");
114+
Output.WriteLine($"Argument '{argumentResult.Argument.Name}' = {CliStringUtil.FormatValue(value)}");
117115
}
118116
else if (symbolResult is OptionResult optionResult)
119117
{
120118
var value = bindingContext.GetValue(parseResult, optionResult.Option);
121-
output.WriteLine($"Option '{optionResult.Option.Name}' = {CliStringUtil.FormatValue(value)}");
119+
Output.WriteLine($"Option '{optionResult.Option.Name}' = {CliStringUtil.FormatValue(value)}");
122120
}
123121
}
124122
}
@@ -130,7 +128,7 @@ public void ShowValues()
130128
public void ShowHierarchy(bool showLevel = false)
131129
{
132130
var theme = GetThemeOrDefault();
133-
var rootCommand = parseResult.Configuration.RootCommand;
131+
var rootCommand = parseResult.RootCommandResult.Command;
134132

135133
foreach (var command in GetParentTree(rootCommand))
136134
{

src/DotMake.CommandLine/CliParser.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class CliParser
1919
{
2020
private readonly CliBindingContext bindingContext = new();
2121
private readonly CliSettings settings;
22-
private readonly CommandLineConfiguration configuration;
22+
private readonly ParserConfiguration parserConfiguration;
23+
private readonly InvocationConfiguration invocationConfiguration;
2324

2425
internal CliParser(Type definitionType, CliSettings settings = null)
2526
{
@@ -31,17 +32,21 @@ internal CliParser(Type definitionType, CliSettings settings = null)
3132

3233
Command = command;
3334

34-
configuration = new CommandLineConfiguration(command)
35+
parserConfiguration = new ParserConfiguration
3536
{
3637
EnablePosixBundling = settings.EnablePosixBundling,
38+
ResponseFileTokenReplacer = settings.ResponseFileTokenReplacer
39+
};
40+
41+
invocationConfiguration = new InvocationConfiguration
42+
{
3743
EnableDefaultExceptionHandler = settings.EnableDefaultExceptionHandler,
3844
ProcessTerminationTimeout = settings.ProcessTerminationTimeout,
39-
ResponseFileTokenReplacer = settings.ResponseFileTokenReplacer
4045
};
4146
if (settings.Output != null) //Console.Out is NOT being used
42-
configuration.Output = settings.Output;
47+
invocationConfiguration.Output = settings.Output;
4348
if (settings.Error != null) //Console.Error is NOT being used
44-
configuration.Error = settings.Error;
49+
invocationConfiguration.Error = settings.Error;
4550

4651
if (rootCommand != null)
4752
{
@@ -121,7 +126,7 @@ internal CliParser(Type definitionType, CliSettings settings = null)
121126
*/
122127
public CliResult Parse(string[] args = null)
123128
{
124-
var parseResult = configuration.Parse(FixArgs(args) ?? GetArgs());
129+
var parseResult = Command.Parse(FixArgs(args) ?? GetArgs(), parserConfiguration);
125130
return new CliResult(bindingContext, parseResult);
126131
}
127132

@@ -137,7 +142,7 @@ public CliResult Parse(string[] args = null)
137142
*/
138143
public CliResult Parse(string commandLine)
139144
{
140-
var parseResult = configuration.Parse(commandLine);
145+
var parseResult = Command.Parse(commandLine, parserConfiguration);
141146
return new CliResult(bindingContext, parseResult);
142147
}
143148

@@ -156,7 +161,8 @@ public CliResult Parse(string commandLine)
156161
public int Run(string[] args = null)
157162
{
158163
using (new CliSession(settings))
159-
return configuration.Invoke(FixArgs(args) ?? GetArgs());
164+
return Command.Parse(FixArgs(args) ?? GetArgs(), parserConfiguration)
165+
.Invoke(invocationConfiguration);
160166
}
161167

162168
/// <summary>
@@ -173,7 +179,8 @@ public int Run(string[] args = null)
173179
public int Run(string commandLine)
174180
{
175181
using (new CliSession(settings))
176-
return configuration.Invoke(commandLine);
182+
return Command.Parse(commandLine, parserConfiguration)
183+
.Invoke(invocationConfiguration);
177184
}
178185

179186
/// <summary>
@@ -191,7 +198,8 @@ public int Run(string commandLine)
191198
public async Task<int> RunAsync(string[] args = null, CancellationToken cancellationToken = default)
192199
{
193200
using (new CliSession(settings))
194-
return await configuration.InvokeAsync(FixArgs(args) ?? GetArgs(), cancellationToken);
201+
return await Command.Parse(FixArgs(args) ?? GetArgs(), parserConfiguration)
202+
.InvokeAsync(invocationConfiguration, cancellationToken);
195203
}
196204

197205
/// <summary>
@@ -209,7 +217,8 @@ public async Task<int> RunAsync(string[] args = null, CancellationToken cancella
209217
public async Task<int> RunAsync(string commandLine, CancellationToken cancellationToken = default)
210218
{
211219
using (new CliSession(settings))
212-
return await configuration.InvokeAsync(commandLine, cancellationToken);
220+
return await Command.Parse(commandLine, parserConfiguration)
221+
.InvokeAsync(invocationConfiguration, cancellationToken);
213222
}
214223

215224

@@ -267,7 +276,7 @@ private sealed class VersionOptionAction : SynchronousCommandLineAction
267276
{
268277
public override int Invoke(ParseResult parseResult)
269278
{
270-
parseResult.Configuration.Output.WriteLine(ExecutableInfo.Version);
279+
parseResult.InvocationConfiguration.Output.WriteLine(ExecutableInfo.Version);
271280
return 0;
272281
}
273282
}

src/DotMake.CommandLine/CliSettings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public class CliSettings
1616
/// </summary>
1717
/// <param name="value"><see langword="true" /> to parse POSIX bundles; otherwise, <see langword="false" />.</param>
1818
/// <remarks>
19-
/// POSIX conventions recommend that single-character options be allowed to be specified together after a single <c>-</c> prefix. When <see cref="P:System.CommandLine.CliConfiguration.EnablePosixBundling" /> is set to <see langword="true" />, the following command lines are equivalent:
19+
/// POSIX conventions recommend that single-character options be allowed to be specified together after a single <c>-</c> prefix. When <see cref="EnablePosixBundling" /> is set to <see langword="true" />, the following command lines are equivalent:
2020
///
2121
/// <code>
2222
/// &gt; myapp -a -b -c
2323
/// &gt; myapp -abc
2424
/// </code>
2525
///
2626
/// If an argument is provided after an option bundle, it applies to the last option in the bundle.
27-
/// When <see cref="P:System.CommandLine.CliConfiguration.EnablePosixBundling" /> is set to <see langword="true" />,
27+
/// When <see cref="EnablePosixBundling" /> is set to <see langword="true" />,
2828
/// all of the following command lines are equivalent:
2929
/// <code>
3030
/// &gt; myapp -a -b -c arg
@@ -65,7 +65,7 @@ public class CliSettings
6565

6666
/// <summary>
6767
/// Enables signaling and handling of process termination (Ctrl+C, SIGINT, SIGTERM) via a <see cref="T:System.Threading.CancellationToken" />
68-
/// that can be passed to a <see cref="T:System.CommandLine.Invocation.CliAction" /> during invocation.
68+
/// that can be passed to a <see cref="T:System.CommandLine.Invocation.CommandLineAction" /> during invocation.
6969
/// If not provided, a default timeout of 2 seconds is enforced.
7070
/// </summary>
7171
public TimeSpan? ProcessTerminationTimeout { get; set; } = TimeSpan.FromSeconds(2.0);
@@ -78,7 +78,7 @@ public class CliSettings
7878
/// When enabled, any token prefixed with <c>@</c> can be replaced with zero or more other tokens.
7979
/// This is mostly commonly used to expand tokens from response files and interpolate them into a command line prior to parsing.
8080
/// </remarks>
81-
public TryReplaceToken ResponseFileTokenReplacer { get; set; } = DefaultConfiguration.ResponseFileTokenReplacer;
81+
public TryReplaceToken ResponseFileTokenReplacer { get; set; } = DefaultParserConfiguration.ResponseFileTokenReplacer;
8282

8383
/// <summary>
8484
/// Gets or sets the standard output. Used by Help and other facilities that write non-error information.
@@ -102,6 +102,6 @@ public class CliSettings
102102
/// </summary>
103103
public CliTheme Theme { get; set; } = CliTheme.Default;
104104

105-
private static readonly CommandLineConfiguration DefaultConfiguration = new CommandLineConfiguration(new RootCommand());
105+
private static readonly ParserConfiguration DefaultParserConfiguration = new ();
106106
}
107107
}

src/DotMake.CommandLine/DotMake.CommandLine.csproj

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,7 @@
2121
<PackageTags>command-line CLI console System.CommandLine declarative attributes parsing command argument option generator</PackageTags>
2222
<PackageReleaseNotes>
2323
<![CDATA[
24-
- Added: `Command` and `RootCommand` properties to `CliParser` class:
25-
```c#
26-
var parser = Cli.GetParser<RootCliCommand>();
27-
28-
//Access the command that is used to parse the command line input.
29-
var command = parser.Command;
30-
31-
//Access the root of the command that is used to parse the command line input.
32-
//If parser.Command is already a root command, this will be same instance.
33-
//If it's a sub-command, it will be the root of that sub-command.
34-
var rootCommand = parser.RootCommand;
35-
```
36-
37-
- Fixed: SourceGenerator sometimes triggers a concurrency exception. Use `ConcurrentDictionary` for `GenerationCounts`.
38-
39-
- Fixed: Do not add auto name or alias for root commands as it can unnecessarily conflict with children.
24+
- Updated to version 2.0.0-beta7.25380.108 of System.CommandLine.
4025
]]>
4126
</PackageReleaseNotes>
4227
</PropertyGroup>
@@ -45,7 +30,7 @@
4530

4631
<ItemGroup>
4732
<!-- use exact version match with [] for now as future beta versions can break API -->
48-
<PackageReference Include="System.CommandLine" Version="[2.0.0-beta6.25358.103]" />
33+
<PackageReference Include="System.CommandLine" Version="[2.0.0-beta7.25380.108]" />
4934

5035
<!--
5136
UPDATE: No longer using this as now 2.0.0-beta5.25306.1 is released to official nuget feed.

src/DotMake.CommandLine/Help/CustomHelpAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public HelpBuilder Builder
2525
/// <inheritdoc />
2626
public override int Invoke(ParseResult parseResult)
2727
{
28-
var output = parseResult.Configuration.Output;
28+
var output = parseResult.InvocationConfiguration.Output;
2929

3030
var helpContext = new HelpContext(Builder,
3131
parseResult.CommandResult.Command,

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/(ModuleInitializerAttribute).g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.6.8.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.7.0.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
44
// Generation: 1
55

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/(RequiredMemberAttribute).g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.6.8.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.7.0.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
44
// Generation: 1
55

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/ArgumentConverterCliCommandBuilder-3j0trcm.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.6.8.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.7.0.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
44
// Generation: 1
55

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/CamelCaseCliCommandBuilder-2ntm48g.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.6.8.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.7.0.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
44
// Generation: 1
55

0 commit comments

Comments
 (0)