Skip to content

Commit ba7ad76

Browse files
committed
Updated commands to use new System.Commandline
1 parent 308c85f commit ba7ad76

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

NuGet.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<add key="disableSourceControlIntegration" value="true" />
55
</solution>
66
<packageSources>
7-
<clear />
7+
88
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
99
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
1010
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />

src/DwC-A_dotnet.Interactive/Commands/DwcaCodegenCommand.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,29 @@
99
using Microsoft.DotNet.Interactive.ValueSharing;
1010
using System;
1111
using System.CommandLine;
12-
using System.CommandLine.NamingConventionBinder;
1312
using System.IO;
1413
using System.Threading.Tasks;
1514

1615
namespace DwC_A.Interactive.Commands
1716
{
18-
internal class DwcaCodegenCommand : Command
17+
internal static class DwcaCodegenCommandFactory
1918
{
20-
public DwcaCodegenCommand()
21-
: base("#!dwca-codegen", "Generate strongly typed class files for Darwin Core Archive")
19+
public static Command Create()
2220
{
23-
AddArgument(new Argument<string>()
21+
var command = new Command("#!dwca-codegen", "Generate strongly typed class files for Darwin Core Archive");
22+
command.AddArgument(new Argument<string>()
2423
{
2524
Name = "archivePath",
2625
Description = "Path to archive folder or zip file"
2726
});
2827

29-
AddOption(new Option<string>(
28+
command.AddOption(new Option<string>(
3029
aliases: new[] {"-c", "--configName"},
3130
description: "Name of configuration variable",
3231
getDefaultValue: () => ""
3332
));
3433

35-
Handler = CommandHandler.Create<KernelInvocationContext, string, string>((Func<KernelInvocationContext, string, string, Task>)(async (context, archivePath, configName) =>
34+
command.SetHandler((Func<KernelInvocationContext, string, string, Task>)(async (context, archivePath, configName) =>
3635
{
3736
var archive = new ArchiveReader(archivePath);
3837

@@ -44,12 +43,14 @@ public DwcaCodegenCommand()
4443
context.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
4544
context.Display(config, new[] { "text/html" });
4645

47-
await GenerateClass(context, archive.CoreFile, config);
46+
await DwcaCodegenCommandFactory.GenerateClass(context, archive.CoreFile, config);
4847
foreach(var extension in archive.Extensions.GetFileReaders())
4948
{
50-
await GenerateClass(context, extension, config);
49+
await DwcaCodegenCommandFactory.GenerateClass(context, extension, config);
5150
}
5251
}));
52+
53+
return command;
5354
}
5455

5556
private static async Task GenerateClass(KernelInvocationContext context,
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using Microsoft.DotNet.Interactive;
22
using System;
33
using System.CommandLine;
4-
using System.CommandLine.NamingConventionBinder;
54

65
namespace DwC_A.Interactive.Commands
76
{
8-
internal class TermsCommand : Command
7+
internal static class TermsCommandFactory
98
{
10-
public TermsCommand() : base("#!terms", "Display Darwin Core standard terms")
9+
public static Command Create()
1110
{
12-
Handler = CommandHandler.Create((KernelInvocationContext invocationContext) =>
11+
var termsCmd = new Command("#!terms", "Display Darwin Core standard terms");
12+
termsCmd.SetHandler((KernelInvocationContext invocationContext) =>
1313
{
1414
var defaultTerms = new DefaultTerms();
1515
invocationContext.Display(defaultTerms);
1616
});
17+
return termsCmd;
1718
}
1819
}
1920
}

src/DwC-A_dotnet.Interactive/DwC-A_dotnet.Interactive.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<RootNamespace>DwC_A.Interactive</RootNamespace>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Copyright>Copyright © Paul Joiner 2021</Copyright>
@@ -11,10 +11,10 @@
1111
<PackageTags>DwC-A darwin-core Biodiversity</PackageTags>
1212
<Authors>Paul Joiner</Authors>
1313
<Company>Paul Joiner</Company>
14-
<Version>0.1.10-Pre</Version>
14+
<Version>0.1.20-Pre</Version>
1515
<Description>.NET Interactive Extensions for Darwin Core Archive file reader</Description>
16-
<AssemblyVersion>0.1.10.0</AssemblyVersion>
17-
<FileVersion>0.1.10.0</FileVersion>
16+
<AssemblyVersion>0.1.20.0</AssemblyVersion>
17+
<FileVersion>0.1.20.0</FileVersion>
1818
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
2020
</PropertyGroup>
@@ -24,9 +24,8 @@
2424
<Aliases>Core</Aliases>
2525
</PackageReference>
2626
<PackageReference Include="DwC-A_dotnet.Mapping" Version="0.6.3" />
27-
<PackageReference Include="System.CommandLine" Version="2.0.0-*" />
27+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.22071.1" />
2828
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22070.1" />
29-
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta2.22071.1" />
3029
</ItemGroup>
3130

3231
<ItemGroup>

src/DwC-A_dotnet.Interactive/DwCKernelExtension.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Core.DwC_A;
66
using Core.DwC_A.Meta;
77
using DwC_A.Interactive.Formatters;
8-
using System.CommandLine;
9-
using System.CommandLine.Invocation;
108
using System.Collections.Generic;
119
using DwC_A.Interactive.Commands;
1210
using DwC_A.Config;
@@ -24,8 +22,8 @@ public Task OnLoadAsync(Kernel kernel)
2422
Formatter.Register<IEnumerable<IRow>>(RowFormatter.Register, "text/html");
2523
Formatter.Register<IGeneratorConfiguration>(GeneratorConfigFormatter.Register, "text/html");
2624

27-
kernel.AddDirective(new TermsCommand());
28-
kernel.AddDirective(new DwcaCodegenCommand());
25+
kernel.AddDirective(TermsCommandFactory.Create());
26+
kernel.AddDirective(DwcaCodegenCommandFactory.Create());
2927

3028
return Task.CompletedTask;
3129
}

0 commit comments

Comments
 (0)