Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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 ๐Ÿ› ๏ธ

Awesome Lists containing this project

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


dotnu 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โ”€โ•ฏ
```