-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle multiple #!set commands in sungle submission #2960
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
using System.CommandLine.Invocation; | ||
using System.CommandLine.NamingConventionBinder; | ||
using System.CommandLine.Parsing; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
|
@@ -215,7 +216,7 @@ private static async Task HandleSetMagicCommand<T>( | |
T kernel, | ||
InvocationContext cmdLineContext, | ||
Option<string> nameOption, | ||
Option<object> valueOption, | ||
Option<ValueOptionResult> valueOption, | ||
Option<string> mimeTypeOption, | ||
Option<bool> byrefOption) | ||
where T : Kernel | ||
|
@@ -230,8 +231,14 @@ private static async Task HandleSetMagicCommand<T>( | |
var events = new List<ValueProduced>(); | ||
|
||
using var subscription = context.KernelEvents.OfType<ValueProduced>().Subscribe(events.Add); | ||
|
||
var valueSource = cmdLineContext.ParseResult.GetValueForOption(valueOption); | ||
|
||
|
||
var valueProduced = events.SingleOrDefault(); | ||
var valueProduced = valueSource switch | ||
{ { Name: var sourceValueName, Kernel: var sourceKernelName } when !string.IsNullOrWhiteSpace(sourceKernelName) && !string.IsNullOrEmpty(sourceKernelName) && sourceKernelName != "input" => events.SingleOrDefault(e => e.Name == sourceValueName && e.Command.TargetKernelName == sourceKernelName), | ||
_ => null | ||
}; | ||
|
||
if (valueProduced is { }) | ||
{ | ||
|
@@ -242,15 +249,16 @@ private static async Task HandleSetMagicCommand<T>( | |
} | ||
else | ||
{ | ||
var interpolatedValue = cmdLineContext.ParseResult.GetValueForOption(valueOption); | ||
|
||
await SendValue(kernel, interpolatedValue, null, valueName); | ||
await SendValue(kernel,valueSource?.Value, null, valueName); | ||
} | ||
} | ||
else | ||
{ | ||
context.Fail(context.Command, new CommandNotSupportedException(typeof(SendValue), kernel)); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: Remove blank lines |
||
} | ||
|
||
public static T UseValueSharing<T>(this T kernel) where T : Kernel | ||
|
@@ -293,7 +301,7 @@ private static void ConfigureAndAddSetMagicCommand<T>(T destinationKernel) where | |
HtmlFormatter.MimeType, | ||
PlainTextFormatter.MimeType); | ||
|
||
var valueOption = new Option<object>( | ||
var valueOption = new Option<ValueOptionResult>( | ||
"--value", | ||
description: | ||
LocalizationResources.Magics_set_value_Description(), | ||
|
@@ -355,13 +363,13 @@ destinationKernel.RootKernel is CompositeKernel root && | |
|
||
destinationKernel.AddDirective(set); | ||
|
||
object ParseValueOption(ArgumentResult argResult) | ||
ValueOptionResult ParseValueOption(ArgumentResult argResult) | ||
{ | ||
var valueOptionValue = argResult.Tokens.Single().Value; | ||
|
||
if (!valueOptionValue.StartsWith("@")) | ||
{ | ||
return valueOptionValue; | ||
return new ValueOptionResult( valueOptionValue, null,null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider using named params for the nulls |
||
} | ||
|
||
bool isByref; | ||
|
@@ -412,15 +420,17 @@ object ParseValueOption(ArgumentResult argResult) | |
|
||
if (isByref) | ||
{ | ||
return valueProduced.Value; | ||
return new ValueOptionResult(valueProduced.Value, sourceKernelName, sourceValueName); | ||
} | ||
else | ||
{ | ||
return valueProduced.FormattedValue; | ||
return new ValueOptionResult(valueProduced.FormattedValue, sourceKernelName, sourceValueName); | ||
} | ||
} | ||
} | ||
|
||
private record ValueOptionResult(object Value, string Kernel, string Name); | ||
|
||
private static void ConfigureAndAddShareMagicCommand<T>(T kernel) where T : Kernel | ||
{ | ||
var sourceValueNameArg = new Argument<string>( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to split the long line...