Skip to content

Commit 8e28d56

Browse files
committed
Update to 2.0.0-beta4.25072.1 and fix class name changes
- Updated to latest daily build 2.0.0-beta4.25072.1 of System.CommandLine. - Fixed: New naming convention of classes from System.CommandLine (they dropped `Cli` prefix from symbol classes and replaced it with `CommandLine` for other classes). - Changed: Nuget framework targets from `net7.0;netstandard2.0` to `net8.0;netstandard2.0` as underlying System.CommandLine package did so. `net7.0` project can still use `netstandard2.0` target. - Added: We now include a MSBuild .props file in the nuget package so referencing projects that do not explicitly set SatelliteResourceLanguages property, will be considered using "en" by default: Prevent satellite resource DLL pollution (which come from System.CommandLine package) in bin folder, by setting a specific culture in referencing project, if not already set. Empty value (default) for SatelliteResourceLanguages property causes copying of all culture subfolders and DLLs to bin folder, so we opt for "en" culture by default, to prevent copying of satellite resource DLLs. - Fixed: Referencing DotMake.CommandLine DLL instead of project in DotMake.CommandLine.SourceGeneration.Embedded project, does not work well, especially if you Clean and Build (or for first build) you get reference errors as DotMake.CommandLine.dll is not yet produced, so better to use project reference but only from this project (to avoid circular dependency). Ensure that the .Embedded project is built after DotMake.CommandLine project only for checking compile errors, otherwise .cs files are only embedded as resource in DotMake.CommandLine.SourceGeneration.dll.
1 parent ce91dcf commit 8e28d56

File tree

243 files changed

+1444
-8030
lines changed

Some content is hidden

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

243 files changed

+1444
-8030
lines changed

docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ PM> Install-Package DotMake.CommandLine
3636

3737
### Prerequisites
3838

39-
- .NET 7.0 and later project or .NET Standard 2.0 and later project.
40-
Note that .NET Framework 4.7.2+ or .NET Core 2.0 to NET 6.0 projects can reference our netstandard2.0 target (automatic in nuget).
39+
- .NET 8.0 and later project or .NET Standard 2.0 and later project.
40+
Note that .NET Framework 4.7.2+ or .NET Core 2.0 to NET 7.0 projects can reference our netstandard2.0 target (automatic in nuget).
4141
If your target framework is below net5.0, you also need `<LangVersion>9.0</LangVersion>` tag (minimum) in your .csproj file.
4242
- Visual Studio 2022 v17.3+ or .NET SDK 6.0.407+ (when building via `dotnet` cli).
4343
Our incremental source generator requires performance features added first in these versions.
@@ -198,7 +198,7 @@ And that's it! You now have a fully working command-line app.
198198
## Help output
199199

200200
When you run the app via
201-
- `TestApp.exe -?` in project output path (e.g. in `TestApp\bin\Debug\net7.0`)
201+
- `TestApp.exe -?` in project output path (e.g. in `TestApp\bin\Debug\net8.0`)
202202
- or `dotnet run -- -?` in project directory (e.g. in `TestApp`) (note the double hyphen/dash which allows `dotnet run` to pass arguments to our actual application)
203203

204204
- You see this usage help:
@@ -1168,7 +1168,7 @@ Cli.Run<RootCliCommand>();
11681168

11691169
## Response files
11701170

