Skip to main content
Skip to main content

args

Source code

This file contains functions for working with arguments

Index

:args

bash rust

This function will parse the command line arguments and set the variables for the user to use. It will also print the usage information if the user passes the -h or --help flag.

Example

local arg flag flag1 flag2 flag3 flag4 flag5 flag6="default"
local -a args
args=(
'arg' "positional argument" # required
'flag|' "flag with value"
'flag1|f' "flag with value and short"
'flag2|l:+' "flag without value"
'flag3|a:!' "required flag" # required
'flag4|b:~float' "flag with type"
'flag5|c:~int!' "required flag with type" # required
'flag6|d' "flag with default"
)
:args "Title" "${@}"

Arguments

  • $1 (string): The title of the usage
  • ... (array): User arguments

Variables set

  • args (array): [get] The arguments to parse

Exit codes

  • 0: If user arguments are correct
  • 2: If user arguments are incorrect

:usage::completion

rust

Generate shell completion scripts (bash, zsh, fish) from the usage array.

:usage::docgen

rust

Generate documentation in various formats (man, md, rst, yaml, llm) from the usage array.

:usage::mcp

rust

Run an MCP (Model Context Protocol) tool server over stdio, exposing subcommands as tools.

:usage

rust

Parse subcommands from the usage array and dispatch to the matching handler.

:usage::help

rust

Display formatted help text for subcommands defined in the usage array.

Was this section helpful?