-
Notifications
You must be signed in to change notification settings - Fork 390
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
Documentation for 'def' keyword signature should include optional syntax for the return type of the custom command #1035
Comments
I believe that currently, both input and output types are required, and also def square [x: int]: nothing -> int {
$x * $x
} or in the case of multiple possible input/output pairs: def square [x: int]: [ nothing -> int, nothing -> string ] {
if $x == 0 {
"zero"
} else {
$x * $x
}
} You can verify this with |
Ok, but none of the documentation I listed above mentions any of that. I agree that comment should exclude the point thatn being passed to another function that takes a particulartype. I think that the documentation should explicitly describe all of the of the 'def' keyword in all of its forms. What is the 'nothing' and the '[]: ' does not seem to work for 0.84.0 : × Parse mismatch during operation. |
I agree that the documentation should be updated to reflect the newly available syntax. |
Yes, definitely the docs need to be updated, I was just clarifying the syntax. The issue could live in https://github.com/nushell/nushell.github.io but here is also OK because we should update the output of @edhowland |
With #1167, this should now be halfway done; while not documented in the |
* Update command signature doc to modern syntax While implementing a custom alias, I found myself unable to provide an explicit command signature as described in the documentation. A bit of crawling the main repo's commit history led to my discovery that the syntax as described in the documentation was indeed outdated. After a bit of experimentation I was able to discover the correct annotation syntax. Ideally, in a slightly longer timescale than I am willing to deal with right now, this change shouldn't be needed; I believe the information on this page would serve better integrated with the rest of the documentation. It seems as though it would fit better there after the syntax change. * Update signature doc with single type example This should bring the syntax more in-line with the discussion in #1035. * Update signature doc with clearer examples. I've also removed the `cell-path` paragraph. It's probably fine(?) as again that should already be elsewhere. Furthermore, I've decided that instead of omitting some types from `str distance` that instead it would be better to just select a command with one non-`<nothing>` pipeline signature. Surprisingly challenging! `histogram` seems like it should do the trick, though. * Update signature doc primary example amtoine suggested that `str stats` is used in the first example rather than `histogram`, as unlike `str stats`, `histogram` is not a default command.
Describe the bug
Custom commands defined using the 'def' keyword allow, in addition to specifying
the optional parameter types, also allow for specifying an optional return
type. E.g.
The '-> ' is not mentioned in any of the documentation for either
the 'def' keyword or the Nushell book chapter on Custom Commands:
The def keyword
https://www.nushell.sh/commands/docs/def.html
Note: The same text as in the command reference for the 'def' keyword is output
when you type:
help def
and should also include the optional '-> part of the signature.
The Custom Command chapter
https://www.nushell.sh/book/custom_commands.html
In the command reference or the help text there should be:
In the chapter on "Custom Commands",
there should be a Heading 2 section called something like
Specifying the return type of your command
Custom commands can optionally specify their return type which helps the Nushell
compiler to check your usage when calling your custom command especially in an expression.
Eg. Say we just want to format our greeting like this:
How to reproduce
This is just a documentation ommision. There is no steps to reproduce this bug. Just add the missing documentation.
Expected behavior
The documentation on the web site for the Nushell book and the command reference should be updated to include the optional return type syntax for defining custom commands. This should also be included in the help text for the 'def' keyword.
Screenshots
No response
Configuration
Additional context
No response
The text was updated successfully, but these errors were encountered: