The framework provides utility functions organized by domain under src/main/shell/framework/bootstrap/context/libs/.
- Overview
- Logging (
radp_log_*) - OS Detection (
radp_os_*) - System Security (
radp_os_*) - System Resources (
radp_os_*) - Cron Management (
radp_os_crontab_*) - File System (
radp_io_*) - YAML Parsing (
radp_io_yaml_*) - User Prompts (
radp_io_prompt_*) - Retry/Wait (
radp_wait_until,radp_retry) - Sysctl Management (
radp_os_sysctl_*) - Kernel Module Management (
radp_os_*) - Service Management (
radp_os_service_*) - User/Group Management (
radp_os_*) - Network (
radp_net_*) - Arrays (
radp_nr_*) - Dry-Run Mode (
radp_exec_*) - CLI Infrastructure (
radp_cli_*) - IDE Integration (
radp_ide_*)
| Pattern | Meaning | Example |
|---|---|---|
radp_<domain>_* |
Public function | radp_os_get_distro_id |
radp_nr_* |
Nameref function (pass variable name, not value) | radp_nr_arr_merge_unique |
radp_cli_* |
CLI infrastructure | radp_cli_dispatch |
radp_app_* |
Application-level functions | radp_app_run |
radp_ide_* |
IDE integration | radp_ide_init |
*_is_* / *_has_* |
Boolean check (0=true, 1=false) | radp_os_is_pkg_installed |
__fw_* / __radp_* |
Private/internal (do not use) | — |
| Pattern | Meaning | Example |
|---|---|---|
gr_* |
Global readonly paths/config | gr_fw_root_path |
gw_* |
Global writable state/flags | gw_fw_run_initialized |
gwxa_* |
Global arrays | gwxa_fw_sourced_scripts |
gr_radp_fw_* |
Framework config values | gr_radp_fw_log_level |
gr_radp_extend_* |
User extension config | gr_radp_extend_myapp_api_url |
opt_* |
Command option (auto-set) | opt_dry_run |
args_* |
Command argument (auto-set) | args_name |
gopt_* |
App global option (auto-set) | gopt_config |
| Code | Meaning |
|---|---|
0 |
Success / True (for boolean functions) |
1 |
General error / False (for boolean functions) |
2 |
Missing or invalid arguments |
| Variable | Description |
|---|---|
gr_fw_root_path |
Framework installation root directory |
gr_fw_version |
Framework version string |
gr_fw_user_config_path |
User configuration directory |
gr_fw_app_config_path |
App bundled config directory (always points to source) |
gr_fw_context_cache_path |
Framework cache directory |
gw_fw_run_initialized |
Framework initialization flag |
gwxa_fw_sourced_scripts |
Array of sourced script paths |
Location: libs/logger/logger.sh
| Function | Description |
|---|---|
radp_log_debug(msg [script] [func] [line]) |
Log DEBUG message (requires GX_RADP_FW_LOG_DEBUG=true) |
radp_log_info(msg [script] [func] [line]) |
Log INFO message |
radp_log_warn(msg [script] [func] [line]) |
Log WARN message |
radp_log_error(msg [script] [func] [line]) |
Log ERROR message |
radp_log_raw(msg) |
Output raw content without formatting or level filtering |
All logging functions accept:
msg— Log message (required)script— Script name (optional, auto-detected fromBASH_SOURCE)func— Function name (optional, auto-detected fromFUNCNAME)line— Line number (optional, auto-detected fromBASH_LINENO)
| Variable | Description | Default |
|---|---|---|
GX_RADP_FW_LOG_DEBUG |
Enable debug logging | false |
GX_RADP_FW_LOG_LEVEL |
Minimum log level | info |
gr_radp_fw_log_level |
Log level (readonly) | info |
Enable debug logging (choose one):
# CLI flag (for scaffold apps)
myapp --debug hello
# YAML config (recommended for persistent settings)
# radp.fw.log.debug: true
# Environment variable
GX_RADP_FW_LOG_DEBUG=true myapp helloradp_log_debug "Connecting to database" # Only shown when debug is enabled
radp_log_info "Server started on port 8080"
radp_log_warn "Config file not found, using defaults"
radp_log_error "Failed to connect to API"
radp_log_raw "Plain output without formatting"Location: libs/toolkit/os/
| Function | Returns | Example Output |
|---|---|---|
radp_os_get_distro_os() |
OS kernel name | Linux, Darwin |
radp_os_get_distro_arch() |
System architecture | x86_64, aarch64, arm64 |
radp_os_get_distro_id() |
Distribution ID | ubuntu, fedora, osx |
radp_os_get_distro_name() |
Distribution name | Ubuntu, Fedora, macOS |
radp_os_get_distro_version() |
Version string | 22.04, 39, 14.0 |
radp_os_get_distro_pm() |
Package manager | apt-get, dnf, brew |
Check if a package is installed.
radp_os_is_pkg_installed (pm pkg)Parameters:
pm— Package manager (yum,dnf,apt,apt-get,brew)pkg— Package name
Returns: 0 if installed, 1 if not installed or unsupported PM
Example:
if radp_os_is_pkg_installed "$(radp_os_get_distro_pm)" git; then
echo "git is installed"
fiInstall packages with cross-platform support.
radp_os_install_pkgs ([packages...] [options])Options:
--update— Update package cache before installing--dry-run— Print commands without executing--check-only— Only check for missing packages--map <str>— Package mapping ("apt:pkg1,pkg2;dnf:pkg3")--pm <pm> <pkg...> --— Override packages for specific PM
Returns: 0 on success, 1 on error, 2 if missing packages (with --check-only)
Examples:
# Basic installation
radp_os_install_pkgs curl wget jq
# With package manager mapping
radp_os_install_pkgs curl --map "brew:curl;apt:curl,ca-certificates"
# Check only (no installation)
if ! radp_os_install_pkgs curl wget --check-only; then
echo "Missing packages"
fi
# Dry run
radp_os_install_pkgs nginx --update --dry-runLocation: libs/toolkit/os/02_security.sh
Disable SELinux. Sets SELinux to permissive mode temporarily and disables it in config.
radp_os_disable_selinux()Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success or already disabled, 1 on failure
Note: Only applicable on systems with SELinux (RHEL, CentOS, Fedora, etc.). On systems without SELinux, returns 0
immediately.
Example:
radp_os_disable_selinux || {
radp_log_error "Failed to disable SELinux"
return 1
}Disable firewalld. Stops and disables the firewalld service.
radp_os_disable_firewalld()Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success or already disabled, 1 on failure
Note: Only applicable on systems with firewalld (RHEL, CentOS, Fedora, etc.). On systems without firewalld, returns
0 immediately.
Example:
radp_os_disable_firewalld || {
radp_log_error "Failed to disable firewalld"
return 1
}Disable swap. Disables swap immediately and removes swap entries from fstab.
radp_os_disable_swap()Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success or already disabled, 1 on failure
Note: Required for Kubernetes nodes. Disables swap via swapoff -a and comments out swap entries in /etc/fstab
for persistence across reboots.
Example:
radp_os_disable_swap || {
radp_log_error "Failed to disable swap"
return 1
}Location: libs/toolkit/os/03_resource.sh
Check if system has at least the specified number of CPU cores.
radp_os_check_min_cpu_cores (min_cores)Parameters:
min_cores— Minimum required CPU cores
Returns: 0 if system meets requirement, 1 if not
Outputs: Warning message if requirement not met
Example:
if ! radp_os_check_min_cpu_cores 4; then
radp_log_error "Insufficient CPU cores for this application"
exit 1
fiCheck if system has at least the specified amount of RAM.
radp_os_check_min_ram (min_ram)Parameters:
min_ram— Minimum required RAM (supports GB, G, MB, M suffixes)- Examples:
"4GB","4G","4096MB","4096M","4096"(MB default)
- Examples:
Returns: 0 if system meets requirement, 1 if not
Outputs: Warning message if requirement not met
Example:
radp_os_check_min_ram 4GB || {
radp_log_error "System requires at least 4GB RAM"
exit 1
}
radp_os_check_min_ram 4G
radp_os_check_min_ram 4096MGet total system RAM in MB.
radp_os_get_total_ram_mb()Returns: 0 on success, 1 if unable to determine
Outputs: Total RAM in MB to stdout
Example:
ram_mb=$(radp_os_get_total_ram_mb)
echo "System has ${ram_mb}MB RAM"
ram_gb=$((ram_mb / 1024))
echo "System has ${ram_gb}GB RAM"Get total CPU cores count.
radp_os_get_cpu_cores()Returns: 0 on success, 1 if unable to determine
Outputs: Number of CPU cores to stdout
Example:
cores=$(radp_os_get_cpu_cores)
echo "System has $cores CPU cores"Location: libs/toolkit/os/07_cron.sh
Add or update crontab from a file. Merges contents of a crontab file into user's crontab.
radp_os_crontab_add (user crontab_file)Parameters:
user— User to update crontab forcrontab_file— Path to crontab file to merge
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
# Create a crontab file
cat >/tmp/my-crontab <<'EOF'
# Backup every day at 4 AM
0 4 * * * /usr/local/bin/backup.sh
EOF
radp_os_crontab_add "root" "/tmp/my-crontab"Create or replace crontab from content string.
radp_os_create_or_update_crontab (user content)Parameters:
user— User to update crontab forcontent— Crontab content (multiline string)
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
crontab_content=$(
cat <<'EOF'
# Daily backup at 4 AM
0 4 * * * /usr/local/bin/backup.sh
# Weekly cleanup on Saturday at 8 PM
0 20 * * 6 /usr/local/bin/cleanup.sh
EOF
)
radp_os_create_or_update_crontab "vagrant" "$crontab_content"Remove crontab entries matching pattern.
radp_os_crontab_remove (user pattern)Parameters:
user— User to update crontab forpattern— Grep pattern to match lines to remove
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
# Remove all backup-related cron entries
radp_os_crontab_remove "root" "backup.sh"
# Remove all gitlab-related cron entries
radp_os_crontab_remove "vagrant" "gitlab"List user's crontab entries.
radp_os_crontab_list ([user])Parameters:
user— User to list crontab for (optional, defaults to current user)
Returns: 0 on success, 1 on failure or no crontab
Outputs: Crontab contents to stdout
Example:
# List current user's crontab
radp_os_crontab_list
# List root's crontab
radp_os_crontab_list "root"
# Check if crontab has entries
if radp_os_crontab_list "vagrant" | grep -q "backup"; then
echo "Backup cron is configured"
fiLocation: libs/toolkit/io/
Resolve path to absolute with symlink expansion.
radp_io_get_path_abs ([target])Parameters:
target— File or directory path (defaults to caller's script path)
Returns: 0 on success
Outputs: Absolute resolved path
Example:
abs_path=$(radp_io_get_path_abs "./relative/path")
script_dir=$(radp_io_get_path_abs) # Current script's directoryDownload file from URL with curl/wget fallback.
radp_io_download (url dest [--silent | --progress])Parameters:
url— URL to download fromdest— Destination file path--silent— Suppress progress output (default)--progress— Show progress output
Returns: 0 on success, 1 on failure
Example:
radp_io_download "https://example.com/file.tar.gz" "/tmp/file.tar.gz"
radp_io_download "https://example.com/large.zip" "./large.zip" --progressExtract archive to destination directory.
radp_io_extract (archive dest)Parameters:
archive— Archive file pathdest— Destination directory (created if not exists)
Supported formats: tar.gz, tgz, tar.xz, tar.bz2, zip
Returns: 0 on success, 1 on failure
Example:
radp_io_download "https://example.com/app.tar.gz" "/tmp/app.tar.gz"
radp_io_extract "/tmp/app.tar.gz" "/opt/app"Create temporary directory with auto-cleanup.
radp_io_mktemp_dir ([prefix])Parameters:
prefix— Directory name prefix (default:radp)
Returns: 0 on success, 1 on failure
Outputs: Path to created temporary directory
Example:
tmp_dir=$(radp_io_mktemp_dir "myapp")
# Use $tmp_dir...
# Directory is automatically cleaned up on script exitAppend a line to file if it doesn't already exist (deduplication).
radp_io_append_line_unique (file_path line)Parameters:
file_path— Path to the fileline— Line content to append
Globals:
gr_sudo— Sudo command prefix (optional, used if file requires elevated permissions)
Returns: 0 on success (line added or already exists), 1 on failure
Example:
radp_io_append_line_unique "/etc/hosts" "127.0.0.1 myhost"
radp_io_append_line_unique "$HOME/.bashrc" "export PATH=\$PATH:/opt/bin"Location: libs/toolkit/io/05_yaml.sh
Simple YAML parsing using only grep/sed (no external dependencies like yq).
Note: For complex YAML operations (nested structures, variable references, merging), use the
yq-based functions inautoconfigure.shinstead.
Limitations:
- Only supports simple
key: valuepairs (no nested objects) - Only supports simple lists (
- itemformat) - Does not handle multi-line values
- Does not handle YAML anchors/aliases
Extract a scalar value from YAML content.
radp_io_yaml_get_value (key [content])Parameters:
key— The YAML key to extract (required)content— YAML content (optional, reads from stdin if not provided)
Returns: 0 on success
Outputs: The value for the specified key (quotes stripped)
Example:
# From variable
version=$(radp_io_yaml_get_value "version" "$yaml_content")
# From file via stdin
name=$(radp_io_yaml_get_value "name" <config.yaml)
# From pipe
author=$(echo "$yaml" | radp_io_yaml_get_value "author")Extract list items from YAML content.
radp_io_yaml_get_listParameters: None (reads from stdin)
Returns: 0 on success
Outputs: List items, one per line (leading - stripped)
Example:
# Parse list items
echo "$yaml_list" | radp_io_yaml_get_list
# Given input:
# - foo
# - bar
# Returns:
# foo
# barExtract a specific section from YAML content.
radp_io_yaml_get_section (key [content])Parameters:
key— The section key to extract (required)content— YAML content (optional, reads from stdin if not provided)
Returns: 0 on success
Outputs: All lines belonging to the section (including nested content)
Example:
# Extract dependencies section, then parse as list
deps=$(radp_io_yaml_get_section "dependencies" "$yaml" | radp_io_yaml_get_list)Check if a key exists in YAML content.
radp_io_yaml_has_key (key [content])Parameters:
key— The YAML key to check (required)content— YAML content (optional, reads from stdin if not provided)
Returns: 0 if key exists, 1 if not found
Example:
if radp_io_yaml_has_key "enabled" "$yaml_content"; then
echo "Key 'enabled' exists"
fiLocation: libs/toolkit/io/02_prompt.sh
Confirmation prompt (y/N style). Displays a message and waits for user confirmation.
radp_io_prompt_confirm (--msg <string >[--default <Y | N >] [--timeout <sec >] [--level <info | warn | error >])Parameters:
--msg <string>— Prompt message (required)--default <Y|N>— Default answer if user presses Enter (default:N)--timeout <sec>— Timeout in seconds (default:0, no timeout)--level <info|warn|error>— Log level for the prompt (default:info)
Returns: 0 if user confirmed (y/Y or default Y on timeout/empty input), 1 if user declined or timeout with
default N
Example:
radp_io_prompt_confirm --msg "Continue?" --default Y
radp_io_prompt_confirm --msg "Delete file?" --level warn --timeout 30
if radp_io_prompt_confirm --msg "Proceed with installation? (y/N)"; then
echo "Installing..."
fiInput prompt with nameref. Prompts user for input and stores result in a variable.
radp_nr_io_prompt_input (
nameref --msg <string >[--default <value >] [--timeout <sec >] [--level <info | warn | error >]
)Parameters:
nameref— Variable name to store user input (required, first positional argument)--msg <string>— Prompt message (required)--default <value>— Default value if user presses Enter--timeout <sec>— Timeout in seconds (default:0, no timeout)--level <info|warn|error>— Log level for the prompt (default:info)
Returns: 0 on success, 1 on timeout or error
Example:
local user_name
radp_nr_io_prompt_input user_name --msg "Enter your name:" --default "anonymous"
echo "Hello, $user_name"
local choice
radp_nr_io_prompt_input choice --msg "Select option:" --timeout 60Location: libs/toolkit/exec/02_retry.sh
Functions for waiting on conditions and retrying commands with configurable attempts and intervals.
Wait until a condition becomes true.
radp_wait_until (condition_cmd [--max-attempts N] [--interval N] [--message MSG])Parameters:
condition_cmd— Command to check (exit 0 = success)--max-attempts N— Maximum attempts (default:10)--interval N— Sleep interval in seconds (default:5)--message MSG— Progress message (optional)
Returns: 0 if condition became true, 1 if timeout (max attempts reached)
Example:
# Wait for Kubernetes cluster to be ready
radp_wait_until "kubectl cluster-info" --max-attempts 5 --interval 10
# Wait for network interface with custom message
radp_wait_until "ip link show flannel.1" \
--max-attempts 15 \
--interval 10 \
--message "Waiting for flannel..."Retry a command until it succeeds.
radp_retry (command [--max-attempts N] [--interval N] [--message MSG])Parameters:
command— Command to execute--max-attempts N— Maximum attempts (default:3)--interval N— Sleep interval between retries (default:2)--message MSG— Progress message (optional)
Returns: Exit code of the last command execution
Example:
# Retry curl with custom retry settings
radp_retry "curl -fsSL https://example.com" --max-attempts 5 --interval 3
# Retry with progress message
radp_retry "wget https://example.com/file.tar.gz" \
--max-attempts 3 \
--message "Downloading file..."Location: libs/toolkit/os/04_sysctl.sh
Functions for managing kernel parameters via sysctl.
Set a sysctl parameter temporarily (does not persist across reboots).
radp_os_sysctl_set (key value)Parameters:
key— sysctl parameter name (e.g.,net.ipv4.ip_forward)value— Value to set
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
radp_os_sysctl_set "net.ipv4.ip_forward" "1"
radp_os_sysctl_set "net.bridge.bridge-nf-call-iptables" "1"Check if a sysctl parameter has the expected value.
radp_os_sysctl_check (key expected)Parameters:
key— sysctl parameter nameexpected— Expected value
Returns: 0 if parameter matches expected value, 1 if not or error
Example:
if radp_os_sysctl_check "net.ipv4.ip_forward" "1"; then
echo "IP forwarding is enabled"
fiConfigure sysctl parameters persistently. Creates a config file in /etc/sysctl.d/ and applies settings.
radp_os_sysctl_configure_persistent (config_name key=value [key=value...])Parameters:
config_name— Name for the config file (without.confextension)key=value— One or more sysctl parameters to configure
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
# Configure Kubernetes networking requirements
radp_os_sysctl_configure_persistent "k8s" \
"net.bridge.bridge-nf-call-iptables=1" \
"net.bridge.bridge-nf-call-ip6tables=1" \
"net.ipv4.ip_forward=1"
# Creates /etc/sysctl.d/k8s.conf and applies settingsLocation: libs/toolkit/os/08_kernel.sh
Functions for loading and configuring kernel modules.
Check if a kernel module is currently loaded.
radp_os_is_kernel_module_loaded (module)Parameters:
module— Kernel module name
Returns: 0 if module is loaded, 1 if not
Example:
if radp_os_is_kernel_module_loaded "overlay"; then
echo "overlay module is loaded"
fiLoad one or more kernel modules.
radp_os_load_kernel_modules (module [module...])Parameters:
module— One or more kernel module names to load
Globals:
gr_sudo— Sudo command prefix
Returns: 0 if all modules loaded successfully, 1 if any failed
Example:
# Load modules required for Kubernetes
radp_os_load_kernel_modules "overlay" "br_netfilter"Configure kernel modules to load at boot. Creates a config file in /etc/modules-load.d/.
radp_os_configure_kernel_modules (config_name module [module...])Parameters:
config_name— Name for the config file (without.confextension)module— One or more kernel module names to configure
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
# Configure modules for boot persistence
radp_os_configure_kernel_modules "k8s" "overlay" "br_netfilter"
# Creates /etc/modules-load.d/k8s.confConfigure and load kernel modules (combines configure_kernel_modules and load_kernel_modules).
radp_os_setup_kernel_modules (config_name module [module...])Parameters:
config_name— Name for the config file (without.confextension)module— One or more kernel module names
Globals:
gr_sudo— Sudo command prefix
Returns: 0 on success, 1 on failure
Example:
# Configure for boot and load immediately
radp_os_setup_kernel_modules "k8s" "overlay" "br_netfilter"Location: libs/toolkit/os/09_service.sh
Functions for managing systemd services.
Enable and start a systemd service.
radp_os_service_enable_start (service_name)Parameters:
service_name— Name of the service (with or without.servicesuffix)
Returns: 0 on success, 1 on failure
Example:
radp_os_service_enable_start "docker"
radp_os_service_enable_start "containerd.service"Restart a systemd service.
radp_os_service_restart (service_name)Parameters:
service_name— Name of the service (with or without.servicesuffix)
Returns: 0 on success, 1 on failure
Example:
radp_os_service_restart "docker"Stop and disable a systemd service.
radp_os_service_stop_disable (service_name)Parameters:
service_name— Name of the service (with or without.servicesuffix)
Returns: 0 on success
Example:
radp_os_service_stop_disable "firewalld"Configure HTTP proxy for a systemd service. Creates a drop-in file for proxy environment variables.
radp_os_service_configure_http_proxy (service_name http_proxy [https_proxy] [no_proxy])Parameters:
service_name— Name of the service (e.g.,docker,containerd)http_proxy— HTTP proxy URL (required)https_proxy— HTTPS proxy URL (optional, defaults tohttp_proxy)no_proxy— Comma-separated list of hosts to bypass (optional, defaults tolocalhost,127.0.0.1)
Returns: 0 on success, 1 on failure
Example:
# Configure proxy for Docker
radp_os_service_configure_http_proxy "docker" \
"http://proxy.example.com:8080" \
"http://proxy.example.com:8080" \
"localhost,127.0.0.1,10.0.0.0/8"
# Creates /etc/systemd/system/docker.service.d/http-proxy.confRemove HTTP proxy configuration for a systemd service.
radp_os_service_remove_http_proxy (service_name)Parameters:
service_name— Name of the service (e.g.,docker,containerd)
Returns: 0 on success
Example:
radp_os_service_remove_http_proxy "docker"
# Removes /etc/systemd/system/docker.service.d/http-proxy.confLocation: libs/toolkit/os/10_user.sh
Functions for managing users and groups.
Check if a user belongs to a specific group.
radp_os_user_in_group (user group)Parameters:
user— Username to checkgroup— Group name to check membership in
Returns: 0 if user is in the group, 1 if not or error
Example:
if radp_os_user_in_group "vagrant" "docker"; then
echo "User can run Docker commands"
fiEnsure a group exists, creating it if necessary.
radp_os_ensure_group (group)Parameters:
group— Group name to ensure exists
Returns: 0 if group exists or was created, 1 on failure
Example:
radp_os_ensure_group "docker"Add a user to a group.
radp_os_user_add_to_group (user group)Parameters:
user— Username to addgroup— Group name to add user to
Returns: 0 if user added or already in group, 1 on failure
Note: User needs to log out and back in for group membership to take effect.
Example:
# Add user to docker group for rootless Docker access
radp_os_user_add_to_group "vagrant" "docker"Remove a user from a group.
radp_os_user_remove_from_group (user group)Parameters:
user— Username to removegroup— Group name to remove user from
Returns: 0 if user removed or not in group, 1 on failure
Example:
radp_os_user_remove_from_group "testuser" "docker"Get the current username.
radp_os_get_current_user()Outputs: Current username
Example:
current_user=$(radp_os_get_current_user)
echo "Running as: $current_user"Location: libs/toolkit/net/
Get latest release version from GitHub repository.
radp_net_github_latest_release (repo [--with-v])Parameters:
repo— GitHub repository (owner/repoformat)--with-v— Include leadingvif present in tag
Returns: 0 on success, 1 on failure
Outputs: Version string (e.g., 1.2.3 or v1.2.3 with --with-v)
Example:
version=$(radp_net_github_latest_release "junegunn/fzf")
echo "Latest fzf: $version" # e.g., "0.45.0"
version=$(radp_net_github_latest_release "cli/cli" --with-v)
echo "Latest gh: $version" # e.g., "v2.40.0"Download asset from GitHub release.
radp_net_github_download_asset (repo asset_pattern dest [--version ver])Parameters:
repo— GitHub repository (owner/repoformat)asset_pattern— Glob pattern to match asset namedest— Destination file path--version <ver>— Specific version (default: latest)
Returns: 0 on success, 1 on failure
Example:
# Download latest fzf binary for current platform
radp_net_github_download_asset "junegunn/fzf" \
"fzf-*-linux_amd64.tar.gz" \
"/tmp/fzf.tar.gz"
# Download specific version
radp_net_github_download_asset "sharkdp/bat" \
"bat-*-x86_64-unknown-linux-gnu.tar.gz" \
"/tmp/bat.tar.gz" \
--version "v0.24.0"Location: libs/toolkit/core/
Merge multiple arrays with deduplication.
radp_nr_arr_merge_unique (dest_name src_name [src_name...])Parameters: (all are variable names without $)
dest_name— Destination array variable namesrc_name— Source array variable names to merge
Returns: 0
Example:
local -a src1=("a" "b" "c")
local -a src2=("b" "c" "d")
local -a src3=("d" "e")
local -a result=()
radp_nr_arr_merge_unique result src1 src2 src3
# result = ("a" "b" "c" "d" "e")Location: libs/toolkit/exec/04_dry_run.sh
The dry-run mode support provides wrapper functions for command execution that respect a global dry-run flag. When dry-run mode is enabled, commands are logged instead of executed.
| Variable | Description |
|---|---|
gw_dry_run |
Global writable flag for dry-run mode ("true" or "") |
Enable or disable dry-run mode.
radp_set_dry_run ([enabled])Parameters:
enabled—"true","1", or empty to enable; any other value to disable (default:"true")
Example:
# Enable from CLI flag
radp_set_dry_run "${opt_dry_run:-}"
# Explicitly enable
radp_set_dry_run true
# Explicitly disable
radp_set_dry_run falseCheck if dry-run mode is enabled.
radp_is_dry_run()Returns: 0 if dry-run mode is enabled, 1 otherwise
Example:
if radp_is_dry_run; then
echo "Would perform operation..."
else
perform_operation
fiExecute command or log in dry-run mode.
radp_exec (description command [args...])Parameters:
description— Human-readable description of the operationcommand— Command to executeargs— Command arguments
Returns: 0 in dry-run mode, otherwise the command's exit code
Example:
radp_exec "Create config directory" mkdir -p /etc/myapp
radp_exec "Install package" apt-get install -y nginx
radp_exec "Start service" systemctl start nginxExecute command with sudo or log in dry-run mode.
radp_exec_sudo (description command [args...])Parameters:
description— Human-readable description of the operationcommand— Command to execute (will be prefixed with${gr_sudo:-})args— Command arguments
Returns: 0 in dry-run mode, otherwise the command's exit code
Note: Uses ${gr_sudo:-} which is set by the framework based on whether the current user is root.
Example:
radp_exec_sudo "Update package cache" apt-get update -qq
radp_exec_sudo "Install nginx" apt-get install -y nginx
radp_exec_sudo "Enable service" systemctl enable nginxCheck and log for complex operations that can't use radp_exec.
radp_dry_run_skip (description)Parameters:
description— Human-readable description of the operation being skipped
Returns: 0 if dry-run mode is enabled (operation should be skipped), 1 otherwise (proceed with operation)
Example:
if radp_dry_run_skip "Configure yadm repository"; then
radp_log_info "[dry-run] - Repository: $repo_url"
radp_log_info "[dry-run] - Would run bootstrap after clone"
return 0
fi
# Complex operations that can't be wrapped in radp_exec
yadm clone "$repo_url"
yadm bootstrapTypical usage in a CLI command with --dry-run flag:
# @cmd
# @desc Configure system settings
# @flag --dry-run Show what would be done without making changes
cmd_configure() {
# Enable dry-run from flag
radp_set_dry_run "${opt_dry_run:-}"
# Simple commands - use radp_exec or radp_exec_sudo
radp_exec_sudo "Install required packages" apt-get install -y curl wget
# Complex operations - use radp_dry_run_skip
if radp_dry_run_skip "Apply configuration changes"; then
radp_log_info "[dry-run] - Would modify /etc/myapp/config"
radp_log_info "[dry-run] - Would restart service"
return 0
fi
# Actual complex logic here
configure_application
restart_services
}Location: libs/toolkit/cli/
Configure application name, version, and description.
radp_app_config (name [version] [desc])Parameters:
name— Application nameversion— Application version (optional)desc— Application description (optional)
Example:
radp_app_config "myapp" "1.0.0" "My awesome CLI tool"For scaffold projects, use launcher.sh which handles all setup automatically:
#!/usr/bin/env bash
set -euo pipefail
if ! command -v radp-bf &>/dev/null; then
echo "Error: radp-bash-framework not found." >&2
exit 1
fi
export RADP_APP_ROOT="$(radp-bf path resolve "${BASH_SOURCE[0]}")"
source "$(radp-bf path launcher)" "$@"The launcher automatically:
- Detects dev/installed mode via
_ide.shmarker - Sets config and library paths
- Parses global options (
-v,--debug,--show-config) - Runs command dispatch
Simplified bootstrap with auto-detection. Use launcher.sh for new projects.
radp_app_bootstrap (app_root app_name [arguments...])Parameters:
app_root— Application root directoryapp_name— Application namearguments— Command-line arguments to pass
Main application entry point.
radp_app_run ([arguments...])Parameters:
arguments— Command-line arguments
Prerequisites: Commands directory must be set via radp_cli_set_commands_dir()
Note: When using launcher.sh, this is called automatically.
Output application version.
radp_app_version()Outputs: Application name and version
Note: Can be overridden by defining custom radp_app_version() before sourcing framework.
Check if help flag was passed.
radp_app_is_help_request ([arguments...])Returns: 0 if -h or --help present, 1 otherwise
Check if version flag was passed.
radp_app_is_version_request ([arguments...])Returns: 0 if -v or --version present, 1 otherwise
Example:
if radp_app_is_help_request "$@"; then
radp_cli_help
exit 0
fi
if radp_app_is_version_request "$@"; then
radp_app_version
exit 0
fiDisplay application configuration information. Outputs app info, framework settings, config paths, log settings, and optionally extension configurations.
radp_app_show_config()Output formats:
- Text (default): Docker info style grouped sections
- JSON: Machine-readable format (set
__RADP_APP_CONFIG_JSON=true) - With extensions: Include extension configs (set
__RADP_APP_CONFIG_ALL=true)
Example output (text):
App: myapp
Version: v1.0.0
Environment: local
Framework:
Version: v0.6.29
Root: /usr/local/opt/radp-bash-framework/libexec
Config:
Directory: /home/user/.config/myapp
File: /home/user/.config/myapp/config.yaml (exists)
Libs: /home/user/myapp/src/main/shell/libs
Settings:
Banner: off
Log:
Level: info
Debug: false
Console: enabled
File: enabled
File Path: /home/user/logs/radp/myapp.log
Log Rolling:
Enabled: true
Max History: 7
Max File Size: 10MB
Total Size: 5GB
Usage: This function is typically invoked via myapp --show-config global option (handled by launcher.sh). Use
--show-config --all to include extension configurations.
Set commands directory path.
radp_cli_set_commands_dir (commands_dir)Parameters:
commands_dir— Absolute path tocommands/directory
Returns: 0 on success, 1 if directory not found
Set application name for help/completion.
radp_cli_set_app_name (app_name)Set global options displayed in help.
radp_cli_set_global_options ([options...])Parameters:
options— Global option flags (e.g.,"-v","--verbose","--debug")
Example:
radp_cli_set_global_options "-v" "--verbose" "--debug"Discover all commands from commands directory.
radp_cli_discover()Returns: 0 on success, 1 if commands directory not set
Check if command exists.
radp_cli_cmd_exists (cmd_path)Parameters:
cmd_path— Command path (e.g.,"db migrate")
Returns: 0 if exists, 1 if not
Check if command has subcommands.
radp_cli_has_subcommands (cmd)Returns: 0 if has subcommands, 1 if not
List all top-level commands.
radp_cli_list_commands()Outputs: One command per line (sorted)
List subcommands for parent command.
radp_cli_list_subcommands (parent_cmd)Outputs: One subcommand per line (sorted)
Get command file path.
radp_cli_get_cmd_file (cmd_path)Returns: 0 if found, 1 if not
Outputs: Absolute path to command file
Get command metadata.
radp_cli_get_cmd_meta (cmd_path var_name)Parameters:
cmd_path— Command pathvar_name— Associative array variable name (nameref)
Returns: 0 on success, 1 if not found
Parse command metadata from file.
radp_cli_parse_meta (file_path var_name)Parameters:
file_path— Command file pathvar_name— Associative array variable name (nameref)
Returns: 0 on success, 1 if file not found or not a command
Parsed keys: desc, args, options, examples, completes, passthrough
Parse @arg declaration.
radp_cli_parse_arg_spec (arg_spec var_name)Parameters:
arg_spec— Argument specification stringvar_name— Associative array for result (nameref)
Parsed keys: name, required, variadic, desc
Parse @option declaration.
radp_cli_parse_option_spec (opt_spec var_name)Parameters:
opt_spec— Option specification stringvar_name— Associative array for result (nameref)
Parsed keys: short, long, has_value, value_name, default, desc
Build getopt option strings from metadata.
radp_cli_build_getopt_spec (options_spec)Parameters:
options_spec—@optiondeclarations (newline-separated)
Sets globals: __radp_cli_getopt_short, __radp_cli_getopt_long
Parse command-line arguments.
radp_cli_parse_args (options_spec args_spec [arguments...])Parameters:
options_spec—@optiondeclarationsargs_spec—@argdeclarationsarguments— Arguments to parse
Sets globals:
opt_<name>— Option values (e.g.,opt_verbose,opt_config)__radp_cli_positional_args— Positional arguments array__radp_cli_show_help—trueif--helpwas passed
Returns: 0 on success, 1 on error
Get positional argument by index.
radp_cli_get_arg (index [default])Parameters:
index— Argument index (0-based)default— Default value if not found (optional)
Outputs: Argument value or default
Get all positional arguments.
radp_cli_get_all_args()Outputs: All arguments space-separated
Get arguments from index onwards.
radp_cli_get_remaining_args (start_index)Parameters:
start_index— Starting index
Outputs: Arguments one per line
Auto-generate contextual help.
radp_cli_help ([cmd_path...])Parameters:
cmd_path— Command path for specific help (optional)
Behavior:
- No args: Show app-level help
- Command group: Show group help with subcommands
- Specific command: Show command help with args/options
Generate application-level help.
radp_cli_help_app()Generate command group help.
radp_cli_help_command_group (cmd)Generate specific command help.
radp_cli_help_command (cmd_path)Route arguments to command handler.
radp_cli_dispatch ([arguments...])Parameters:
arguments— Command-line arguments
Returns: Command's return code
Behavior:
- Parses command path from arguments
- Sources command file
- Parses options and arguments
- Calls
cmd_<path>()function
Get current executing command path.
radp_cli_current_cmd()Outputs: Current command path (e.g., "db migrate")
Generate shell completion script.
radp_cli_completion_generate (shell)Parameters:
shell— Shell type (bashorzsh)
Returns: 0 on success, 1 on invalid shell
Outputs: Complete shell completion script
Example:
# Generate and install bash completion
radp_cli_completion_generate bash >~/.local/share/bash-completion/completions/myapp
# Generate zsh completion
radp_cli_completion_generate zsh >~/.zfunc/_myappGenerate bash completion script.
radp_cli_completion_bash()Generate zsh completion script.
radp_cli_completion_zsh()Parse @complete declaration.
radp_cli_parse_complete_spec (complete_spec var_name)Parameters:
complete_spec— Completion specification string (e.g.,"name _complete_func")var_name— Associative array for result (nameref)
Parsed keys: name, func
Get completion function for a parameter or option.
radp_cli_get_complete_func (name completes)Parameters:
name— Parameter name or option long namecompletes— Completion specifications (newline-separated)
Returns: 0 if found, 1 if not found
Outputs: Completion function name
The @complete annotation enables dynamic shell completion for arguments and options.
# @complete <name> <function>name— Argument name or option long name (without--)function— Shell function that outputs completion values (one per line)
# @cmd
# @arg name! Package name
# @complete name _complete_packages
cmd_install() {
local name="$1"
# ...
}
_complete_packages() {
echo "fzf"
echo "bat"
echo "jq"
}# @cmd
# @option -e, --env <name> Target environment
# @complete env _complete_envs
cmd_deploy() {
local env="${opt_env:-production}"
# ...
}
_complete_envs() {
echo "development"
echo "staging"
echo "production"
}# Git branches
_complete_branches() {
git branch --format='%(refname:short)' 2>/dev/null
}
# SSH hosts from config
_complete_hosts() {
grep -E "^Host " ~/.ssh/config 2>/dev/null | awk '{print $2}' | grep -v '*'
}
# API data
_complete_users() {
curl -s https://api.example.com/users | jq -r '.[].name' 2>/dev/null
}# @cmd
# @arg src! Source file
# @arg dest! Destination
# @option -H, --host <name> Target host
# @complete src _complete_files
# @complete dest _complete_paths
# @complete host _complete_hostsCompletion functions can be defined in:
- Command file — Self-contained, simple commands
- User libraries (
libs/) — Reusable across commands, automatically loaded
See CLI Development Guide - Dynamic Completion for detailed examples.
Application-level global options are defined in commands/_globals.sh using @global annotations. These options are
available to all commands and use the gopt_ variable prefix.
Load application-level global options from _globals.sh.
radp_cli_load_app_global_options()Behavior:
- Scans
commands/_globals.shfor@globalannotations - Populates
__radp_cli_app_global_options(space-separated list for completion) - Populates
__radp_cli_app_global_options_spec(array of option specs)
Called automatically by launcher.sh before command dispatch.
Parse application global options from arguments (before command).
radp_cli_parse_app_global_options (args_var_name)Parameters:
args_var_name— Name of array variable containing arguments (modified in place)
Behavior:
- Extracts global options from the beginning of arguments
- Sets
gopt_<name>variables for each found option - Removes parsed options from the input array
Example:
local -a args=("-c" "/path" "list" "--verbose")
radp_cli_parse_app_global_options args
# gopt_config="/path"
# args=("list" "--verbose")Extract application global options from arguments (after command).
radp_cli_extract_app_global_options (args_var_name)Parameters:
args_var_name— Name of array variable containing command arguments (modified in place)
Behavior:
- Scans command arguments for global options
- Sets
gopt_<name>variables for each found option - Removes extracted options from the input array
Note: This handles the case where global options appear after the command name (e.g., myapp list -c /path).
Generate help text for application global options.
radp_cli_app_global_options_help()Returns: 0 if global options exist, 1 if none defined
Outputs: Formatted help text for global options section
Example output:
Global Options:
-c, --config <dir> Configuration directory
-e, --env <name> Environment name [default: local]
For commands wrapping external tools, use @meta passthrough to bypass argument parsing:
# @cmd
# @desc Run docker commands
# @meta passthrough
cmd_docker() {
exec docker "$@" # All arguments passed through
}Behavior:
- No getopt parsing (avoids conflicts with external tool options)
--helpstill shows framework-generated help- Use environment variables for wrapper-specific configuration
See Command Annotations for details.
Create new CLI project.
radp_cli_scaffold_new (project_name [target_dir])Parameters:
project_name— Project name (alphanumeric, underscore, hyphen; must start with letter)target_dir— Target directory (defaults toproject_name)
Returns: 0 on success, 1 on failure
Creates:
bin/<name>— Entry scriptsrc/main/shell/commands/— Command directory with examplessrc/main/shell/config/— Configuration filessrc/main/shell/libs/— User libraries directorysrc/main/shell/vars/— Constants filepackaging/— Distribution packaging.github/workflows/— CI/CD workflows
Example:
radp_cli_scaffold_new "myapp" # Creates ./myapp/
radp_cli_scaffold_new "myapp" "/opt" # Creates /opt/myapp/Upgrade an existing CLI project to the latest scaffold version.
radp_cli_upgrade ([target_dir] [components...] [options])Parameters:
target_dir— Project directory (default: current directory)components— Components to upgrade:entry,ide,gitignore,version,workflows,packaging,globals, orall(default: all)
Options:
--dry-run— Show what would change without modifying files--force— Force overwrite of user-modified files--diff— Show file diffs for changes
Returns: 0 on success, 1 on failure
Example:
radp_cli_upgrade # Upgrade current directory (all components)
radp_cli_upgrade ./myapp --dry-run # Preview changes
radp_cli_upgrade . workflows packaging # Upgrade specific components
radp_cli_upgrade --force # Overwrite modified filesLocation: libs/toolkit/ide/
The framework provides IDE code completion support for BashSupport Pro (JetBrains IDEs).
- Autocompletion for framework functions (
radp_*) - Autocompletion for framework variables (
gr_fw_*,gr_radp_fw_*) - Autocompletion for user-defined config variables (
gr_radp_extend_*) - Autocompletion for user library functions
- Autocompletion for command functions
The framework generates a _idecomp.sh file containing # shellcheck source=... directives. BashSupport Pro uses
ShellCheck's source directives to resolve symbols and provide code completion.
Generated file locations:
$gr_fw_user_config_path/_idecomp.sh— User config directory$gr_fw_context_cache_path/_idecomp.sh— Framework cache (for development)
- Install BashSupport Pro in your JetBrains IDE
- Run your CLI once to generate the hints file:
myapp --help
- Open your project in the IDE — completion should work automatically
Initialize IDE hints file.
radp_ide_init()Called automatically during bootstrap.
Add commands directory to IDE hints.
radp_ide_add_commands_dir (commands_dir)Called automatically by radp_cli_set_commands_dir().
| Issue | Solution |
|---|---|
| No completion | Ensure _idecomp.sh exists in user config path |
| Stale completion | Delete _idecomp.sh and run CLI again |
| Read-only install | IDE hints are skipped for system installs (/usr/lib64) |
Note: The
_idecomp.shfile uses absolute paths and should be added to.gitignore.