Skip to content

Commit

Permalink
Migrate to use Devlead.Console
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Jan 20, 2025
1 parent 973989d commit 39b1fb6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"rollForward": false
},
"dpi": {
"version": "2024.11.23.86",
"version": "2025.1.19.88",
"commands": [
"dpi"
],
Expand Down
9 changes: 1 addition & 8 deletions src/ARI/ARI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,10 @@
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Cake.Bridge.DependencyInjection" Version="0.15.0" />
<PackageReference Include="Cake.Common" Version="5.0.0" />
<PackageReference Include="Spectre.Console.Cli.Extensions.DependencyInjection" Version="0.3.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Spectre.Console.Analyzer" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="Devlead.Console" Version="2025.1.20.36" />
</ItemGroup>

<ItemGroup>
Expand Down
101 changes: 38 additions & 63 deletions src/ARI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,48 @@
using ARI.Commands;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.Configuration;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Azure.Core;
using Azure.Identity;

var serviceCollection = new ServiceCollection()
.AddCakeCore()
.AddLogging(configure =>
configure
.AddSimpleConsole(opts =>
public partial class Program
{
static partial void AddServices(IServiceCollection services)
{
services
.AddCakeCore()
.AddSingleton<AzureTokenService>(
async (tenantId, scope) =>
{
opts.TimestampFormat = "yyyy-MM-dd HH:mm:ss ";
})
.AddConfiguration(
new ConfigurationBuilder()
.Add(new MemoryConfigurationSource
{
InitialData = new Dictionary<string, string?>
{
{ "LogLevel:System.Net.Http.HttpClient", "Warning" }
}
})
.Build()
))
.AddSingleton<AzureTokenService>(
async (tenantId, scope) =>
{
var tokenCredential = new DefaultAzureCredential();
var accessToken = await tokenCredential.GetTokenAsync(
new TokenRequestContext(
tenantId: tenantId,
scopes: new string[] {
scope ?? "https://management.azure.com/.default"
}
)
);
return accessToken;
}
)
.AddSingleton<InventoryCommand>()
.AddSingleton<TokenService>()
.AddSingleton<TenantService>()
.AddSingleton<SubscriptionService>()
.AddSingleton<ResourceGroupService>()
.AddSingleton<ResourceService>()
.AddSingleton<WebAppConfigService>()
.AddSingleton<WebAppSettingsService>()
.AddSingleton<MarkdownServiceBase, WebAppConfigurationServiceMarkdownService>()
.AddSingleton<MarkdownServiceBase, WebAppSettingsServiceMarkdownService>();

serviceCollection.AddHttpClient();
var tokenCredential = new DefaultAzureCredential();
var accessToken = await tokenCredential.GetTokenAsync(
new TokenRequestContext(
tenantId: tenantId,
scopes: [
scope ?? "https://management.azure.com/.default"
]
)
);
return accessToken;
}
)
.AddSingleton<InventoryCommand>()
.AddSingleton<TokenService>()
.AddSingleton<TenantService>()
.AddSingleton<SubscriptionService>()
.AddSingleton<ResourceGroupService>()
.AddSingleton<ResourceService>()
.AddSingleton<WebAppConfigService>()
.AddSingleton<WebAppSettingsService>()
.AddSingleton<MarkdownServiceBase, WebAppConfigurationServiceMarkdownService>()
.AddSingleton<MarkdownServiceBase, WebAppSettingsServiceMarkdownService>();

using var registrar = new DependencyInjectionRegistrar(serviceCollection);
var app = new CommandApp(registrar);
services.AddHttpClient();
}

app.Configure(
config =>
static partial void ConfigureApp(AppServiceConfig appServiceConfig)
{
config.SetApplicationName("ari");
config.ValidateExamples();
appServiceConfig.SetApplicationName("ari");

config.AddCommand<InventoryCommand>("inventory")
appServiceConfig.AddCommand<InventoryCommand>("inventory")
.WithDescription("Example inventory command.")
.WithExample(new[] { "inventory", "00000000-0000-0000-0000-000000000000", "outputpath" });

config.SetExceptionHandler(
(ex , _) => AnsiConsole.WriteException(ex, ExceptionFormats.ShowLinks)
);
});

return await app.RunAsync(args);
.WithExample(["inventory", "00000000-0000-0000-0000-000000000000", "outputpath"]);
}
}

0 comments on commit 39b1fb6

Please sign in to comment.