#!/usr/bin/env nu # SPDX-License-Identifier: AGPL-3.0-only # Copyright (c) 2026 MatrixFurry const module_path: path = "@MODULE_PATH@" const module_name = $module_path | path basename const print_usage = @PRINT_USAGE@ use std log use $module_path def main --wrapped [ # TODO: --choose (-c) # Interactively choose a function --help (-h) --list (-l) # List available commands --list-all # List all available commands, including hidden ones --interactive (-i) # Enter interactive shell with the module loaded ...cmd ] { if $interactive { exec nu -e $"use ($module_path); print '(ansi yellow)Module loaded.(ansi reset)'" } else if $list_all { print-functions --all } else if $help or $list or ($cmd | length) == 0 { print-functions } else { let cmd_str = $cmd | str join ' ' let function = get-functions | where ($cmd_str starts-with $it) | first if ($function | is-empty) { log error $"Unknown command: `($cmd_str)`" print-functions exit 1 } exec nu -c $"use ($module_path); ($module_name) ($cmd_str)" } } def get-functions [] { scope modules | where name == $module_name | get 0.commands.name } def print-functions [ --all (-a) # show hidden functions ] { get-functions | if $all {$in} else {$in | where $it not-starts-with "_"} | each {|function| let help = help $module_name $function | lines let short_description = $help | first | if $in == $"(ansi green)Usage(ansi reset):" { null } else { $in } mut table = { command: $"(ansi cyan)($function)(ansi reset)" description: $"(ansi lp)($short_description)(ansi reset)" } if $print_usage { let usage = $help | get ( ($help | enumerate | where item == $"(ansi green)Usage(ansi reset):").0.index + 1 ) | str trim $table = $table | merge {usage: $usage} } $table } | table --index false --theme rounded }