|
4 | 4 | using Microsoft.Extensions.Configuration; |
5 | 5 | using Microsoft.Extensions.DependencyInjection; |
6 | 6 | using Serilog; |
| 7 | +using System.Reflection; |
7 | 8 |
|
8 | 9 | namespace Arius.Cli; |
9 | 10 |
|
@@ -51,23 +52,36 @@ public static CliApplicationBuilder CreateBuilder() |
51 | 52 | { |
52 | 53 | var isRunningInContainer = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true"; |
53 | 54 |
|
54 | | - // Command discovery |
55 | | - //return new CliApplicationBuilder().AddCommandsFromThisAssembly(); |
| 55 | + var builder = new CliApplicationBuilder() |
| 56 | + .SetTitle("arius") |
| 57 | + .SetExecutableName("arius") |
| 58 | + .SetVersion($"v{GetVersion()}"); |
56 | 59 |
|
57 | 60 | if (isRunningInContainer) |
58 | 61 | { |
59 | | - return new CliApplicationBuilder() |
60 | | - .AddCommands([ |
61 | | - typeof(ArchiveDockerCliCommand), |
62 | | - typeof(RestoreDockerCliCommand)]); |
| 62 | + builder.AddCommands([ |
| 63 | + typeof(ArchiveDockerCliCommand), |
| 64 | + typeof(RestoreDockerCliCommand)]); |
63 | 65 | } |
64 | 66 | else |
65 | 67 | { |
66 | | - return new CliApplicationBuilder() |
67 | | - .AddCommands([ |
68 | | - typeof(ArchiveCliCommand), |
69 | | - typeof(RestoreCliCommand)]); |
| 68 | + builder.AddCommands([ |
| 69 | + typeof(ArchiveCliCommand), |
| 70 | + typeof(RestoreCliCommand)]); |
70 | 71 | } |
| 72 | + |
| 73 | + return builder; |
| 74 | + } |
| 75 | + |
| 76 | + private static string GetVersion() |
| 77 | + { |
| 78 | + // Prefer informational version so that suffixes like "local" are preserved |
| 79 | + var informational = typeof(Program).Assembly |
| 80 | + .GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; |
| 81 | + if (!string.IsNullOrWhiteSpace(informational)) |
| 82 | + return informational; |
| 83 | + |
| 84 | + return typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown"; |
71 | 85 | } |
72 | 86 |
|
73 | 87 | public static IServiceProvider CreateServiceProvider() |
|
0 commit comments