Skip to content

Commit 6dfacf8

Browse files
author
Paul Joiner
committed
Fixed system.commandline issues for magic commands
1 parent dd4b441 commit 6dfacf8

File tree

6 files changed

+313
-69
lines changed

6 files changed

+313
-69
lines changed

NuGet.config

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<solution>
4-
<add key="disableSourceControlIntegration" value="true" />
5-
</solution>
63
<packageSources>
7-
<clear />
8-
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
9-
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
10-
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
11-
<add key="dotnet-libraries" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json" />
12-
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
13-
<add key="MachineLearning" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json" />
14-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
155
</packageSources>
16-
<disabledPackageSources />
176
</configuration>

notebooks/01_Introduction.ipynb

Lines changed: 122 additions & 16 deletions
Large diffs are not rendered by default.

notebooks/06_DataMapping.ipynb

Lines changed: 161 additions & 14 deletions
Large diffs are not rendered by default.

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
using DwC_A.Interactive.Mapping;
77
using Microsoft.DotNet.Interactive;
88
using Microsoft.DotNet.Interactive.Events;
9-
using Microsoft.DotNet.Interactive.ValueSharing;
109
using System;
1110
using System.CommandLine;
12-
using System.CommandLine.Invocation;
1311
using System.IO;
1412
using System.Threading.Tasks;
1513

@@ -20,36 +18,41 @@ internal class DwcaCodegenCommand : Command
2018
public DwcaCodegenCommand()
2119
: base("#!dwca-codegen", "Generate strongly typed class files for Darwin Core Archive")
2220
{
23-
AddArgument(new Argument<string>()
21+
var archivePathArg = new Argument<string>()
2422
{
2523
Name = "archivePath",
2624
Description = "Path to archive folder or zip file"
27-
});
25+
};
26+
AddArgument(archivePathArg);
2827

29-
AddOption(new Option<string>(
30-
aliases: new[] {"-c", "--configName"},
28+
var cfgOption = new Option<string>(
29+
aliases: new[] { "-c", "--configName" },
3130
description: "Name of configuration variable",
3231
getDefaultValue: () => ""
33-
));
32+
);
33+
AddOption(cfgOption);
3434

35-
Handler = CommandHandler.Create<KernelInvocationContext, string, string>((Func<KernelInvocationContext, string, string, Task>)(async (context, archivePath, configName) =>
35+
System.CommandLine.Handler.SetHandler(this,async (context) =>
3636
{
37+
var archivePath = context.ParseResult.GetValueForArgument(archivePathArg);
38+
var configName = context.ParseResult.GetValueForOption(cfgOption);
3739
var archive = new ArchiveReader(archivePath);
3840

39-
var csharpKernel = (ISupportGetValue)context.HandlingKernel.FindKernel("csharp");
40-
if (!csharpKernel.TryGetValue<IGeneratorConfiguration>(configName, out IGeneratorConfiguration config))
41-
{
42-
config = new GeneratorConfigurationBuilder().Build();
43-
}
44-
context.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
45-
context.Display(config, new[] { "text/html" });
41+
var csharpKernel = KernelInvocationContext.Current.HandlingKernel.FindKernelByName("csharp");
42+
var (success, value) = await csharpKernel.TryRequestValueAsync(configName);
43+
IGeneratorConfiguration config = success ?
44+
value.Value as IGeneratorConfiguration :
45+
null ??
46+
new GeneratorConfigurationBuilder().Build();
47+
KernelInvocationContext.Current.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
48+
KernelInvocationContext.Current.Display(config, new[] { "text/html" });
4649

47-
await GenerateClass(context, archive.CoreFile, config);
48-
foreach(var extension in archive.Extensions.GetFileReaders())
50+
await GenerateClass(KernelInvocationContext.Current, archive.CoreFile, config);
51+
foreach (var extension in archive.Extensions.GetFileReaders())
4952
{
50-
await GenerateClass(context, extension, config);
53+
await GenerateClass(KernelInvocationContext.Current, extension, config);
5154
}
52-
}));
55+
});
5356
}
5457

5558
private static async Task GenerateClass(KernelInvocationContext context,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
using Microsoft.DotNet.Interactive;
22
using System;
33
using System.CommandLine;
4-
using System.CommandLine.Invocation;
54

65
namespace DwC_A.Interactive.Commands
76
{
87
internal class TermsCommand : Command
98
{
109
public TermsCommand() : base("#!terms", "Display Darwin Core standard terms")
1110
{
12-
Handler = CommandHandler.Create((KernelInvocationContext invocationContext) =>
11+
System.CommandLine.Handler.SetHandler(this, (invocationContext) =>
1312
{
1413
var defaultTerms = new DefaultTerms();
15-
invocationContext.Display(defaultTerms);
14+
KernelInvocationContext.Current.Display(defaultTerms);
1615
});
1716
}
1817
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.9-Pre</Version>
14+
<Version>0.1.12-Pre</Version>
1515
<Description>.NET Interactive Extensions for Darwin Core Archive file reader</Description>
16-
<AssemblyVersion>0.1.9.0</AssemblyVersion>
17-
<FileVersion>0.1.9.0</FileVersion>
16+
<AssemblyVersion>0.1.12.0</AssemblyVersion>
17+
<FileVersion>0.1.12.0</FileVersion>
1818
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
2020
</PropertyGroup>
@@ -24,8 +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-*" />
28-
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.21575.1" />
27+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
28+
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22504.6" />
2929
</ItemGroup>
3030

3131
<ItemGroup>

0 commit comments

Comments
 (0)