1171-
A *response file* is a file that contains a set of [tokens](syntax.md#tokens) for a command-line app. Response files are a feature of `System.CommandLine` that is useful in two scenarios:
1171+
A *response file* is a file that contains a set of tokens for a command-line app. Response files are a feature of `System.CommandLine` that is useful in two scenarios:
11721172

11731173
* To invoke a command-line app by specifying input that is longer than the character limit of the terminal.
11741174
* To invoke the same command repeatedly without retyping the whole line.

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>1.8.8</VersionPrefix>
5+
<VersionPrefix>1.9.0</VersionPrefix>
66
<Product>DotMake Command-Line</Product>
77
<Company>DotMake</Company>
88
<!-- Copyright is also used for NuGet metadata -->

src/DotMake.CommandLine.SourceGeneration.Embedded/DotMake.CommandLine.SourceGeneration.Embedded.csproj

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0;netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
55
<!-- Make sure it compiles for lowest supported LangVersion 9.0 as source may be generated in a netstandard2.0 project -->
66
<LangVersion>9.0</LangVersion>
77
</PropertyGroup>
@@ -14,11 +14,26 @@
1414
<!--
1515
Code should compile against DotMake.CommandLine.dll (not project due to circular dependency),
1616
which will be available during runtime.
17-
-->
17+
$(OutputPath) will be same as bin\$(Configuration)\$(TargetFramework)\
18+
$(IntermediateOutputPath) will be same as obj\$(Configuration)\$(TargetFramework)\
19+
20+
This does not work well, especially if you Clean and Build (or for first build) you get reference errors
21+
as DotMake.CommandLine.dll is not yet produced, so better to use project reference but only from this project.
22+
1823
<Reference Include="DotMake.CommandLine">
1924
<HintPath>..\DotMake.CommandLine\$(OutputPath)DotMake.CommandLine.dll</HintPath>
2025
<Private>false</Private>
2126
</Reference>
27+
-->
28+
<!--
29+
Ensure that the .Embedded project is built after DotMake.CommandLine project only for checking compile errors,
30+
otherwise .cs files are only embedded as resource in DotMake.CommandLine.SourceGeneration.dll
31+
-->
32+
<ProjectReference Include="..\DotMake.CommandLine\DotMake.CommandLine.csproj">
33+
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
34+
<Private>false</Private>
35+
</ProjectReference>
36+
2237
</ItemGroup>
2338

2439
</Project>

src/DotMake.CommandLine.SourceGeneration/CliArgumentInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CliArgumentInfo : CliSymbolInfo, IEquatable<CliArgumentInfo>
1111
{
1212
public static readonly string AttributeFullName = typeof(CliArgumentAttribute).FullName;
1313
public static readonly string[] Suffixes = CliCommandInfo.Suffixes.Select(s => s + "Argument").Append("Argument").ToArray();
14-
public const string ArgumentClassName = "CliArgument";
14+
public const string ArgumentClassName = "Argument";
1515
public const string ArgumentClassNamespace = "System.CommandLine";
1616
public const string ArgumentArityClassName = "ArgumentArity";
1717
public const string DiagnosticName = "CLI argument";

src/DotMake.CommandLine.SourceGeneration/CliCommandInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class CliCommandInfo : CliSymbolInfo, IEquatable<CliCommandInfo>
1212
{
1313
public static readonly string AttributeFullName = typeof(CliCommandAttribute).FullName;
1414
public static readonly string[] Suffixes = { "RootCliCommand", "RootCommand", "SubCliCommand", "SubCommand", "CliCommand", "Command", "Cli" };
15-
public const string RootCommandClassName = "CliRootCommand";
16-
public const string CommandClassName = "CliCommand";
15+
public const string RootCommandClassName = "RootCommand";
16+
public const string CommandClassName = "Command";
1717
public const string CommandClassNamespace = "System.CommandLine";
1818
public const string DiagnosticName = "CLI command";
1919
public const string GeneratedSubNamespace = "GeneratedCode";

src/DotMake.CommandLine.SourceGeneration/CliOptionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CliOptionInfo : CliSymbolInfo, IEquatable<CliOptionInfo>
1111
{
1212
public static readonly string AttributeFullName = typeof(CliOptionAttribute).FullName;
1313
public static readonly string[] Suffixes = CliCommandInfo.Suffixes.Select(s => s + "Option").Append("Option").ToArray();
14-
public const string OptionClassName = "CliOption";
14+
public const string OptionClassName = "Option";
1515
public const string OptionClassNamespace = "System.CommandLine";
1616
public const string DiagnosticName = "CLI option";
1717
public static readonly Dictionary<string, string> PropertyMappings = new Dictionary<string, string>

src/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
2727
</ItemGroup>
2828

29-
<ItemGroup>
30-
<!-- Ensure that the .Embedded project is built together with this project (for checking compile errors) -->
31-
<ProjectReference Include="..\$(MSBuildProjectName).Embedded\$(MSBuildProjectName).Embedded.csproj">
32-
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
33-
</ProjectReference>
34-
</ItemGroup>
35-
3629
<ItemGroup>
3730
<EmbeddedResource Update="Resources.resx">
3831
<Generator>ResXFileCodeGenerator</Generator>

src/DotMake.CommandLine/Binding/ArgumentConverter.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.CommandLine;
88
using System.CommandLine.Parsing;
99
using System.Diagnostics.CodeAnalysis;
10+
using System.Runtime.CompilerServices;
1011
using System.Runtime.Serialization;
1112
using static DotMake.CommandLine.Binding.ArgumentConversionResult;
1213

@@ -16,7 +17,7 @@ internal static partial class ArgumentConverter
1617
{
1718
internal static Dictionary<Type, Func<Array, object>> CollectionConverters = new Dictionary<Type, Func<Array, object>>();
1819

19-
internal static TryConvertArgument? GetConverter(CliArgument argument)
20+
internal static TryConvertArgument? GetConverter(Argument argument)
2021
{
2122
/*
2223
//We check exceptions for convert methods, so disabling this shortcut
@@ -88,10 +89,10 @@ internal static ArgumentConversionResult ConvertObject(
8889
{
8990
switch (value)
9091
{
91-
case CliToken singleValue:
92+
case Token singleValue:
9293
return ConvertToken(argumentResult, type, singleValue);
9394

94-
case IReadOnlyList<CliToken> manyValues:
95+
case IReadOnlyList<Token> manyValues:
9596
return ConvertTokens(argumentResult, type, manyValues);
9697

9798
default:
@@ -115,7 +116,7 @@ internal static ArgumentConversionResult ConvertObject(
115116
private static ArgumentConversionResult ConvertToken(
116117
ArgumentResult argumentResult,
117118
Type type,
118-
CliToken token)
119+
Token token)
119120
{
120121
var value = token.Value;
121122

@@ -159,7 +160,7 @@ private static ArgumentConversionResult ConvertToken(
159160
private static ArgumentConversionResult ConvertTokens(
160161
ArgumentResult argumentResult,
161162
Type type,
162-
IReadOnlyList<CliToken> tokens)
163+
IReadOnlyList<Token> tokens)
163164
{
164165
type = type.GetNullableUnderlyingTypeOrSelf();
165166
var itemType = type.GetElementTypeIfEnumerable(typeof(string)) ?? typeof(string);
@@ -279,6 +280,10 @@ private static Array CreateArray(Type itemType, int capacity)
279280
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern",
280281
Justification = $"{nameof(CreateDefaultValueType)} is only called on a ValueType. You can always create an instance of a ValueType.")]
281282
private static object CreateDefaultValueType(Type type) =>
283+
#if NET
284+
RuntimeHelpers.GetUninitializedObject(type);
285+
#else
282286
FormatterServices.GetUninitializedObject(type);
287+
#endif
283288
}
284289
}

src/DotMake.CommandLine/Cli.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public static string[] GetArgs()
6767
/// </summary>
6868
/// <typeparam name="TDefinition">The definition class for the command. A command builder for this class should be automatically generated by the source generator.</typeparam>
6969
/// <param name="settings">The settings for the parser's grammar and behaviors.</param>
70-
/// <returns>A <see cref="CliConfiguration"/> on which the parser's grammar and behaviors are based.</returns>
71-
public static CliConfiguration GetConfiguration<TDefinition>(CliSettings settings = null)
70+
/// <returns>A <see cref="CommandLineConfiguration"/> on which the parser's grammar and behaviors are based.</returns>
71+
public static CommandLineConfiguration GetConfiguration<TDefinition>(CliSettings settings = null)
7272
{
7373
var definitionType = typeof(TDefinition);
7474

@@ -78,13 +78,13 @@ public static CliConfiguration GetConfiguration<TDefinition>(CliSettings setting
7878
/// <inheritdoc cref = "GetConfiguration{TDefinition}" />
7979
/// <param name="definitionType">The definition class type for the command. A command builder for this class should be automatically generated by the source generator.</param>
8080
/// <param name="settings"><inheritdoc cref="GetConfiguration{TDefinition}" path="/param[@name='settings']/node()" /></param>
81-
public static CliConfiguration GetConfiguration(Type definitionType, CliSettings settings = null)
81+
public static CommandLineConfiguration GetConfiguration(Type definitionType, CliSettings settings = null)
8282
{
8383
var commandBuilder = CliCommandBuilder.Get(definitionType);
8484
var command = commandBuilder.Build();
8585

8686
settings ??= new CliSettings();
87-
var configuration = new CliConfiguration(command)
87+
var configuration = new CommandLineConfiguration(command)
8888
{
8989
EnablePosixBundling = settings.EnablePosixBundling,
9090
EnableDefaultExceptionHandler = settings.EnableDefaultExceptionHandler,
@@ -97,7 +97,7 @@ public static CliConfiguration GetConfiguration(Type definitionType, CliSettings
9797
if (settings.Error != null) //Console.Error is NOT being used
9898
configuration.Error = settings.Error;
9999

100-
if (command is CliRootCommand rootCommand)
100+
if (command is RootCommand rootCommand)
101101
{
102102
//CliRootCommand constructor already adds HelpOption and VersionOption so remove them
103103
foreach (var option in rootCommand.Options.Where(option => option is HelpOption or VersionOption).ToArray())
@@ -369,7 +369,7 @@ and it already trims double quote characters
369369
return args;
370370
}
371371

372-
private sealed class VersionOptionAction : SynchronousCliAction
372+
private sealed class VersionOptionAction : SynchronousCommandLineAction
373373
{
374374
public override int Invoke(ParseResult parseResult)
375375
{

src/DotMake.CommandLine/CliCommandBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ protected CliCommandBuilder()
6464
public bool ShortFormAutoGenerate { get; protected set; }
6565

6666
/// <summary>
67-
/// Builds a <see cref="CliCommand"/> instance, populated with sub-commands, options, arguments and settings.
67+
/// Builds a <see cref="Command"/> instance, populated with sub-commands, options, arguments and settings.
6868
/// </summary>
69-
/// <returns>A populated <see cref="CliCommand"/> instance.</returns>
70-
public abstract CliCommand Build();
69+
/// <returns>A populated <see cref="Command"/> instance.</returns>
70+
public abstract Command Build();
7171

7272
/// <summary>
7373
/// Creates a new instance of the command definition class and binds/populates the properties from the parse result.
@@ -119,7 +119,7 @@ public void Register()
119119
/// <summary>
120120
/// Registers a command builder so that it can be found by the definition class.
121121
/// </summary>
122-
/// <param name="commandBuilder">A command builder which builds a <see cref="CliCommand"/>.</param>
122+
/// <param name="commandBuilder">A command builder which builds a <see cref="Command"/>.</param>
123123
/// <typeparam name="TDefinition">The definition class.</typeparam>
124124
public static void Register<TDefinition>(CliCommandBuilder commandBuilder)
125125
{
@@ -132,7 +132,7 @@ public static void Register<TDefinition>(CliCommandBuilder commandBuilder)
132132
/// Registers a command builder so that it can be found by the definition class.
133133
/// </summary>
134134
/// <param name="definitionType">The type of the definition class.</param>
135-
/// <param name="commandBuilder">A command builder which builds a <see cref="CliCommand"/>.</param>
135+
/// <param name="commandBuilder">A command builder which builds a <see cref="Command"/>.</param>
136136
public static void Register(Type definitionType, CliCommandBuilder commandBuilder)
137137
{
138138
RegisteredDefinitionTypes[definitionType] = commandBuilder;
@@ -290,7 +290,7 @@ public static Func<ArgumentResult, TArgument> GetArgumentParser<TArgument>(Func<
290290
/// <param name="option">The option for which to get a value.</param>
291291
/// <typeparam name="T">The option type.</typeparam>
292292
/// <returns>The parsed value or a configured default.</returns>
293-
public static T GetValueForOption<T>(ParseResult parseResult, CliOption<T> option)
293+
public static T GetValueForOption<T>(ParseResult parseResult, Option<T> option)
294294
{
295295
var result = parseResult.GetResult(option);
296296
if (result != null)
@@ -304,7 +304,7 @@ public static T GetValueForOption<T>(ParseResult parseResult, CliOption<T> optio
304304
}
305305

306306
/// <inheritdoc cref="GetValueForOption{T}"/>
307-
public static object GetValueForOption(ParseResult parseResult, CliOption option)
307+
public static object GetValueForOption(ParseResult parseResult, Option option)
308308
{
309309
var result = parseResult.GetResult(option);
310310
if (result != null)
@@ -328,7 +328,7 @@ public static object GetValueForOption(ParseResult parseResult, CliOption option
328328
/// <param name="argument">The argument for which to get a value.</param>
329329
/// <typeparam name="T">The argument type.</typeparam>
330330
/// <returns>The parsed value or a configured default.</returns>
331-
public static T GetValueForArgument<T>(ParseResult parseResult, CliArgument<T> argument)
331+
public static T GetValueForArgument<T>(ParseResult parseResult, Argument<T> argument)
332332
{
333333
var result = parseResult.GetResult(argument);
334334
if (result != null)
@@ -342,7 +342,7 @@ public static T GetValueForArgument<T>(ParseResult parseResult, CliArgument<T> a
342342
}
343343

344344
/// <inheritdoc cref="GetValueForArgument{T}"/>
345-
public static object GetValueForArgument(ParseResult parseResult, CliArgument argument)
345+
public static object GetValueForArgument(ParseResult parseResult, Argument argument)
346346
{
347347
var result = parseResult.GetResult(argument);
348348
if (result != null)

src/DotMake.CommandLine/CliContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void ShowHelp()
6666
}
6767
};
6868

69-
var action = (SynchronousCliAction)helpOption.Action;
69+
var action = (SynchronousCommandLineAction)helpOption.Action;
7070

7171
action?.Invoke(ParseResult);
7272
}

0 commit comments

Comments
 (0)