Skip to content

Commit b8a0380

Browse files
committed
Version 3.0.0
- **Improved:** Updated to final version `2.0.0` of `System.CommandLine`. - **Improved:** Remove `SourceRevisionId` (commit id) from `AssemblyInformationalVersion` (`<InformationalVersion>`) so that displayed app version and result of `--version` command is clean and concise. For example display `MyApp v2.0.0` instead of `MyApp v2.0.0+b0f34d51fccc69fd334253924abd8d6853fad7aa`.
1 parent db42495 commit b8a0380

File tree

127 files changed

+325
-339
lines changed

Some content is hidden

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

127 files changed

+325
-339
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ if (result.ParseResult.Errors.Count > 0)
124124
}
125125
```
126126
#### Summary
127-
- Mark the class with `[CliCommand]` attribute to make it a CLI command (see [CliCommandAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliCommandAttribute.htm) docs for more info).
128-
- Mark a property with `[CliOption]` attribute to make it a CLI option (see [CliOptionAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliOptionAttribute.htm) docs for more info).
129-
- Mark a property with `[CliArgument]` attribute to make it a CLI argument (see [CliArgumentAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliArgumentAttribute.htm) docs for more info).
127+
- Mark the class with `[CliCommand]` attribute to make it a CLI command (see [CliCommandAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliCommandAttribute.html) docs for more info).
128+
- Mark a property with `[CliOption]` attribute to make it a CLI option (see [CliOptionAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliOptionAttribute.html) docs for more info).
129+
- Mark a property with `[CliArgument]` attribute to make it a CLI argument (see [CliArgumentAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliArgumentAttribute.html) docs for more info).
130130
- Add a method with name `Run` or `RunAsync` to make it the handler for the CLI command. The method can have one of the following signatures:
131131

132132
-
@@ -167,7 +167,7 @@ if (result.ParseResult.Errors.Count > 0)
167167
If no handler method is provided, then by default it will show help for the command.
168168
This can be also controlled manually by `ShowHelp()` method of `CliContext`.
169169
Other methods `IsEmptyCommand()`, `IsEmpty()`, `ShowValues()` and `ShowHierarchy()` are also useful.
170-
- Call `Cli.Run<>` or`Cli.RunAsync<>` method with your class name to run your CLI app (see [Cli](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_Cli.htm) docs for more info).
170+
- Call `Cli.Run<>` or`Cli.RunAsync<>` method with your class name to run your CLI app (see [Cli](https://dotmake.build/command-line/api/DotMake.CommandLine.Cli.html) docs for more info).
171171
- For best practice, create a subfolder named `Commands` in your project and put your command classes there
172172
so that they are easy to locate and maintain in the future.
173173

@@ -192,9 +192,9 @@ And that's it! You now have a fully working command-line app.
192192
#### Summary
193193
- Pass a delegate (a parenthesized lambda expression or a method reference) which has parameters that represent your options and arguments, to `Cli.Run`.
194194
- A parameter is by default considered as a CLI option but you can;
195-
- Mark a parameter with `[CliArgument]` attribute to make it a CLI argument and specify settings (see [CliArgumentAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliArgumentAttribute.htm) docs for more info).
196-
- Mark a parameter with `[CliOption]` attribute to specify CLI option settings (see [CliOptionAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliOptionAttribute.htm) docs for more info).
197-
- Mark the delegate itself with `[CliCommand]` attribute to specify CLI command settings (see [CliCommandAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliCommandAttribute.htm) docs for more info).
195+
- Mark a parameter with `[CliArgument]` attribute to make it a CLI argument and specify settings (see [CliArgumentAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliArgumentAttribute.html) docs for more info).
196+
- Mark a parameter with `[CliOption]` attribute to specify CLI option settings (see [CliOptionAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliOptionAttribute.html) docs for more info).
197+
- Mark the delegate itself with `[CliCommand]` attribute to specify CLI command settings (see [CliCommandAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliCommandAttribute.html) docs for more info).
198198
- Note that for being able to mark a parameter with an attribute in an anonymous lambda function,
199199
if your target framework is below net6.0, you also need `<LangVersion>10.0</LangVersion>` tag (minimum) in your .csproj file.
200200
- Set a default value for a parameter if you want it to be optional (not required to be specified on the command-line).
@@ -889,7 +889,7 @@ public class My2CliCommand : IOptionsGroup1
889889
```
890890

