Repository navigation
docs(nushell): add script and path rules - #20
Merged
Merged
Conversation
Replace the argument-splicing trap with a defensive rule against passing untrusted strings as script arguments, and add traps for flags on def main, which subcommands do not inherit, and for piping an external command into ignore, which hides its failure. Bump hakula-languages to 1.0.5.
Nushell now tracks the behaviour publicly in nushell/nushell#19484, so the trap names the three shapes with harmless examples before the defensive rule.
Qualify the flag-name example, list the three argument shapes with semicolons, name FILE_PWD beside CURRENT_FILE, and join the plugin manifest path's literal run as one string.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The nushell skill gains two traps from recent devkit work and rules for path joins and script-relative paths, and its script-argument trap now names the three argument shapes that run as code on Nushell 0.116.1, followed by a defensive rule.
nu <script> <args>re-parses the arguments as source text and leaves three shapes unquoted, as nushell/nushell#19484 reports: a--argument's name part, a bare redirection token, and an argument starting with...$. The trap names each with a harmless example, then tells writers never to pass an untrusted string as a script argument, and to pass it through stdin, an environment variable, or a file, or check it against an allowlist pattern first. The old bullet named only the first shape and put the burden on callers to avoid it.def maindoes not reachdef "main <sub>", soscript sub --flagfails with an unknown flag andscript --flag subpassessubtomain.| ignore: piping an external command intoignorediscards its exit status, so the script continues and can exit 0.path joinas one/-separated string, as inpath join "libexec/gnubin", with a separate argument only for each segment from a variable. This matches the single-string form that comparable Nushell scripts use. The two joins innix/check-skills.nuthat split a literal run now follow the rule.path selfconstant at the top, such asconst SCRIPT_DIR = path self ".", sincepath selfruns only at parse time and names the file it appears in, while$env.FILE_PWDand$env.CURRENT_FILEpoint at the running script even inside a module.Bump hakula-languages to 1.0.5.
Test plan
nix develop -c run-hooksnix flake check --all-systemsclaude plugin validate .def main [x]reportsintfornu script.nu 8andboolfortrue, each of the three shapes runs as code with a harmlessprintor redirection to a scratch file, a--name=valueargument stays quoted, and data passed through--stdinor an environment variable arrives as a plain stringnu script.nu sub --verbosefails withnu::parser::unknown_flagandnu script.nu --verbose subwithnu::parser::extra_positionalwhen onlymaindeclares--verbosepath join "libexec/gnubin"andpath join "libexec" "gnubin"yield the same pathconst SCRIPT_DIR = path self "."gives the script's directory, a module'spath selfgives the module's directory, the module's$env.CURRENT_FILEgives the main script, and an inlinepath selfinsidemainfails withthis command can only run during parse-time^false | ignoreand thenprintprints and exits 0, while^false | linesends it with exit 1