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 775a64b commit 2f8dcd6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 63 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.4.84",
"version": "2025.1.19.88",
"commands": [
"dpi"
],
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ The NuGet branch of commands have recursively from given path inventories packag
**nuget analyze** command inventories and outputs result to console or file.

```bash
# Output as table (default)
dpi nuget --output table analyze

# Output as JSON
dpi nuget --output json analyze

# Output as Markdown
dpi nuget --output markdown analyze

# Save output to file
dpi nuget --output json --file dependencies.json analyze
```

#### report
Expand All @@ -44,5 +54,15 @@ export NuGetReportSettings_WorkspaceId=<workspaceid>

export NuGetReportSettings_SharedKey=<sharedkey>

# Output as table (default)
dpi nuget --output table report

# Output as JSON
dpi nuget --output json report

# Output as Markdown
dpi nuget --output markdown report

# Save output to file
dpi nuget --output json --file report.json report
```
11 changes: 2 additions & 9 deletions src/DPI/DPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@
<PackageIcon>icon/dpi.png</PackageIcon>
<ImplicitUsings>enable</ImplicitUsings>
<PackageReadmeFile>README.md</PackageReadmeFile>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli.Extensions.DependencyInjection" Version="0.3.0" />
<PackageReference Include="Devlead.Console" Version="2025.1.20.36" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Cake.Core" Version="5.0.0" />
<PackageReference Include="Cake.Common" Version="5.0.0" />
<PackageReference Include="Cake.Bridge.DependencyInjection" Version="0.15.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<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.Text.Json" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
80 changes: 27 additions & 53 deletions src/DPI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,40 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.Logging;
using DPI.Commands.NuGet;
using DPI.Commands.NuGet;
using DPI.Commands.Settings.NuGet;
using DPI.Models;
using DPI.OutputConverters;
using DPI.Parsers.NuGet;
using Spectre.Console.Cli;
using Spectre.Console.Cli.Extensions.DependencyInjection;

var serviceCollection = new ServiceCollection()
.AddLogging(configure =>
configure
.AddSimpleConsole(opts => {
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()
))
.AddHttpClient()
.AddTransient<NuGetAnalyzeSettings>()
.AddTransient<NuGetReportSettings>()
.AddSingleton<CsProjParser>()
.AddSingleton<DotNetToolsManifestParser>()
.AddSingleton<PackageConfigParser>()
.AddSingleton<CakeParser>()
.AddSingleton<NuGetParsers>()
.AddSingleton<ProjectsAssetsParser>()
.AddSingleton<IOutputConverter, JsonOutputConverter>()
.AddSingleton<IOutputConverter, TableOutputConverter>()
.AddSingleton<IOutputConverter, MarkdownOutputConverter>()
.AddSingleton<ILookup<OutputFormat, IOutputConverter>, OutputConverterLookup>()
.AddCakeCore();

using var registrar = new DependencyInjectionRegistrar(serviceCollection);
var app = new CommandApp(registrar);
public partial class Program
{
static partial void AddServices(IServiceCollection services)
{
services.AddHttpClient()
.AddTransient<NuGetAnalyzeSettings>()
.AddTransient<NuGetReportSettings>()
.AddSingleton<CsProjParser>()
.AddSingleton<DotNetToolsManifestParser>()
.AddSingleton<PackageConfigParser>()
.AddSingleton<CakeParser>()
.AddSingleton<NuGetParsers>()
.AddSingleton<ProjectsAssetsParser>()
.AddSingleton<IOutputConverter, JsonOutputConverter>()
.AddSingleton<IOutputConverter, TableOutputConverter>()
.AddSingleton<IOutputConverter, MarkdownOutputConverter>()
.AddSingleton<ILookup<OutputFormat, IOutputConverter>, OutputConverterLookup>()
.AddCakeCore();
}

app.Configure(
config =>
static partial void ConfigureApp(AppServiceConfig appServiceConfig)
{
config.UseAssemblyInformationalVersion();
config.SetApplicationName("dpi");
config.ValidateExamples();
config.AddBranch<NuGetSettings>("nuget", nuGet => {
appServiceConfig.SetApplicationName("dpi");
appServiceConfig.AddBranch<NuGetSettings>("nuget", nuGet => {
nuGet.SetDescription("NuGet dependency commands.");

nuGet.AddCommand<NuGetAnalyzeCommand<NuGetAnalyzeSettings>>("analyze")
.WithDescription("Inventories NuGet packages")
.WithExample(new[] { "nuget", "<SourcePath>", "analyze" });
.WithExample(["nuget", "<SourcePath>", "analyze"]);

nuGet.AddCommand<NuGetReportCommand>("report")
.WithDescription("Inventories NuGet packages and reports to Azure Log Analytics")
.WithExample(new[] { "nuget", "<SourcePath>", "report" });
.WithExample(["nuget", "<SourcePath>", "report"]);
});
});

return await app.RunAsync(args);
}
}

0 comments on commit 2f8dcd6

Please sign in to comment.