891891
---
892-
The properties for `[CliCommand]` attribute (see [CliCommandAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliCommandAttribute.htm) docs for more info):
892+
The properties for `[CliCommand]` attribute (see [CliCommandAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliCommandAttribute.html) docs for more info):
893893
- Name
894894
- Description
895895
- Hidden
@@ -944,7 +944,7 @@ Only the last option can specify an argument.
944944
Note that if you have an explicit option named "-abc" then it will win over bundled options.
945945

946946
---
947-
The properties for `[CliOption]` attribute (see [CliOptionAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliOptionAttribute.htm) docs for more info):
947+
The properties for `[CliOption]` attribute (see [CliOptionAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliOptionAttribute.html) docs for more info):
948948
- Name
949949
- Description
950950
- Hidden
@@ -1003,7 +1003,7 @@ Quiet
10031003
```
10041004

10051005
---
1006-
The properties for `[CliArgument]` attribute (see [CliArgumentAttribute](https://dotmake.build/command-line/api/html/T_DotMake_CommandLine_CliArgumentAttribute.htm) docs for more info):
1006+
The properties for `[CliArgument]` attribute (see [CliArgumentAttribute](https://dotmake.build/command-line/api/DotMake.CommandLine.CliArgumentAttribute.html) docs for more info):
10071007
- Name
10081008
- Description
10091009
- Hidden

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

src/DotMake.CommandLine/CliHelpBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ public override void Write(HelpContext helpContext)
124124
public virtual bool WriteSynopsisSection(HelpContext helpContext)
125125
{
126126
ConsoleExtensions.SetColor(theme.SynopsisColor, theme.DefaultColor);
127-
helpContext.Output.Write(ExecutableInfo.Product);
128-
if (!string.IsNullOrWhiteSpace(ExecutableInfo.Version))
129-
helpContext.Output.Write(" v{0}", ExecutableInfo.Version);
127+
helpContext.Output.Write(ExecutableInfo.AssemblyInfo.Product);
128+
if (!string.IsNullOrWhiteSpace(ExecutableInfo.AssemblyInfo.Version))
129+
helpContext.Output.Write(" v{0}", ExecutableInfo.AssemblyInfo.Version);
130130
helpContext.Output.WriteLine();
131-
if (!string.IsNullOrWhiteSpace(ExecutableInfo.Copyright))
132-
helpContext.Output.WriteLine(ExecutableInfo.Copyright);
131+
if (!string.IsNullOrWhiteSpace(ExecutableInfo.AssemblyInfo.Copyright))
132+
helpContext.Output.WriteLine(ExecutableInfo.AssemblyInfo.Copyright);
133133

134134
var isRoot = (helpContext.Command.Parents.FirstOrDefault() == null);
135135
var name = isRoot ? string.Empty : helpContext.Command.Name;
136136
var description = helpContext.Command.Description
137-
?? (isRoot ? ExecutableInfo.Description : string.Empty);
137+
?? (isRoot ? ExecutableInfo.AssemblyInfo.Description : string.Empty);
138138
const string separator = ": ";
139139

140140
var hasName = !string.IsNullOrWhiteSpace(name);

src/DotMake.CommandLine/CliParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private sealed class VersionOptionAction : SynchronousCommandLineAction
276276
{
277277
public override int Invoke(ParseResult parseResult)
278278
{
279-
parseResult.InvocationConfiguration.Output.WriteLine(ExecutableInfo.Version);
279+
parseResult.InvocationConfiguration.Output.WriteLine(ExecutableInfo.AssemblyInfo.Version);
280280
return 0;
281281
}
282282

src/DotMake.CommandLine/DotMake.CommandLine.csproj

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,20 @@
2121
<PackageTags>command-line CLI console System.CommandLine declarative attributes parsing command argument option generator</PackageTags>
2222
<PackageReleaseNotes>
2323
<![CDATA[
24-
- **Fixed:** All types in generated code will now be prefixed with global namespace `global::` to prevent
25-
CS0234 errors (namespace and type conflict compile errors) which can happen when user names a namespace part and a class same.
26-
Example code to replicate the problem (now fixed), note the `.TestApp`, `.System`, `.DotMake`
27-
as the final part of the namespace which triggered the problem:
28-
```c#
29-
using DotMake.CommandLine;
30-
31-
//Generated code should not fail to compile even if user uses some crazy namespaces
32-
33-
namespace TestApp.Commands.TestApp
34-
{
35-
[CliCommand]
36-
public class TestAppCliCommand
37-
{
38-
[CliArgument(Arity = CliArgumentArity.ZeroOrMore)]
39-
public string Arg { get; set; }
40-
}
41-
}
42-
43-
namespace TestApp.Commands.System
44-
{
45-
[CliCommand]
46-
public class SystemCliCommand
47-
{
48-
49-
}
50-
}
51-
52-
namespace TestApp.Commands.DotMake
53-
{
54-
[CliCommand]
55-
public class DotMakeCliCommand
56-
{
57-
58-
}
59-
}
60-
```
24+
- **Improved:** Updated to final version `2.0.0` of `System.CommandLine`.
6125
62-
- **Improved:** Documentation for `CliContext.IsEmptyCommand()` and `CliContext.IsEmpty()` to emphasize the difference.
26+
- **Improved:** Remove `SourceRevisionId` (commit id) from `AssemblyInformationalVersion` (`<InformationalVersion>`)
27+
so that displayed app version and result of `--version` command is clean and concise.
28+
For example display `MyApp v2.0.0` instead of `MyApp v2.0.0+b0f34d51fccc69fd334253924abd8d6853fad7aa`.
6329
]]>
6430
</PackageReleaseNotes>
6531
</PropertyGroup>
6632

6733
<Import Project="..\DotMake.CommandLine.Shared\DotMake.CommandLine.Shared.projitems" Label="Shared" />
6834

6935
<ItemGroup>
70-
<!-- use exact version match with [] for now as future beta versions can break API -->
71-
<PackageReference Include="System.CommandLine" Version="[2.0.0-rc.1.25451.107]" />
36+
<!-- update: use final 2.0.0 now, old: use exact version match with [] for now as future beta versions can break API -->
37+
<PackageReference Include="System.CommandLine" Version="2.0.0" />
7238

7339
<!--
7440
UPDATE: No longer using this as now 2.0.0-beta5.25306.1 is released to official nuget feed.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Reflection;
2+
3+
namespace DotMake.CommandLine.Util
4+
{
5+
internal class AssemblyInfo
6+
{
7+
public AssemblyInfo(Assembly assembly)
8+
{
9+
Assembly = assembly;
10+
AssemblyName = assembly.GetName();
11+
12+
var assemblyInformationalVersion = Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
13+
if (assemblyInformationalVersion != null)
14+
{
15+
var parts = assemblyInformationalVersion.InformationalVersion.Split('+');
16+
Version = parts[0].TrimStart('v');
17+
SourceRevisionId = (parts.Length > 1) ? parts[1].Trim() : "";
18+
}
19+
else
20+
{
21+
var assemblyFileVersion = Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
22+
if (assemblyFileVersion != null)
23+
Version = assemblyFileVersion.Version;
24+
else
25+
{
26+
Version = AssemblyName.Version?.ToString() ?? "";
27+
}
28+
}
29+
30+
var assemblyProduct = Assembly.GetCustomAttribute<AssemblyProductAttribute>();
31+
Product = assemblyProduct != null ? assemblyProduct.Product : AssemblyName.Name;
32+
33+
var assemblyCopyright = Assembly.GetCustomAttribute<AssemblyCopyrightAttribute>();
34+
Copyright = assemblyCopyright != null ? assemblyCopyright.Copyright : "";
35+
36+
var assemblyDescription = Assembly.GetCustomAttribute<AssemblyDescriptionAttribute>();
37+
Description = assemblyDescription != null ? assemblyDescription.Description : "";
38+
}
39+
40+
public Assembly Assembly { get; }
41+
42+
public AssemblyName AssemblyName { get; }
43+
44+
public string Product { get; }
45+
46+
public string Version { get; }
47+
48+
public string SourceRevisionId { get; }
49+
50+
public string Copyright { get; }
51+
52+
public string Description { get; }
53+
}
54+
}

src/DotMake.CommandLine/Util/ExecutableInfo.cs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ internal static class ExecutableInfo
88
{
99
static ExecutableInfo()
1010
{
11-
Assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
12-
AssemblyName = Assembly.GetName();
11+
AssemblyInfo = new AssemblyInfo(Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly());
1312

1413
try
1514
{
@@ -18,48 +17,15 @@ static ExecutableInfo()
1817
}
1918
catch
2019
{
21-
ExecutableName = AssemblyName.Name ?? "app";
20+
ExecutableName = AssemblyInfo.AssemblyName.Name ?? "app";
2221
ExecutablePath = Path.Combine(AppContext.BaseDirectory, ExecutableName);
2322
}
2423

25-
var assemblyInformationalVersion = Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
26-
if (assemblyInformationalVersion != null)
27-
Version = assemblyInformationalVersion.InformationalVersion.TrimStart('v');
28-
else
29-
{
30-
var assemblyFileVersion = Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
31-
if (assemblyFileVersion != null)
32-
Version = assemblyFileVersion.Version;
33-
else
34-
{
35-
Version = AssemblyName.Version?.ToString() ?? "";
36-
}
37-
}
38-
39-
var assemblyProduct = Assembly.GetCustomAttribute<AssemblyProductAttribute>();
40-
Product = assemblyProduct != null ? assemblyProduct.Product : AssemblyName.Name;
41-
42-
var assemblyCopyright = Assembly.GetCustomAttribute<AssemblyCopyrightAttribute>();
43-
Copyright = assemblyCopyright != null ? assemblyCopyright.Copyright : "";
44-
45-
var assemblyDescription = Assembly.GetCustomAttribute<AssemblyDescriptionAttribute>();
46-
Description = assemblyDescription != null ? assemblyDescription.Description : "";
4724
}
48-
49-
public static Assembly Assembly { get; }
50-
51-
public static AssemblyName AssemblyName { get; }
25+
public static AssemblyInfo AssemblyInfo { get; }
5226

5327
public static string ExecutablePath { get; }
5428

5529
public static string ExecutableName { get; }
56-
57-
public static string Product { get; }
58-
59-
public static string Version { get; }
60-
61-
public static string Copyright { get; }
62-
63-
public static string Description { get; }
6430
}
6531
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.2.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
2+
// Generated by DotMake.CommandLine.SourceGeneration v3.0.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.46508
44
// Generation: 1
55

66
#if !NET5_0_OR_GREATER

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.2.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
2+
// Generated by DotMake.CommandLine.SourceGeneration v3.0.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.46508
44
// Generation: 1
55

66
// Licensed to the .NET Foundation under one or more agreements.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.2.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
2+
// Generated by DotMake.CommandLine.SourceGeneration v3.0.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.46508
44
// Generation: 1
55

66
namespace TestApp.Commands.GeneratedCode

0 commit comments

Comments
 (0)