Skip to content

Commit 9997f94

Browse files
committed
Change: Replace old CLI framework and update related code
Switched from the deprecated `OLD` CLI framework to the updated `CliData` attributes and interfaces across commands and parameter definitions. Adjusted method signatures, updated parser initialization in the main program, and cleaned obsolete imports for improved consistency and maintainability.
1 parent aa5e745 commit 9997f94

File tree

8 files changed

+44
-41
lines changed

8 files changed

+44
-41
lines changed

src/CodeOfChaos.CliArgsParser.Generators/CommandGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private static void GenerateSources(SourceProductionContext context, (Compilatio
6363
"System",
6464
"System.Threading",
6565
"System.Threading.Tasks",
66+
"System.Collections.Generic",
6667
"CodeOfChaos.CliArgsParser"
6768
);
6869

src/CodeOfChaos.CliArgsParser.Library/Commands/DownloadIcon/DownloadIconCommand.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
44
using CodeOfChaos.CliArgsParser.Library.Shared;
5-
using CodeOfChaos.CliArgsParser.OLD;
65
using System.Text.RegularExpressions;
76
using System.Xml.Linq;
87

98
namespace CodeOfChaos.CliArgsParser.Library.Commands.DownloadIcon;
109
// ---------------------------------------------------------------------------------------------------------------------
1110
// Code
1211
// ---------------------------------------------------------------------------------------------------------------------
13-
[CliArgsCommand("nuget-download-icon")]
14-
[CliArgsDescription("Downloads and assigns the icon, to be used as nuget package's icon, for the specified project.")]
15-
public partial class DownloadIconCommand : ICommand<DownloadIconParameters> {
12+
[CliData("nuget-download-icon")]
13+
// [CliArgsDescription("Downloads and assigns the icon, to be used as nuget package's icon, for the specified project.")]
14+
public partial class DownloadIconCommand : ICliCommand<DownloadIconParameters> {
1615

1716
[GeneratedRegex(@"^[^/\\\s]+$")]
1817
private static partial Regex IsEmptyFolderNameRegex { get; }
1918

2019
// -----------------------------------------------------------------------------------------------------------------
2120
// Methods
2221
// -----------------------------------------------------------------------------------------------------------------
23-
public async Task ExecuteAsync(DownloadIconParameters parameters) {
22+
public async ValueTask ExecuteAsync(DownloadIconParameters parameters, CancellationToken ct = default) {
2423
Console.WriteLine("Downloading Icon...");
2524
bool getResult = await TryGetIcon(parameters);
2625
if (!getResult) {

src/CodeOfChaos.CliArgsParser.Library/Commands/DownloadIcon/DownloadIconParameters.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using CodeOfChaos.CliArgsParser.OLD;
5-
64
namespace CodeOfChaos.CliArgsParser.Library.Commands.DownloadIcon;
75
// ---------------------------------------------------------------------------------------------------------------------
86
// Code
97
// ---------------------------------------------------------------------------------------------------------------------
10-
public readonly partial struct DownloadIconParameters : IParameters {
11-
[CliArgsParameter("root", "r")] [CliArgsDescription("The root directory of the project to update")]
8+
public record DownloadIconParameters : ICliParameters {
9+
[CliData("root", "r")]
10+
// [CliArgsDescription("The root directory of the project to update")]
1211
public string Root { get; init; } = "../../../../../";
1312

14-
[CliArgsParameter("projects", "pr")] [CliArgsDescription("The projects to update")]
13+
[CliData("projects", "pr")]
14+
// [CliArgsDescription("The projects to update")]
1515
public required string ProjectsStringValue { get; init; }
1616

17-
[CliArgsParameter("project-split", "ps")] [CliArgsDescription("The split character to use when splitting the projects string")]
17+
[CliData("project-split", "ps")]
18+
// [CliArgsDescription("The split character to use when splitting the projects string")]
1819
public string ProjectsSplit { get; init; } = ";";
1920

20-
[CliArgsParameter("source-folder", "sf")] [CliArgsDescription("The folder where the projects are located")]
21+
[CliData("source-folder", "sf")]
22+
// [CliArgsDescription("The folder where the projects are located")]
2123
public string SourceFolder { get; init; } = "src";
2224

23-
[CliArgsParameter("icon-folder", "if")] [CliArgsDescription("The folder where the icons are located")]
25+
[CliData("icon-folder", "if")]
26+
// [CliArgsDescription("The folder where the icons are located")]
2427
public string IconFolder { get; init; } = "assets/";
2528

26-
[CliArgsParameter("origin", "o")] [CliArgsDescription("The origin of the icon file")]
29+
[CliData("origin", "o")]
30+
// [CliArgsDescription("The origin of the icon file")]
2731
public required string Origin { get; init; }
2832

2933
public string[] GetProjects() => ProjectsStringValue

src/CodeOfChaos.CliArgsParser.Library/Commands/VersionBump/VersionBumpCommand.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
44
using CodeOfChaos.CliArgsParser.Library.Shared;
5-
using CodeOfChaos.CliArgsParser.OLD;
65
using System.Xml.Linq;
76

87
namespace CodeOfChaos.CliArgsParser.Library.Commands.VersionBump;
98
// ---------------------------------------------------------------------------------------------------------------------
109
// Code
1110
// ---------------------------------------------------------------------------------------------------------------------
12-
[CliArgsCommand("git-version-bump")]
13-
[CliArgsDescription("Bumps the version of the projects specified in the projects argument.")]
14-
public partial class VersionBumpCommand : ICommand<VersionBumpParameters> {
11+
[CliData("git-version-bump")]
12+
// [CliArgsDescription("Bumps the version of the projects specified in the project argument.")]
13+
public partial class VersionBumpCommand : ICliCommand<VersionBumpParameters> {
1514
private static readonly List<string> ErrorMessages = [];
1615

1716
// -----------------------------------------------------------------------------------------------------------------
1817
// Methods
1918
// -----------------------------------------------------------------------------------------------------------------
20-
public async Task ExecuteAsync(VersionBumpParameters parameters) {
19+
public async ValueTask ExecuteAsync(VersionBumpParameters parameters, CancellationToken ct = default) {
2120
Console.WriteLine(ConsoleTextStore.BumpingVersion);
2221
SemanticVersionDto? updatedVersion = await BumpVersion(parameters);
2322
if (updatedVersion is null) {

src/CodeOfChaos.CliArgsParser.Library/Commands/VersionBump/VersionBumpParameters.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using CodeOfChaos.CliArgsParser.OLD;
5-
64
namespace CodeOfChaos.CliArgsParser.Library.Commands.VersionBump;
75
// ---------------------------------------------------------------------------------------------------------------------
86
// Code
97
// ---------------------------------------------------------------------------------------------------------------------
10-
public readonly partial struct VersionBumpParameters : IParameters {
11-
[CliArgsParameter("root", "r")] [CliArgsDescription("The root directory of the project to update")]
8+
public record VersionBumpParameters : ICliParameters {
9+
[CliData("root", "r")]
10+
// [CliArgsDescription("The root directory of the project to update")]
1211
public string Root { get; init; } = "../../../../../";
1312

14-
[CliArgsParameter("section", "s")] [CliArgsDescription("The section of the version to bump. One of: Major, Minor, Patch")]
13+
[CliData("section", "s")]
14+
// [CliArgsDescription("The section of the version to bump. One of: Major, Minor, Patch")]
1515
public required string? SectionStringValue { get; init; }
1616

1717
public VersionSection Section => Enum.Parse<VersionSection>(SectionStringValue ?? "None", true);
1818

19-
[CliArgsParameter("push", "p", ParameterType.Flag)] [CliArgsDescription("Push the changes to the remote repository")]
19+
[CliData("push", "p")]
20+
// [CliArgsDescription("Push the changes to the remote repository")]
2021
public bool PushToRemote { get; init; } = false;
2122

22-
[CliArgsParameter("force", "f", ParameterType.Flag)] [CliArgsDescription("Automatically push the changes to the remote repository without user input")]
23+
[CliData("force", "f")]
24+
// [CliArgsDescription("Automatically push the changes to the remote repository without user input")]
2325
public bool Force { get; init; } = false;
2426

25-
[CliArgsParameter("projects", "pr")] [CliArgsDescription("The projects to update")]
27+
[CliData("projects", "pr")]
28+
// [CliArgsDescription("The projects to update")]
2629
public required string ProjectsStringValue { get; init; }
2730

28-
[CliArgsParameter("project-split", "ps")] [CliArgsDescription("The split character to use when splitting the projects string")]
31+
[CliData("project-split", "ps")]
32+
// [CliArgsDescription("The split character to use when splitting the projects string")]
2933
public string ProjectsSplit { get; init; } = ";";
3034

31-
[CliArgsParameter("source-folder", "sf")] [CliArgsDescription("The folder where the projects are located")]
35+
[CliData("source-folder", "sf")]
36+
// [CliArgsDescription("The folder where the projects are located")]
3237
public string SourceFolder { get; init; } = "src";
3338

3439
public string[] GetProjects() => ProjectsStringValue

src/Tools.CodeOfChaos.CliArgsParser/Program.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// ---------------------------------------------------------------------------------------------------------------------
44
using CodeOfChaos.CliArgsParser;
55
using CodeOfChaos.CliArgsParser.Library;
6-
using CodeOfChaos.CliArgsParser.OLD;
76

87
namespace Tools.CodeOfChaos.CliArgsParser;
98
// ---------------------------------------------------------------------------------------------------------------------
@@ -13,15 +12,13 @@ public static class Program {
1312
public static async Task Main(string[] args) {
1413
// Register & Build the parser
1514
// Don't forget to add the current assembly if you built more tools for the current project
16-
global::CodeOfChaos.CliArgsParser.OLD.CliArgsParser parser = CliArgsBuilder.CreateFromConfig(
17-
config => {
18-
config.AddCommandsFromAssemblyEntrypoint<IAssemblyEntry>();
19-
}
20-
).Build();
15+
ICliParser parser = CliParser.FromBuilder()
16+
.AddCommandsFromAssembly<IAssemblyEntry>()
17+
.Build();
2118

2219
// We are doing this here because else the launchSettings.json file becomes a humongous issue to deal with.
23-
// Sometimes CLI params is not the answer.
24-
// Code is the true saviour
20+
// Sometimes CLI params are not the answer.
21+
// Code is the true savior
2522
// const string projects = "";
2623
string projects = string.Join(";",
2724
"CodeOfChaos.CliArgsParser",
@@ -32,7 +29,7 @@ public static async Task Main(string[] args) {
3229

3330
string oneLineArgs = ArgsInputHelper.ToOneLine(args).Replace("%PROJECTS%", projects);
3431

35-
// Finally start executing
36-
await parser.ParseAsync(oneLineArgs);
32+
// Finally, start executing
33+
await parser.ExecuteAsync(oneLineArgs);
3734
}
3835
}

tests/Tests.CodeOfChaos.CliArgsParser/ArgsInputHelperTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
44
using CodeOfChaos.CliArgsParser;
5-
using CodeOfChaos.CliArgsParser.OLD;
65

76
namespace Tests.CodeOfChaos.CliArgsParser;
87

tests/Tests.CodeOfChaos.CliArgsParser/ParameterDictionaryTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
44
using CodeOfChaos.CliArgsParser;
5-
using CodeOfChaos.CliArgsParser.OLD;
65
using JetBrains.Annotations;
76

87
namespace Tests.CodeOfChaos.CliArgsParser;

0 commit comments

Comments
 (0)