Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nushell-prophet/dotnu
dotnu - tools for Nushell module developers ๐ ๏ธ
https://github.com/nushell-prophet/dotnu
cool-stuff developer-tools nushell terminal
Last synced: 5 days ago
JSON representation
dotnu - tools for Nushell module developers ๐ ๏ธ
- Host: GitHub
- URL: https://github.com/nushell-prophet/dotnu
- Owner: nushell-prophet
- License: unlicense
- Created: 2024-02-29T16:12:38.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-01-21T04:06:07.000Z (6 days ago)
- Last Synced: 2025-01-21T05:18:32.676Z (6 days ago)
- Topics: cool-stuff, developer-tools, nushell, terminal
- Language: Nushell
- Homepage:
- Size: 321 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nu - dotnu
README
![dotnu](https://github.com/user-attachments/assets/4fb74e46-f75b-4155-8e61-8ff75db66117)
dotnu - tools for Nushell module developers ๐ ๏ธ
(A good companion for numd)
## dotnu video demo
## Quickstart
```nushell no-run
> git clone https://github.com/nushell-prophet/dotnu; cd dotnu
> use dotnu
```## Commands
### dotnu dependencies
```nushell
> 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 : paths to nushell module files
//
//
// Input/output types:
// โญโ#โโฌโinputโโฌโoutputโโฎ
// โ 0 โ any โ any โ
// โฐโ#โโดโinputโโดโoutputโโฏ
//
//
// 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
```nushell
> 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
//
//
// Input/output types:
// โญโ#โโฌโinputโโฌโoutputโโฎ
// โ 0 โ any โ any โ
// โฐโ#โโดโinputโโดโoutputโโฏ
//
//
// 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:
```nushell
> 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).
```nushell
> dotnu parse-docstrings $hello_module_path | reject input | get 0 | table -e
โญโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ command_name โ main โ
โ 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:
1. The command description and example blocks are divided by a line with only the `#` symbol. The command description is optional.
2. Examples of command usage may contain their own annotations (rows before the line starting with `>`). Example annotations are optional.
3. 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.
```nushell
> 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_path>
//
//
// Flags:
// --command-filter : filter commands by their name to update examples at (default: '')
// --use-statement : 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_path provided
// --no-git-check: don't check for the emptiness of the working tree
//
//
// Parameters:
// $module_path : path to a nushell module file
//
//
// Input/output types:
// โญโ#โโฌโinputโโฌโoutputโโฎ
// โ 0 โ any โ any โ
// โฐโ#โโดโinputโโดโoutputโโฏ
```### 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
```nushell
> 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
```nushell
> 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
```nushell
> dotnu generate-nupm-tests --help | numd parse-help
// Description:
// Generate nupm tests from examples in docstrings
//
//
// Usage:
// > generate-nupm-tests {flags} <$module_path>
//
//
// Flags:
// --echo: output script to stdout instead of updating the module_path provided
//
//
// Parameters:
// $module_path : path to a nushell module file
//
//
// Input/output types:
// โญโ#โโฌโinputโโฌโoutputโโฎ
// โ 0 โ any โ any โ
// โฐโ#โโดโinputโโดโoutputโโฏ
```