Awesome
<h1 align="center"><strong>dotnu - tools for Nushell module developers ๐ ๏ธ</strong></h1> <p align="center"><em>(A good companion for <a href="https://github.com/nushell-prophet/numd">numd</a>)</em></p>dotnu video demo
<a href="https://youtu.be/-C7_dfLXXrE"> <img src="https://github.com/user-attachments/assets/fdd07bfc-7d77-4dca-8a1c-3e27ac3063f9" alt="dotnu demo" width="100"/> </a>Quickstart
> git clone https://github.com/nushell-prophet/dotnu; cd dotnu
> use dotnu
Commands
dotnu dependencies
> dotnu dependencies --help | numd parse-help
Description:
Check .nu module files to determine which commands depend on other commands.
Usage:
> dependencies {flags} ...(paths)
Flags:
--keep_builtins - keep builtin commands in the result page
--definitions_only - output only commands' names definitions
Parameters:
...paths <path>: paths to nushell module files
Examples:
> dependencies ...(glob tests/assets/module-say/say/*.nu)
โญโ#โโฌโโcallerโโโฌโfilename_of_callerโโฌโโcalleeโโโฌโstepโโฎ
โ 0 โ hello โ hello.nu โ โ 0 โ
โ 1 โ question โ ask.nu โ โ 0 โ
โ 2 โ say โ mod.nu โ hello โ 0 โ
โ 3 โ say โ mod.nu โ hi โ 0 โ
โ 4 โ say โ mod.nu โ question โ 0 โ
โ 5 โ hi โ mod.nu โ โ 0 โ
โ 6 โ test-hi โ test-hi.nu โ hi โ 0 โ
โฐโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโฏ
dotnu filter-commands-with-no-tests
> dotnu filter-commands-with-no-tests --help | numd parse-help
Description:
Filter commands after `dotnu dependencies` that aren't used by any other command containing `test` in its name.
Usage:
> filter-commands-with-no-tests
Examples:
> dependencies ...(glob tests/assets/module-say/say/*.nu) | filter-commands-with-no-tests
โญโ#โโฌโโcallerโโโฌโfilename_of_callerโโฎ
โ 0 โ hello โ hello.nu โ
โ 1 โ question โ ask.nu โ
โ 2 โ say โ mod.nu โ
โฐโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโฏ
dotnu parse-docstrings
dotnu parse-docstrings
parses command definitions along with their docstrings from a module file and outputs a table. It uses regex instead of the internal parsing engine of nushell to enable str replace
operations inside the dotnu update-docstring-examples
that will be showecased further.
To see it in action let's first examine an example module:
> let hello_module_path = [tests assets module-say say hello.nu] | path join
> open $hello_module_path | lines
โญโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ 0 โ # Output greeting! โ
โ 1 โ # โ
โ 2 โ # Say hello to Maxim โ
โ 3 โ # > hello Maxim โ
โ 4 โ # hello Maxim! โ
โ 5 โ # โ
โ 6 โ # Say hello to Darren โ
โ 7 โ # and capitlize letters โ
โ 8 โ # > hello Darren โ
โ 9 โ # | str capitalize โ
โ 10 โ # Hello Darren! โ
โ 11 โ export def main [name: string] { โ
โ 12 โ $"hello ($name)!" โ
โ 13 โ } โ
โฐโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
And now let's use dotnu parse-docstrings
and see its structured output (I get 0 row here for better output formatting).
> dotnu parse-docstrings $hello_module_path | reject input | get 0 | table -e
โญโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ command_name โ hello โ
โ command_description โ Output greeting! โ
โ โ โญโ#โโฌโโโโโโannotationโโโโโโโโฌโโโโโcommandโโโโโโโฌโโโโresultโโโโโโฎ โ
โ examples โ โ 0 โ Say hello to Maxim โ > hello Maxim โ hello Maxim! โ โ
โ โ โ 1 โ Say hello to Darren โ > hello Darren โ Hello Darren! โ โ
โ โ โ โ and capitlize letters โ | str capitalize โ โ โ
โ โ โฐโ#โโดโโโโโโannotationโโโโโโโโดโโโโโcommandโโโโโโโดโโโโresultโโโโโโฏ โ
โฐโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
dotnu parse-docstrings
uses the following assumptions:
- The command description and example blocks are divided by a line with only the
#
symbol. The command description is optional. - Examples of command usage may contain their own annotations (rows before the line starting with
>
). Example annotations are optional. - Examples of command usage consist of consecutive lines starting with
>
or|
symbols.
dotnu update-docstring-examples
dotnu update-docstring-examples
executes and updates examples in the specified nushell module file.
To prevent data loss it checks the current repository for uncommitted changes (this check can be disabled using --no_git_check
).
If an example produces an error, this error is printed to the terminal output, and the file is updated with the text example update failed
on the failed example result place.
> dotnu update-docstring-examples --help | numd parse-help
Description:
Execute examples in the docstrings of the module commands and update the results accordingly.
Usage:
> update-docstring-examples {flags} <module_file>
Flags:
--command_filter <String> - filter commands by their name to update examples at (default: '')
--use_statement <String> - use statement to execute examples with (like 'use module.nu'). Can be omitted to try to deduce automatically (default: '')
--echo - output script to stdout instead of updating the module_file provided
--no_git_check - don't check for the emptiness of the working tree
Parameters:
module_file <path>: path to a nushell module file
dotnu set-x
dotnu set-x
opens a regular .nu script. It divides it into blocks using the specified regex (by default, it is "\n\n") and generates a new script that will print the code of each block before executing it, along with the timings of each block's execution.
Let's check the code of the simple set-x-demo.nu
script
> let $filename = [tests assets set-x-demo.nu] | path join
> open $filename | lines | table -i false
โญโโโโโโโโโโโโโโโฎ
โ sleep 0.5sec โ
โ โ
โ sleep 0.7sec โ
โ โ
โ sleep 0.8sec โ
โฐโโโโโโโโโโโโโโโฏ
Let's see how dotnu set-x
will modify this script
> dotnu set-x $filename --echo | lines | table -i false
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ mut $prev_ts = date now โ
โ print ("> sleep 0.5sec" | nu-highlight) โ
โ sleep 0.5sec โ
โ print $'(ansi grey)((date now) - $prev_ts)(ansi reset)'; $prev_ts = (date now); โ
โ โ
โ โ
โ print ("> sleep 0.7sec" | nu-highlight) โ
โ sleep 0.7sec โ
โ print $'(ansi grey)((date now) - $prev_ts)(ansi reset)'; $prev_ts = (date now); โ
โ โ
โ โ
โ print ("> sleep 0.8sec" | nu-highlight) โ
โ sleep 0.8sec โ
โ print $'(ansi grey)((date now) - $prev_ts)(ansi reset)'; $prev_ts = (date now); โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
dotnu generate-nupm-tests
> dotnu generate-nupm-tests --help | numd parse-help
Description:
Generate nupm tests from examples in docstrings
Usage:
> generate-nupm-tests {flags} <$module_file>
Flags:
--echo - output script to stdout instead of updating the module_file provided
Parameters:
$module_file <path>: path to a nushell module file