jonsequitur / dotnet-repl

A polyglot REPL built on .NET Interactive

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to set a variable with #!set

marckruzik opened this issue · comments

I am trying to use --input to set a variable as an entry parameter. I would like to pass a string in CLI that I can use as a C# variable in my notebook.

I have .dib file with the following:

#!set --name csVar --value @input:myinput
System.IO.File.WriteAllText(@"result.txt", csVar);
#!whos

In Polyglot notebook, everything is fine:
2023_05_22-11h36m52s-wip dib - notebook - Visual Studio Code

Then I use the following dotnet-repl:

dotnet repl --run wip.dib --exit-after-run --input myinput="hello" --output-path output.ipynb

But the cell with the #!set command outputs this error message (in output.ipynb):

Required command was not provided.
Unrecognized command or argument '#!set'.
Unrecognized command or argument '--name'.
Unrecognized command or argument 'csVar'.
Unrecognized command or argument '--value'.
Unrecognized command or argument 'hello'.

What should I write to make it work? Is #!set the right command to set a C# variable?

From the documentation, it's not clear how to pass a string variable from the CLI to the notebook, and use this variable outside a magic command.
https://github.com/dotnet/interactive/blob/main/docs/input-prompts.md

It might just be that an updated version of Microsoft.DotNet.Interactive is needed in dotnet-repl.

I realized that the problem here isn't that #!set doesn't work, it's that @input doesn't work.

Fixed by #87.