From 3c47ee8a4c7850ce8f559b04a290577e86cae9b3 Mon Sep 17 00:00:00 2001 From: Harvmaster Date: Mon, 4 May 2026 12:14:40 +0000 Subject: [PATCH] Add documentation to the commands for the CLI --- src/cli/autocomplete/completions.ts | 1 - src/cli/autocomplete/scripts/bash.sh | 64 ++++++++--- src/cli/autocomplete/scripts/fish.fish | 62 +++++++---- src/cli/autocomplete/scripts/zsh.zsh | 53 ++++++--- src/cli/commands/invitation.ts | 142 ++++++++++++++++++++++++- src/cli/commands/mnemonic.ts | 22 ++++ src/cli/commands/receive.ts | 3 + src/cli/commands/resource.ts | 56 +++++++++- src/cli/commands/template.ts | 108 ++++++++++++++++++- src/cli/mnemonic.ts | 16 +++ src/cli/utils.ts | 8 ++ 11 files changed, 480 insertions(+), 55 deletions(-) diff --git a/src/cli/autocomplete/completions.ts b/src/cli/autocomplete/completions.ts index 3e702a5..24fcb1f 100644 --- a/src/cli/autocomplete/completions.ts +++ b/src/cli/autocomplete/completions.ts @@ -23,7 +23,6 @@ import { existsSync, readFileSync, appendFileSync, - writeFileSync, } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; diff --git a/src/cli/autocomplete/scripts/bash.sh b/src/cli/autocomplete/scripts/bash.sh index c91aa90..7c12ef4 100644 --- a/src/cli/autocomplete/scripts/bash.sh +++ b/src/cli/autocomplete/scripts/bash.sh @@ -1,7 +1,16 @@ -# bash completion for {{BIN_NAME}} -# Add to ~/.bashrc: eval "$({{BIN_NAME}} completions bash)" +# ------------------------------------------------------------------------------ +# Bash completion template for {{BIN_NAME}} +# ------------------------------------------------------------------------------ +# Installation: +# eval "$({{BIN_NAME}} completions bash)" +# +# This file is generated from a template. Placeholders (for example `{{OPTIONS}}`) +# are replaced at build/runtime with concrete command data from the CLI. +# ------------------------------------------------------------------------------ -# Find xo-complete in the same directory as xo-cli +# Prefer a globally-installed helper, but fall back to a helper co-located with +# the CLI binary. This lets completions work in both "installed via PATH" and +# "single extracted directory" workflows. __xo_complete_bin="" if command -v xo-complete &>/dev/null; then __xo_complete_bin="xo-complete" @@ -9,16 +18,28 @@ elif command -v {{BIN_NAME}} &>/dev/null; then __xo_complete_bin="$(dirname "$(command -v {{BIN_NAME}})")/xo-complete" fi -# Wrapper to call xo-complete helper +# @description +# Calls the dynamic completion helper and suppresses helper stderr so the shell +# completion menu stays clean even when the helper is unavailable or errors. +# @param "$@" Arguments forwarded to xo-complete. __xo_complete() { [[ -n "${__xo_complete_bin}" ]] && "${__xo_complete_bin}" "$@" 2>/dev/null } +# @description +# Main completion dispatcher invoked by bash's `complete -F`. +# It determines context (command/subcommand/argument position) and then mixes: +# - static completions (known command words) +# - dynamic completions (resolved by xo-complete) +# - filesystem completions (when a subcommand expects file paths) _{{FUNC_NAME}}_completions() { local cur prev words cword + # Populates `cur`, `prev`, `words`, and `cword`. + # `_init_completion` is provided by bash-completion. _init_completion || return - # Handle -m/--mnemonic-file argument (previous word was -m) + # If the previous token is `-m/--mnemonic-file`, this argument expects a + # mnemonic file alias/path. Ask the helper for mnemonic suggestions. if [[ "${prev}" == "-m" || "${prev}" == "--mnemonic-file" ]]; then local mnemonics mnemonics=$(__xo_complete mnemonics "${cur}") @@ -30,13 +51,14 @@ _{{FUNC_NAME}}_completions() { fi fi - # If the current word starts with "-", offer option flags + # Option context: show global options when the current token starts with `-`. if [[ "${cur}" == -* ]]; then COMPREPLY=($(compgen -W "{{OPTIONS}}" -- "${cur}")) return 0 fi - # Find the command and subcommand positions + # Parse command/subcommand from non-option tokens before the current cursor. + # We track indices so argument-position logic can be computed later. local cmd="" subcmd="" cmd_idx=0 subcmd_idx=0 for ((i=1; i < cword; i++)); do if [[ "${words[i]}" != -* ]]; then @@ -51,13 +73,13 @@ _{{FUNC_NAME}}_completions() { fi done - # No command yet — offer the top-level commands + # No command selected yet: complete top-level commands. if [[ -z "${cmd}" ]]; then COMPREPLY=($(compgen -W "{{COMMANDS}}" -- "${cur}")) return 0 fi - # Handle each command's completion + # Command-specific completion rules. case "${cmd}" in mnemonic) if [[ -z "${subcmd}" ]]; then @@ -69,7 +91,9 @@ _{{FUNC_NAME}}_completions() { if [[ -z "${subcmd}" ]]; then COMPREPLY=($(compgen -W "{{TEMPLATE_SUBS}}" -- "${cur}")) elif [[ "${subcmd}" == "list" || "${subcmd}" == "inspect" ]]; then - # template list/inspect