-
Notifications
You must be signed in to change notification settings - Fork 385
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
[Proposal] Parameterization and user input via @input
tokens in magic commands
#1554
Comments
#!value
and host APIs#!value
and host APIs
Everything about this proposal looks great! In my vision of being able to author notebook and hand them off to non-technical people, the non technical people will likely prefer to run interactively at first and then may in the future want to swap to automated. If there is the same parameter validation across both invocation planes, then they will have a great experience.
If command line validation is desired, you'll need some way to type the input. At least in powershell, we have types as well as various validation attributes like [ValidateSet("one","other")]
[ValidateRange(10,99)]
[ValidatePattern("^\d\d$")] In powershell, you can set multiple of these on a single parameter, though, I find that to be rarely needed. So you'd possibly add another parameter to #!value --name iterations --prompt "The number of iterations" --type System.Int32
#!value --name iterations --prompt "The number of iterations" --validate range=10,100 --type System.Int32
#!value --name employee --prompt "Your full name" --validate "pattern=^(\w+ ){2,3}"
#!value --name oddNumber --prompt "Odd number between 1 and 10" --validate range=1,10 pattern=[13579] --type System.int32 I would think that for stuff like range validation, you'd cast a copy of the parameter to int and not change the actual type of the input to int. Sometimes people like to validate as numbers, but use as a string. You'd also want to make sure that you specify WHY user input is invalid: whether it was due to not being able to get cast or what validation rule it failed to pass (if a rule, also add why it failed the validation rule Hope this brainstorm helps flesh out the proposal of what things you do like and what you don't like from my thoughts. |
A few thoughts: We'd use System.CommandLine for the command line parsing and validation under the hood, but the magic commands should possibly avoid embedding .NET concepts such as types. Maybe we would use a constrained set of type signifiers that could be mapped easily into different kernel languages, e.g. "bool", "int", "float", "string", "file". |
No strong feelings either way from me on that. Seems fine. |
#!value
and host APIs@input
tokens in magic commands
Experimental support for this is available in |
Supplying a parameter to a notebook will necessarily behave differently when running the notebook interactively versus via automation. A gesture that can serve both purposes based on the context would be ideal.
Important goals would be:
Update: I've adjusted the proposal to account for a few recent improvements. The original proposal limited this functionality to the
#!value
magic command but we can now enable this for all magic commands.One approach that would satisfy all of the above would be to use the
@input:
prefix available in magic command tokens to declare required parameters. Consider the following example. (All API details here are for illustration only.)#!value --name iterations --from-value @input:number_of_iterations`
Running this interactively currently produces a user input prompt:
Running the notebook non-interactively from the command line, the proposal is to allow the value to provided something like this:
> dotnet interactive run mynotebook.ipynb --iterations 123
When the notebook is exported as a command line app (#1275), these parameters would be explicitly converted into options for the command line interface.
The value in this example would be stored in the value kernel and be available for sharing to other kernels. Other magic commands could also take advantage of this, anywhere where an
@input:
- or@password:
-prefixed token is valid.Type safety and validation of these inputs can be known based on the target type designated by System.CommandLine, and potentially stored in the document model (
Microsoft.DotNet.Interactive.Documents.InteractiveDocument
) in order to be used for tooling (e.g. generating command line tools with input validation or forms with richer UI) without running the notebook.The text was updated successfully, but these errors were encountered: