Skip to content

Commit

Permalink
Upgrade packages
Browse files Browse the repository at this point in the history
  • Loading branch information
aimenux committed Oct 14, 2024
1 parent 284bf12 commit 3ec54b7
Show file tree
Hide file tree
Showing 30 changed files with 170 additions and 175 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Jetbrains
.idea/*
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![.NET](https://github.com/aimenux/SpectreCliDemo/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aimenux/SpectreCliDemo/actions/workflows/ci.yml)

# SpectreCliDemo
# SpectreConsoleCliDemo
```
Exploring ways of using Spectre.Console to build CLI tools
```
Expand All @@ -13,10 +13,10 @@ In this repo, i m exploring various ways in order to build a simple cli tool bas
>
To run code in debug or release mode, type the following commands in your favorite terminal :
> - `.\BasicWay.exe math add [number1] [number2]`
> - `.\CustomWay.exe math add [number1] [number2]`
> - `.\BasicWay.exe path list [path] -e [extension]`
> - `.\CustomWay.exe path list [path] -e [extension]`
> - `dotnet run --project .\src\BasicWay\BasicWay.csproj math add [number1] [number2]`
> - `dotnet run --project .\src\CustomWay\CustomWay.csproj math add [number1] [number2]`
> - `dotnet run --project .\src\BasicWay\BasicWay.csproj path list [path] -e [extension]`
> - `dotnet run --project .\src\CustomWay\CustomWay.csproj path list [path] -e [extension]`
>
**`Tools`** : vs22, net 6.0, spectre.console.cli
**`Tools`** : net 8.0, spectre.console.cli
1 change: 1 addition & 0 deletions SpectreCliDemo.sln → SpectreConsoleCliDemo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
.gitignore = .gitignore
EndProjectSection
EndProject
Global
Expand Down
12 changes: 6 additions & 6 deletions src/BasicWay/BasicWay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Scrutor" Version="4.2.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Scrutor" Version="5.0.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/Commands/Math/AddCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BasicWay.Commands.Math;

public class AddCommand : AsyncCommand<MathSettings>
public sealed class AddCommand : AsyncCommand<MathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, MathSettings settings)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/Commands/Math/MathSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BasicWay.Commands.Math;

public class MathSettings : CommandSettings
public sealed class MathSettings : CommandSettings
{
[CommandArgument(0, "<FIRST_NUMBER>")]
public int FirstNumber { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/Commands/Math/SubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BasicWay.Commands.Math;

public class SubCommand : AsyncCommand<MathSettings>
public sealed class SubCommand : AsyncCommand<MathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, MathSettings settings)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/Commands/Path/CountCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BasicWay.Commands.Path;

public class CountCommand : AsyncCommand<PathSettings>
public sealed class CountCommand : AsyncCommand<PathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, PathSettings settings)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/Commands/Path/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BasicWay.Commands.Path;

public class ListCommand : AsyncCommand<PathSettings>
public sealed class ListCommand : AsyncCommand<PathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, PathSettings settings)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/Commands/Path/PathSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BasicWay.Commands.Path;

public class PathSettings : CommandSettings
public sealed class PathSettings : CommandSettings
{
[CommandArgument(0, "<PATH_NAME>")]
public string PathName { get; set; }
Expand Down
41 changes: 20 additions & 21 deletions src/BasicWay/Common/Spectre/SpectreCommandApp.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using Spectre.Console.Cli;

namespace BasicWay.Common.Spectre
namespace BasicWay.Common.Spectre;

public sealed class SpectreCommandApp : ICommandApp
{
public class SpectreCommandApp : ICommandApp
{
private readonly ICommandApp _commandApp;
private readonly ICommandApp _commandApp;

public SpectreCommandApp(ITypeRegistrar registrar)
{
_commandApp = new CommandApp(registrar);
}
public SpectreCommandApp(ITypeRegistrar registrar)
{
_commandApp = new CommandApp(registrar);
}

public void Configure(Action<IConfigurator> configuration)
{
_commandApp.Configure(configuration);
}
public void Configure(Action<IConfigurator> configuration)
{
_commandApp.Configure(configuration);
}

public int Run(IEnumerable<string> args)
{
return _commandApp.Run(args);
}
public int Run(IEnumerable<string> args)
{
return _commandApp.Run(args);
}

public Task<int> RunAsync(IEnumerable<string> args)
{
return _commandApp.RunAsync(args);
}
public Task<int> RunAsync(IEnumerable<string> args)
{
return _commandApp.RunAsync(args);
}
}
}
23 changes: 11 additions & 12 deletions src/BasicWay/Common/Spectre/SpectreExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using Spectre.Console;

namespace BasicWay.Common.Spectre
namespace BasicWay.Common.Spectre;

public static class SpectreExtensions
{
public static class SpectreExtensions
public static void RenderException<T>(this T exception) where T : Exception
{
public static void RenderException<T>(this T exception) where T : Exception
{
const ExceptionFormats formats = ExceptionFormats.ShortenTypes
| ExceptionFormats.ShortenPaths
| ExceptionFormats.ShortenMethods;
const ExceptionFormats formats = ExceptionFormats.ShortenTypes
| ExceptionFormats.ShortenPaths
| ExceptionFormats.ShortenMethods;

AnsiConsole.WriteLine();
AnsiConsole.WriteException(exception, formats);
AnsiConsole.WriteLine();
}
AnsiConsole.WriteLine();
AnsiConsole.WriteException(exception, formats);
AnsiConsole.WriteLine();
}
}
}
8 changes: 4 additions & 4 deletions src/BasicWay/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ public static async Task<int> Main(string[] args)
.AddCommand<AddCommand>("add")
.WithAlias("addition")
.WithDescription("Addition of two numbers")
.WithExample(new[] { "math", "add", "8", "5" });
.WithExample("math", "add", "8", "5");
math
.AddCommand<SubCommand>("sub")
.WithAlias("subtraction")
.WithDescription("Subtraction of two numbers")
.WithExample(new[] { "math", "sub", "6", "2" });
.WithExample("math", "sub", "6", "2");
});
config.AddBranch("path", path =>
{
path
.AddCommand<ListCommand>("list")
.WithDescription("List directory files")
.WithExample(new[] { "path", "list", "c:/", "-e", "*" });
.WithExample("path", "list", "c:/", "-e", "*");
path
.AddCommand<CountCommand>("count")
.WithDescription("Count directory files")
.WithExample(new[] { "path", "count", "c:/", "-e", "*" });
.WithExample("path", "count", "c:/", "-e", "*");
});
});
return await app.RunAsync(args);
Expand Down
6 changes: 3 additions & 3 deletions src/BasicWay/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace BasicWay;

public class Settings
public sealed class Settings
{
public string ApplicationName { get; set; } = "spectre-cli";
public string ApplicationName { get; init; } = "spectre-console-cli";

public string ApplicationVersion { get; set; } = "1.0";
public string ApplicationVersion { get; init; } = "1.0";

public static class ExitCode
{
Expand Down
2 changes: 1 addition & 1 deletion src/BasicWay/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
]
},
"Settings": {
"ApplicationName": "spectre-cli",
"ApplicationName": "spectre-console-cli",
"ApplicationVersion": "1.0"
}
}
2 changes: 1 addition & 1 deletion src/CustomWay/Commands/Math/AddCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CustomWay.Commands.Math;

public class AddCommand : AsyncCommand<MathSettings>
public sealed class AddCommand : AsyncCommand<MathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, MathSettings settings)
{
Expand Down
39 changes: 19 additions & 20 deletions src/CustomWay/Commands/Math/MathConfigurator.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using CustomWay.Common.Spectre;
using Spectre.Console.Cli;

namespace CustomWay.Commands.Math
namespace CustomWay.Commands.Math;

public sealed class MathConfigurator : ISpectreConfigurator
{
public class MathConfigurator : ISpectreConfigurator
{
public int Rank => 1;
public int Rank => 1;

public void Configure(IConfigurator config)
public void Configure(IConfigurator config)
{
config.AddBranch("math", math =>
{
config.AddBranch("math", math =>
{
math
.AddCommand<AddCommand>("add")
.WithAlias("addition")
.WithDescription("Addition of two numbers")
.WithExample(new[] { "math", "add", "8", "5" });
math
.AddCommand<AddCommand>("add")
.WithAlias("addition")
.WithDescription("Addition of two numbers")
.WithExample("math", "add", "8", "5");
math
.AddCommand<SubCommand>("sub")
.WithAlias("subtraction")
.WithDescription("Subtraction of two numbers")
.WithExample(new[] { "math", "sub", "6", "2" });
});
}
math
.AddCommand<SubCommand>("sub")
.WithAlias("subtraction")
.WithDescription("Subtraction of two numbers")
.WithExample("math", "sub", "6", "2");
});
}
}
}
2 changes: 1 addition & 1 deletion src/CustomWay/Commands/Math/MathSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CustomWay.Commands.Math;

public class MathSettings : CommandSettings
public sealed class MathSettings : CommandSettings
{
[CommandArgument(0, "<FIRST_NUMBER>")]
public int FirstNumber { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/CustomWay/Commands/Math/SubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CustomWay.Commands.Math;

public class SubCommand : AsyncCommand<MathSettings>
public sealed class SubCommand : AsyncCommand<MathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, MathSettings settings)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CustomWay/Commands/Path/CountCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CustomWay.Commands.Path;

public class CountCommand : AsyncCommand<PathSettings>
public sealed class CountCommand : AsyncCommand<PathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, PathSettings settings)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CustomWay/Commands/Path/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CustomWay.Commands.Path;

public class ListCommand : AsyncCommand<PathSettings>
public sealed class ListCommand : AsyncCommand<PathSettings>
{
public override Task<int> ExecuteAsync(CommandContext context, PathSettings settings)
{
Expand Down
Loading

0 comments on commit 3ec54b7

Please sign in to comment.