From 230edbed8cd2bda929011801db7898be41997862 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 9 Oct 2021 07:41:05 +0000 Subject: [PATCH 1/3] remove generated executables from examples --- examples/catch-all-advanced/cli | 439 --------------- examples/catch-all/download | 194 ------- examples/colors/colorly | 228 -------- examples/command-default/ftp | 426 -------------- examples/command-groups/ftp | 609 -------------------- examples/commands-nested/cli | 870 ----------------------------- examples/commands/cli | 495 ---------------- examples/completions/cli | 615 -------------------- examples/config-ini/configly | 688 ----------------------- examples/custom-includes/download | 204 ------- examples/custom-strings/download | 214 ------- examples/default-values/convert | 214 ------- examples/dependencies/cli | 386 ------------- examples/docker-like/docker | 727 ------------------------ examples/environment-variables/cli | 312 ----------- examples/extensible-delegate/mygit | 388 ------------- examples/extensible/cli | 429 -------------- examples/footer/download | 190 ------- examples/git-like/git | 407 -------------- examples/minimal/download | 218 -------- examples/minus-v/cli | 201 ------- examples/multiline/multi | 428 -------------- examples/whitelist/login | 263 --------- examples/yaml/yaml | 278 --------- 24 files changed, 9423 deletions(-) delete mode 100644 examples/catch-all-advanced/cli delete mode 100644 examples/catch-all/download delete mode 100644 examples/colors/colorly delete mode 100644 examples/command-default/ftp delete mode 100644 examples/command-groups/ftp delete mode 100644 examples/commands-nested/cli delete mode 100644 examples/commands/cli delete mode 100644 examples/completions/cli delete mode 100644 examples/config-ini/configly delete mode 100644 examples/custom-includes/download delete mode 100644 examples/custom-strings/download delete mode 100644 examples/default-values/convert delete mode 100644 examples/dependencies/cli delete mode 100644 examples/docker-like/docker delete mode 100644 examples/environment-variables/cli delete mode 100644 examples/extensible-delegate/mygit delete mode 100644 examples/extensible/cli delete mode 100644 examples/footer/download delete mode 100644 examples/git-like/git delete mode 100644 examples/minimal/download delete mode 100644 examples/minus-v/cli delete mode 100644 examples/multiline/multi delete mode 100644 examples/whitelist/login delete mode 100644 examples/yaml/yaml diff --git a/examples/catch-all-advanced/cli b/examples/catch-all-advanced/cli deleted file mode 100644 index 070c6ed3..00000000 --- a/examples/catch-all-advanced/cli +++ /dev/null @@ -1,439 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application\n" - echo - - else - printf "cli - Sample application\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " download Download a file" - echo " upload Upload a file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -cli_download_usage() { - if [[ -n $long_usage ]]; then - printf "cli download - Download a file\n" - echo - - else - printf "cli download - Download a file\n" - echo - - fi - - printf "Shortcut: d\n" - echo - - printf "Usage:\n" - printf " cli download SOURCE [TARGET] [options] [AWS PARAMS...]\n" - printf " cli download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --force, -f" - printf " Overwrite existing files\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - # :argument.usage - echo " TARGET" - printf " Target filename (default: same as source)\n" - echo - - echo " AWS PARAMS..." - printf " Additional arguments or flags for AWS CLI\n" - echo - - # :command.usage_examples - printf "Examples:\n" - - printf " cli download example.com\n" - printf " cli download example.com ./output -f\n" - echo - - fi -} - -# :command.usage -cli_upload_usage() { - if [[ -n $long_usage ]]; then - printf "cli upload - Upload a file\n" - echo - - else - printf "cli upload - Upload a file\n" - echo - - fi - - printf "Shortcut: u\n" - echo - - printf "Usage:\n" - printf " cli upload FILES...\n" - printf " cli upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - echo " FILES..." - printf " Files to upload\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -cli_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'cli download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'cli upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - download | d ) - action="download" - shift - cli_download_parse_requirements "$@" - shift $# - ;; - - upload | u ) - action="upload" - shift - cli_upload_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="download" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli download SOURCE [TARGET] [options] [AWS PARAMS...]\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --force | -f ) - args[--force]=1 - shift - ;; - - -* ) - other_args+=("$1") - shift - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - elif [[ ! ${args[target]} ]]; then - args[target]=$1 - shift - else - other_args+=("$1") - shift - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - other_args+=("$1") - shift - ;; - - * ) - # :command.parse_requirements_case - other_args+=("$1") - shift - ;; - - esac - done - # :command.catch_all_filter - if [[ ${#other_args[@]} -eq 0 ]]; then - printf "missing required argument: FILES...\nusage: cli upload FILES...\n" - exit 1 - fi - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_download_usage - else - cli_download_command - fi - - elif [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_upload_usage - else - cli_upload_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/catch-all/download b/examples/catch-all/download deleted file mode 100644 index 54f33bca..00000000 --- a/examples/catch-all/download +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -download_usage() { - if [[ -n $long_usage ]]; then - printf "download - Catch All Example\n" - echo - - else - printf "download - Catch All Example\n" - echo - - fi - - printf "Usage:\n" - printf " download MESSAGE [...]\n" - printf " download --help | -h\n" - printf " download --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " MESSAGE" - printf " Message\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[message]=$1 - shift - else - printf "missing required argument: MESSAGE\nusage: download MESSAGE [...]\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - other_args+=("$1") - shift - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[message]} ]]; then - args[message]=$1 - shift - else - other_args+=("$1") - shift - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/colors/colorly b/examples/colors/colorly deleted file mode 100644 index ce0c9921..00000000 --- a/examples/colors/colorly +++ /dev/null @@ -1,228 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - message=${args[message]:-hello colors} - - underlined "Message Recevied": - echo - echo " => $(green_bold "$message")" - echo " ==> $(red_bold "$message")" - echo " ===> $(blue_bold "$message")" - echo -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -colorly_usage() { - if [[ -n $long_usage ]]; then - printf "colorly - Sample application that uses the color functions\n" - echo - - else - printf "colorly - Sample application that uses the color functions\n" - echo - - fi - - printf "Usage:\n" - printf " colorly [MESSAGE]\n" - printf " colorly --help | -h\n" - printf " colorly --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " MESSAGE" - printf " Message to show [default: hello colors]\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.user_lib -# :src/lib/colors.sh -# --- -# Color functions -# This file is a part of Bashly standard library -# -# Usage: -# Use any of the functions below to color or format a portion of a string. -# - -# echo "before $(red this is red) after" -# echo "before $(green_bold this is green_bold) after" -# -# --- - -red() { printf "\e[31m%b\e[0m\n" "$*"; } -green() { printf "\e[32m%b\e[0m\n" "$*"; } -yellow() { printf "\e[33m%b\e[0m\n" "$*"; } -blue() { printf "\e[34m%b\e[0m\n" "$*"; } -magenta() { printf "\e[35m%b\e[0m\n" "$*"; } -cyan() { printf "\e[36m%b\e[0m\n" "$*"; } -bold() { printf "\e[1m%b\e[0m\n" "$*"; } -underlined() { printf "\e[4m%b\e[0m\n" "$*"; } -red_bold() { printf "\e[1;31m%b\e[0m\n" "$*"; } -green_bold() { printf "\e[1;32m%b\e[0m\n" "$*"; } -yellow_bold() { printf "\e[1;33m%b\e[0m\n" "$*"; } -blue_bold() { printf "\e[1;34m%b\e[0m\n" "$*"; } -magenta_bold() { printf "\e[1;35m%b\e[0m\n" "$*"; } -cyan_bold() { printf "\e[1;36m%b\e[0m\n" "$*"; } -red_underlined() { printf "\e[4;31m%b\e[0m\n" "$*"; } -green_underlined() { printf "\e[4;32m%b\e[0m\n" "$*"; } -yellow_underlined() { printf "\e[4;33m%b\e[0m\n" "$*"; } -blue_underlined() { printf "\e[4;34m%b\e[0m\n" "$*"; } -magenta_underlined() { printf "\e[4;35m%b\e[0m\n" "$*"; } -cyan_underlined() { printf "\e[4;36m%b\e[0m\n" "$*"; } - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - colorly_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[message]} ]]; then - args[message]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/command-default/ftp b/examples/command-default/ftp deleted file mode 100644 index 1cc8bd0e..00000000 --- a/examples/command-default/ftp +++ /dev/null @@ -1,426 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -ftp_usage() { - if [[ -n $long_usage ]]; then - printf "ftp - Sample application that uses the default command option\n" - echo - - else - printf "ftp - Sample application that uses the default command option\n" - echo - - fi - - printf "Usage:\n" - printf " ftp [command]\n" - printf " ftp [command] --help | -h\n" - printf " ftp --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " upload Upload a file (default)" - echo " download Download a file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -ftp_upload_usage() { - if [[ -n $long_usage ]]; then - printf "ftp upload - Upload a file\n" - echo - - else - printf "ftp upload - Upload a file\n" - echo - - fi - - printf "Shortcut: u\n" - echo - - printf "Usage:\n" - printf " ftp upload SOURCE\n" - printf " ftp upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " File to upload\n" - echo - - fi -} - -# :command.usage -ftp_download_usage() { - if [[ -n $long_usage ]]; then - printf "ftp download - Download a file\n" - echo - - else - printf "ftp download - Download a file\n" - echo - - fi - - printf "Shortcut: d\n" - echo - - printf "Usage:\n" - printf " ftp download SOURCE\n" - printf " ftp download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " File to download\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -ftp_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'ftp upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -ftp_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'ftp download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - upload | u ) - action="upload" - shift - ftp_upload_parse_requirements "$@" - shift $# - ;; - - download | d ) - action="download" - shift - ftp_download_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - "" ) - ftp_usage - exit 1 - ;; - - * ) - action="upload" - ftp_upload_parse_requirements "$@" - shift $# - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -ftp_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: ftp upload SOURCE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -ftp_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="download" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: ftp download SOURCE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - ftp_upload_usage - else - ftp_upload_command - fi - - elif [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - ftp_download_usage - else - ftp_download_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/command-groups/ftp b/examples/command-groups/ftp deleted file mode 100644 index 5e934b94..00000000 --- a/examples/command-groups/ftp +++ /dev/null @@ -1,609 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -ftp_usage() { - if [[ -n $long_usage ]]; then - printf "ftp - Sample application with command grouping\n" - echo - - else - printf "ftp - Sample application with command grouping\n" - echo - - fi - - printf "Usage:\n" - printf " ftp [command]\n" - printf " ftp [command] --help | -h\n" - printf " ftp --version | -v\n" - echo - # :command.usage_commands - printf "File Commands:\n" - echo " download Download a file" - echo " upload Upload a file" - printf "\nLogin Commands:\n" - echo " login Write login credentials to the config file" - echo " logout Delete login credentials to the config file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -ftp_download_usage() { - if [[ -n $long_usage ]]; then - printf "ftp download - Download a file\n" - echo - - else - printf "ftp download - Download a file\n" - echo - - fi - - printf "Usage:\n" - printf " ftp download FILE\n" - printf " ftp download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " FILE" - printf " File to download\n" - echo - - fi -} - -# :command.usage -ftp_upload_usage() { - if [[ -n $long_usage ]]; then - printf "ftp upload - Upload a file\n" - echo - - else - printf "ftp upload - Upload a file\n" - echo - - fi - - printf "Usage:\n" - printf " ftp upload FILE\n" - printf " ftp upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " FILE" - printf " File to upload\n" - echo - - fi -} - -# :command.usage -ftp_login_usage() { - if [[ -n $long_usage ]]; then - printf "ftp login - Write login credentials to the config file\n" - echo - - else - printf "ftp login - Write login credentials to the config file\n" - echo - - fi - - printf "Usage:\n" - printf " ftp login\n" - printf " ftp login --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -ftp_logout_usage() { - if [[ -n $long_usage ]]; then - printf "ftp logout - Delete login credentials to the config file\n" - echo - - else - printf "ftp logout - Delete login credentials to the config file\n" - echo - - fi - - printf "Usage:\n" - printf " ftp logout\n" - printf " ftp logout --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -ftp_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'ftp download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -ftp_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'ftp upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -ftp_login_command() { - # :src/login_command.sh - echo "# this file is located in 'src/login_command.sh'" - echo "# code for 'ftp login' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -ftp_logout_command() { - # :src/logout_command.sh - echo "# this file is located in 'src/logout_command.sh'" - echo "# code for 'ftp logout' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - download ) - action="download" - shift - ftp_download_parse_requirements "$@" - shift $# - ;; - - upload ) - action="upload" - shift - ftp_upload_parse_requirements "$@" - shift $# - ;; - - login ) - action="login" - shift - ftp_login_parse_requirements "$@" - shift $# - ;; - - logout ) - action="logout" - shift - ftp_logout_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - ftp_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -ftp_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="download" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[file]=$1 - shift - else - printf "missing required argument: FILE\nusage: ftp download FILE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[file]} ]]; then - args[file]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -ftp_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[file]=$1 - shift - else - printf "missing required argument: FILE\nusage: ftp upload FILE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[file]} ]]; then - args[file]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -ftp_login_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_login_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="login" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -ftp_logout_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - ftp_logout_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="logout" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - ftp_download_usage - else - ftp_download_command - fi - - elif [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - ftp_upload_usage - else - ftp_upload_command - fi - - elif [[ $action == "login" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - ftp_login_usage - else - ftp_login_command - fi - - elif [[ $action == "logout" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - ftp_logout_usage - else - ftp_logout_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/commands-nested/cli b/examples/commands-nested/cli deleted file mode 100644 index 078b6801..00000000 --- a/examples/commands-nested/cli +++ /dev/null @@ -1,870 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application with nested commands\n" - echo - - else - printf "cli - Sample application with nested commands\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " dir Directory commands" - echo " file File commands" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -cli_dir_usage() { - if [[ -n $long_usage ]]; then - printf "cli dir - Directory commands\n" - echo - - else - printf "cli dir - Directory commands\n" - echo - - fi - - printf "Shortcut: d\n" - echo - - printf "Usage:\n" - printf " cli dir [command]\n" - printf " cli dir [command] --help | -h\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " list Show files in the directory" - echo " remove Remove directory" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -cli_dir_list_usage() { - if [[ -n $long_usage ]]; then - printf "cli dir list - Show files in the directory\n" - echo - - else - printf "cli dir list - Show files in the directory\n" - echo - - fi - - printf "Usage:\n" - printf " cli dir list PATH\n" - printf " cli dir list --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " PATH" - printf " Directory path\n" - echo - - fi -} - -# :command.usage -cli_dir_remove_usage() { - if [[ -n $long_usage ]]; then - printf "cli dir remove - Remove directory\n" - echo - - else - printf "cli dir remove - Remove directory\n" - echo - - fi - - printf "Usage:\n" - printf " cli dir remove PATH [options]\n" - printf " cli dir remove --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --force, -f" - printf " Remove even if when not empty\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " PATH" - printf " Directory path\n" - echo - - fi -} - -# :command.usage -cli_file_usage() { - if [[ -n $long_usage ]]; then - printf "cli file - File commands\n" - echo - - else - printf "cli file - File commands\n" - echo - - fi - - printf "Shortcut: f\n" - echo - - printf "Usage:\n" - printf " cli file [command]\n" - printf " cli file [command] --help | -h\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " show Show file contents" - echo " edit Edit the file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -cli_file_show_usage() { - if [[ -n $long_usage ]]; then - printf "cli file show - Show file contents\n" - echo - - else - printf "cli file show - Show file contents\n" - echo - - fi - - printf "Usage:\n" - printf " cli file show PATH\n" - printf " cli file show --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " PATH" - printf " Path to file\n" - echo - - fi -} - -# :command.usage -cli_file_edit_usage() { - if [[ -n $long_usage ]]; then - printf "cli file edit - Edit the file\n" - echo - - else - printf "cli file edit - Edit the file\n" - echo - - fi - - printf "Usage:\n" - printf " cli file edit PATH\n" - printf " cli file edit --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " PATH" - printf " Path to file\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.function -cli_dir_list_command() { - # :src/dir_list_command.sh - echo "# this file is located in 'src/dir_list_command.sh'" - echo "# code for 'cli dir list' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_dir_remove_command() { - # :src/dir_remove_command.sh - echo "# this file is located in 'src/dir_remove_command.sh'" - echo "# code for 'cli dir remove' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_file_show_command() { - # :src/file_show_command.sh - echo "# this file is located in 'src/file_show_command.sh'" - echo "# code for 'cli file show' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_file_edit_command() { - # :src/file_edit_command.sh - echo "# this file is located in 'src/file_edit_command.sh'" - echo "# code for 'cli file edit' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - dir | d ) - action="dir" - shift - cli_dir_parse_requirements "$@" - shift $# - ;; - - file | f ) - action="file" - shift - cli_file_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_dir_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_dir_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - list ) - action="list" - shift - cli_dir_list_parse_requirements "$@" - shift $# - ;; - - remove ) - action="remove" - shift - cli_dir_remove_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_dir_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_dir_list_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_dir_list_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="dir list" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[path]=$1 - shift - else - printf "missing required argument: PATH\nusage: cli dir list PATH\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[path]} ]]; then - args[path]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_dir_remove_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_dir_remove_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="dir remove" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[path]=$1 - shift - else - printf "missing required argument: PATH\nusage: cli dir remove PATH [options]\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --force | -f ) - args[--force]=1 - shift - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[path]} ]]; then - args[path]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_file_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_file_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - show ) - action="show" - shift - cli_file_show_parse_requirements "$@" - shift $# - ;; - - edit ) - action="edit" - shift - cli_file_edit_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_file_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_file_show_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_file_show_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="file show" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[path]=$1 - shift - else - printf "missing required argument: PATH\nusage: cli file show PATH\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[path]} ]]; then - args[path]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_file_edit_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_file_edit_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="file edit" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[path]=$1 - shift - else - printf "missing required argument: PATH\nusage: cli file edit PATH\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[path]} ]]; then - args[path]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "dir" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_dir_usage - else - cli_dir_command - fi - - elif [[ $action == "dir list" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_dir_list_usage - else - cli_dir_list_command - fi - - elif [[ $action == "dir remove" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_dir_remove_usage - else - cli_dir_remove_command - fi - - elif [[ $action == "file" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_file_usage - else - cli_file_command - fi - - elif [[ $action == "file show" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_file_show_usage - else - cli_file_show_command - fi - - elif [[ $action == "file edit" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_file_edit_usage - else - cli_file_edit_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/commands/cli b/examples/commands/cli deleted file mode 100644 index ebca4aae..00000000 --- a/examples/commands/cli +++ /dev/null @@ -1,495 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application\n" - echo - - else - printf "cli - Sample application\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " download Download a file" - echo " upload Upload a file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_environment_variables - printf "Environment Variables:\n" - - # :environment_variable.usage - echo " API_KEY" - printf " Set your API key\n" - echo - - fi -} - -# :command.usage -cli_download_usage() { - if [[ -n $long_usage ]]; then - printf "cli download - Download a file\n" - echo - - else - printf "cli download - Download a file\n" - echo - - fi - - printf "Shortcut: d\n" - echo - - printf "Usage:\n" - printf " cli download SOURCE [TARGET] [options]\n" - printf " cli download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --force, -f" - printf " Overwrite existing files\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - # :argument.usage - echo " TARGET" - printf " Target filename (default: same as source)\n" - echo - # :command.usage_environment_variables - printf "Environment Variables:\n" - - # :environment_variable.usage - echo " DEFAULT_TARGET_LOCATION" - printf " Set the default location to download to\n" - echo - # :command.usage_examples - printf "Examples:\n" - - printf " cli download example.com\n" - printf " cli download example.com ./output -f\n" - echo - - fi -} - -# :command.usage -cli_upload_usage() { - if [[ -n $long_usage ]]; then - printf "cli upload - Upload a file\n" - echo - - else - printf "cli upload - Upload a file\n" - echo - - fi - - printf "Shortcut: u\n" - echo - - printf "Usage:\n" - printf " cli upload SOURCE [options]\n" - printf " cli upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --user, -u USER (required)" - printf " Username to use for logging in\n" - echo - - # :flag.usage - echo " --password, -p PASSWORD" - printf " Password to use for logging in\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " File to upload\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -cli_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'cli download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'cli upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - download | d ) - action="download" - shift - cli_download_parse_requirements "$@" - shift $# - ;; - - upload | u ) - action="upload" - shift - cli_upload_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="download" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli download SOURCE [TARGET] [options]\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --force | -f ) - args[--force]=1 - shift - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - elif [[ ! ${args[target]} ]]; then - args[target]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli upload SOURCE [options]\n" - exit 1 - fi - # :command.required_flags_filter - argstring="$*" - if [[ "$argstring" != *--user* && "$argstring" != *-u* ]]; then - printf "missing required flag: --user, -u USER\n" - exit 1 - fi - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --user | -u ) - if [[ $2 ]]; then - args[--user]="$2" - shift - shift - else - printf "%s\n" "--user requires an argument: --user, -u USER" - exit 1 - fi - ;; - - # :flag.case - --password | -p ) - if [[ $2 ]]; then - args[--password]="$2" - shift - shift - else - printf "%s\n" "--password requires an argument: --password, -p PASSWORD" - exit 1 - fi - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_download_usage - else - cli_download_command - fi - - elif [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_upload_usage - else - cli_upload_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/completions/cli b/examples/completions/cli deleted file mode 100644 index 70377279..00000000 --- a/examples/completions/cli +++ /dev/null @@ -1,615 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application with bash completions\n" - echo - - else - printf "cli - Sample application with bash completions\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " completions Generate bash completions" - echo " download Download a file" - echo " upload Upload a file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -cli_completions_usage() { - if [[ -n $long_usage ]]; then - printf "cli completions\n" - echo - - printf " Generate bash completions\n Usage: eval \"\$(cli completions)\"\n" - echo - - else - printf "cli completions - Generate bash completions\n" - echo - - fi - - printf "Usage:\n" - printf " cli completions\n" - printf " cli completions --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -cli_download_usage() { - if [[ -n $long_usage ]]; then - printf "cli download - Download a file\n" - echo - - else - printf "cli download - Download a file\n" - echo - - fi - - printf "Shortcut: d\n" - echo - - printf "Usage:\n" - printf " cli download SOURCE [TARGET] [options]\n" - printf " cli download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --force, -f" - printf " Overwrite existing files\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - # :argument.usage - echo " TARGET" - printf " Target filename (default: same as source)\n" - echo - # :command.usage_environment_variables - printf "Environment Variables:\n" - - # :environment_variable.usage - echo " DEFAULT_TARGET_LOCATION" - printf " Set the default location to download to\n" - echo - # :command.usage_examples - printf "Examples:\n" - - printf " cli download example.com\n" - printf " cli download example.com ./output -f\n" - echo - - fi -} - -# :command.usage -cli_upload_usage() { - if [[ -n $long_usage ]]; then - printf "cli upload - Upload a file\n" - echo - - else - printf "cli upload - Upload a file\n" - echo - - fi - - printf "Shortcut: u\n" - echo - - printf "Usage:\n" - printf " cli upload SOURCE [options]\n" - printf " cli upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --user, -u USER (required)" - printf " Username to use for logging in\n" - echo - - # :flag.usage - echo " --password, -p PASSWORD" - printf " Password to use for logging in\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " File to upload\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.user_lib -# :src/lib/send_completions.sh -send_completions() { - echo $'#!/usr/bin/env bash' - echo $'' - echo $'# This bash completions script was generated by' - echo $'# completely (https://github.com/dannyben/completely)' - echo $'# Modifying it manually is not recommended' - echo $'_cli_completions() {' - echo $' local cur=${COMP_WORDS[COMP_CWORD]}' - echo $' local comp_line="${COMP_WORDS[*]:1}"' - echo $'' - echo $' case "$comp_line" in' - echo $' \'completions\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;' - echo $' \'download\'*) COMPREPLY=($(compgen -A file -W "--force --help -f -h" -- "$cur")) ;;' - echo $' \'upload\'*) COMPREPLY=($(compgen -A directory -A user -W "--help --password --user -h -p -u" -- "$cur")) ;;' - echo $' \'\'*) COMPREPLY=($(compgen -W "--help --version -h -v completions download upload" -- "$cur")) ;;' - echo $' esac' - echo $'}' - echo $'' - echo $'complete -F _cli_completions cli' -} - -# :command.command_functions -# :command.function -cli_completions_command() { - # :src/completions_command.sh - # Call the `send_completions` function which was added by running: - # - # $ bashly add comp function - # - # Users can now enable bash completion for this script by running: - # - # $ eval "$(cli completions)" - # - send_completions -} - -# :command.function -cli_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'cli download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'cli upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - completions ) - action="completions" - shift - cli_completions_parse_requirements "$@" - shift $# - ;; - - download | d ) - action="download" - shift - cli_download_parse_requirements "$@" - shift $# - ;; - - upload | u ) - action="upload" - shift - cli_upload_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_completions_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_completions_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="completions" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="download" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli download SOURCE [TARGET] [options]\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --force | -f ) - args[--force]=1 - shift - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - elif [[ ! ${args[target]} ]]; then - args[target]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli upload SOURCE [options]\n" - exit 1 - fi - # :command.required_flags_filter - argstring="$*" - if [[ "$argstring" != *--user* && "$argstring" != *-u* ]]; then - printf "missing required flag: --user, -u USER\n" - exit 1 - fi - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --user | -u ) - if [[ $2 ]]; then - args[--user]="$2" - shift - shift - else - printf "%s\n" "--user requires an argument: --user, -u USER" - exit 1 - fi - ;; - - # :flag.case - --password | -p ) - if [[ $2 ]]; then - args[--password]="$2" - shift - shift - else - printf "%s\n" "--password requires an argument: --password, -p PASSWORD" - exit 1 - fi - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "completions" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_completions_usage - else - cli_completions_command - fi - - elif [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_download_usage - else - cli_download_command - fi - - elif [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_upload_usage - else - cli_upload_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/config-ini/configly b/examples/config-ini/configly deleted file mode 100644 index ef4aad52..00000000 --- a/examples/config-ini/configly +++ /dev/null @@ -1,688 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -configly_usage() { - if [[ -n $long_usage ]]; then - printf "configly - Sample application that uses the config functions\n" - echo - - else - printf "configly - Sample application that uses the config functions\n" - echo - - fi - - printf "Usage:\n" - printf " configly [command]\n" - printf " configly [command] --help | -h\n" - printf " configly --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " set Save a value in the config file" - echo " get Read a value from the config file" - echo " list Show the entire config file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -configly_set_usage() { - if [[ -n $long_usage ]]; then - printf "configly set - Save a value in the config file\n" - echo - - else - printf "configly set - Save a value in the config file\n" - echo - - fi - - printf "Shortcut: s\n" - echo - - printf "Usage:\n" - printf " configly set KEY VALUE\n" - printf " configly set --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " KEY" - printf " Config key\n" - echo - - # :argument.usage - echo " VALUE" - printf " Config value\n" - echo - - # :command.usage_examples - printf "Examples:\n" - - printf " configly set hello world\n" - echo - - fi -} - -# :command.usage -configly_get_usage() { - if [[ -n $long_usage ]]; then - printf "configly get - Read a value from the config file\n" - echo - - else - printf "configly get - Read a value from the config file\n" - echo - - fi - - printf "Shortcut: g\n" - echo - - printf "Usage:\n" - printf " configly get KEY\n" - printf " configly get --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " KEY" - printf " Config key\n" - echo - - # :command.usage_examples - printf "Examples:\n" - - printf " configly set hello\n" - echo - - fi -} - -# :command.usage -configly_list_usage() { - if [[ -n $long_usage ]]; then - printf "configly list - Show the entire config file\n" - echo - - else - printf "configly list - Show the entire config file\n" - echo - - fi - - printf "Shortcut: l\n" - echo - - printf "Usage:\n" - printf " configly list\n" - printf " configly list --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.user_lib -# :src/lib/config.sh -# --- -# Config functions -# This file is a part of Bashly standard library -# -# Usage: -# - In your script, set the CONFIG_FILE variable. For rxample: -# CONFIG_FILE=settings.ini. -# If it is unset, it will default to 'config.ini'. -# - Use any of the functions below to access the config file. -# --- - -# Create a new config file. -# There is normally no need to use this function, it is used by other -# functions as needed. -config_init() { - CONFIG_FILE=${CONFIG_FILE:=config.ini} - [[ -f "$CONFIG_FILE" ]] || touch "$CONFIG_FILE" -} - -# Get a value from the config -# Usage: result=$(config_get hello) -config_get() { - key=$1 - regex="^$key\s*=\s*(.+)$" - - config_init - - while IFS= read -r line || [ -n "$line" ]; do - if [[ $line =~ $regex ]]; then - value="${BASH_REMATCH[1]}" - break - fi - done < "$CONFIG_FILE" - - echo "$value" -} - -# Add or update a key=value pair in the config. -# Usage: config_set key value -config_set() { - key=$1 - shift - value="$*" - - config_init - - regex="^($key)\s*=\s*.+$" - output="" - found_key="" - - while IFS= read -r line || [ -n "$line" ]; do - newline=$line - if [[ $line =~ $regex ]]; then - found_key="${BASH_REMATCH[1]}" - newline="$key = $value" - output="$output$newline\n" - elif [[ $line ]]; then - output="$output$line\n" - fi - done < "$CONFIG_FILE" - - if [[ -z $found_key ]]; then - output="$output$key = $value\n" - fi - - printf "%b\n" "$output" > "$CONFIG_FILE" -} - -# Delete a key from teh config. -# Usage: config_del key -config_del() { - key=$1 - - regex="^($key)\s*=" - output="" - - config_init - - while IFS= read -r line || [ -n "$line" ]; do - newline=$line - if [[ $line ]] && [[ ! $line =~ $regex ]]; then - output="$output$line\n" - fi - done < "$CONFIG_FILE" - - printf "%b\n" "$output" > "$CONFIG_FILE" -} - -# Show the config file -config_show() { - config_init - cat "$CONFIG_FILE" -} - -# Return an array of the keys in the config file -# Usage: -# -# for k in $(config_keys); do -# echo "- $k = $(config_get "$k")"; -# done -# -config_keys() { - regex="^(.*)\s*=" - - config_init - - keys=() - while IFS= read -r line || [ -n "$line" ]; do - if [[ $line =~ $regex ]]; then - key="${BASH_REMATCH[1]}" - keys+=("$key") - fi - done < "$CONFIG_FILE" - echo "${keys[@]}" -} - -# Returns true if the specified key exists in the config file -# Usage: -# -# if config_has_key "key" ; then -# echo "key exists" -# fi -# -config_has_key() { - [[ $(config_get "$1") ]] -} - -# :command.command_functions -# :command.function -configly_set_command() { - # :src/set_command.sh - # Using the standard library (lib/config.sh) to store a value to the config - config_set "${args[key]}" "${args[value]}" - echo "saved: ${args[key]} = ${args[value]}" -} - -# :command.function -configly_get_command() { - # :src/get_command.sh - # Using the standard library (lib/config.sh) to show a value from the config - - key="${args[key]}" - if config_has_key "$key" ; then - - config_get "$key" - else - echo "No such key: $key" - fi - - # Example of how to assign the config value to a variable: - # result=$(config_get "${args[key]}") - # echo $result -} - -# :command.function -configly_list_command() { - # :src/list_command.sh - # Using the standard library (lib/config.sh) to show the entire config file - config_show - - # Or to iterate through keys - for key in $(config_keys) ; do - echo "$key === $(config_get "$key")" - done -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - configly_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - set | s ) - action="set" - shift - configly_set_parse_requirements "$@" - shift $# - ;; - - get | g ) - action="get" - shift - configly_get_parse_requirements "$@" - shift $# - ;; - - list | l ) - action="list" - shift - configly_list_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - configly_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -configly_set_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - configly_set_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="set" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[key]=$1 - shift - else - printf "missing required argument: KEY\nusage: configly set KEY VALUE\n" - exit 1 - fi - - if [[ $1 && $1 != -* ]]; then - args[value]=$1 - shift - else - printf "missing required argument: VALUE\nusage: configly set KEY VALUE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[key]} ]]; then - args[key]=$1 - shift - elif [[ ! ${args[value]} ]]; then - args[value]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -configly_get_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - configly_get_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="get" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[key]=$1 - shift - else - printf "missing required argument: KEY\nusage: configly get KEY\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[key]} ]]; then - args[key]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -configly_list_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - configly_list_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="list" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "set" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - configly_set_usage - else - configly_set_command - fi - - elif [[ $action == "get" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - configly_get_usage - else - configly_get_command - fi - - elif [[ $action == "list" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - configly_list_usage - else - configly_list_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/custom-includes/download b/examples/custom-includes/download deleted file mode 100644 index 70f562b0..00000000 --- a/examples/custom-includes/download +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - # Call our custom library function - echo "Before custom code" - sample_function - echo "After custom code" -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -download_usage() { - if [[ -n $long_usage ]]; then - printf "download - Sample minimal application with custom strings\n" - echo - - else - printf "download - Sample minimal application with custom strings\n" - echo - - fi - - printf "Usage:\n" - printf " download [SOURCE]\n" - printf " download --help | -h\n" - printf " download --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.user_lib -# :src/lib/sample_function.sh -# Add any function here that is needed in more than one parts of your -# application, or that you otherwise wish to extract from the main function -# scripts. -# -# Note that code here should be wrapped inside bash functions, and it is -# recommended to have a separate file for each function. -# -# Subdirectories will also be scanned for *.sh, so you have no reason not -# to organize your code neatly. -# -sample_function() { - echo "it works" -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/custom-strings/download b/examples/custom-strings/download deleted file mode 100644 index 94c77334..00000000 --- a/examples/custom-strings/download +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -download_usage() { - if [[ -n $long_usage ]]; then - printf "download - Sample minimal application with custom strings\n" - echo - - else - printf "download - Sample minimal application with custom strings\n" - echo - - fi - - printf "== Usage ==\n\n" - printf " download SOURCE [options]\n" - printf " download --help | -h\n" - printf " download --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "== Options ==\n\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this helpful help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - # :command.usage_flags - # :flag.usage - echo " --out, -o DIR (required)" - printf " Target directory\n" - echo - # :command.usage_args - printf "== Arguments ==\n\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "Boom! a required argument is missing: SOURCE\nusage: download SOURCE [options]\n" - exit 1 - fi - # :command.required_flags_filter - argstring="$*" - if [[ "$argstring" != *--out* && "$argstring" != *-o* ]]; then - printf "Yo! you forgot a flag: --out, -o DIR\n" - exit 1 - fi - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --out | -o ) - if [[ $2 ]]; then - args[--out]="$2" - shift - shift - else - printf "%s\n" "Hey! the flag --out requires an argument: --out, -o DIR" - exit 1 - fi - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/default-values/convert b/examples/default-values/convert deleted file mode 100644 index b0bc81f3..00000000 --- a/examples/default-values/convert +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -convert_usage() { - if [[ -n $long_usage ]]; then - printf "convert - Sample application using default arguments and flags\n" - echo - - else - printf "convert - Sample application using default arguments and flags\n" - echo - - fi - - printf "Usage:\n" - printf " convert [SOURCE] [options]\n" - printf " convert --help | -h\n" - printf " convert --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - # :command.usage_flags - # :flag.usage - echo " --format, -f FORMAT" - printf " Format to convert to\n" - printf " Default: png\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " Files to convert\n" - printf " Default: *.jpg\n" - echo - - # :command.usage_examples - printf "Examples:\n" - - printf " convert *.bmp\n" - printf " convert --format jpg\n" - printf " convert *.bmp --format jpg\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - convert_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --format | -f ) - if [[ $2 ]]; then - args[--format]="$2" - shift - shift - else - printf "%s\n" "--format requires an argument: --format, -f FORMAT" - exit 1 - fi - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - [[ -n ${args[source]} ]] || args[source]="*.jpg" - [[ -n ${args[--format]} ]] || args[--format]="png" - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/dependencies/cli b/examples/dependencies/cli deleted file mode 100644 index 5260bbe8..00000000 --- a/examples/dependencies/cli +++ /dev/null @@ -1,386 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application that requires dependencies\n" - echo - - else - printf "cli - Sample application that requires dependencies\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " download Download something" - echo " upload Upload something" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -cli_download_usage() { - if [[ -n $long_usage ]]; then - printf "cli download - Download something\n" - echo - - else - printf "cli download - Download something\n" - echo - - fi - - printf "Usage:\n" - printf " cli download\n" - printf " cli download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -cli_upload_usage() { - if [[ -n $long_usage ]]; then - printf "cli upload - Upload something\n" - echo - - else - printf "cli upload - Upload something\n" - echo - - fi - - printf "Usage:\n" - printf " cli upload\n" - printf " cli upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -cli_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'cli download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'cli upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - download ) - action="download" - shift - cli_download_parse_requirements "$@" - shift $# - ;; - - upload ) - action="upload" - shift - cli_upload_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - if ! [[ -x "$(command -v git)" ]]; then - printf "missing dependency: git\n" - exit 1 - fi - if ! [[ -x "$(command -v curl)" ]]; then - printf "missing dependency: curl\n" - exit 1 - fi - if ! [[ -x "$(command -v shmurl)" ]]; then - printf "missing dependency: shmurl\n" - exit 1 - fi - # :command.command_filter - action="download" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_download_usage - else - cli_download_command - fi - - elif [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_upload_usage - else - cli_upload_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/docker-like/docker b/examples/docker-like/docker deleted file mode 100644 index d18cd131..00000000 --- a/examples/docker-like/docker +++ /dev/null @@ -1,727 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -docker_usage() { - if [[ -n $long_usage ]]; then - printf "docker - Docker example\n" - echo - - else - printf "docker - Docker example\n" - echo - - fi - - printf "Usage:\n" - printf " docker [command]\n" - printf " docker [command] --help | -h\n" - printf " docker --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " container Container commands" - echo " image Image commands" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -docker_container_usage() { - if [[ -n $long_usage ]]; then - printf "docker container - Container commands\n" - echo - - else - printf "docker container - Container commands\n" - echo - - fi - - printf "Shortcut: c*\n" - echo - - printf "Usage:\n" - printf " docker container [command]\n" - printf " docker container [command] --help | -h\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " run Run a container" - echo " stop Stop a container" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -docker_container_run_usage() { - if [[ -n $long_usage ]]; then - printf "docker container run - Run a container\n" - echo - - else - printf "docker container run - Run a container\n" - echo - - fi - - printf "Usage:\n" - printf " docker container run IMAGE\n" - printf " docker container run --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " IMAGE" - printf " Image name\n" - echo - - fi -} - -# :command.usage -docker_container_stop_usage() { - if [[ -n $long_usage ]]; then - printf "docker container stop - Stop a container\n" - echo - - else - printf "docker container stop - Stop a container\n" - echo - - fi - - printf "Usage:\n" - printf " docker container stop CONTAINER\n" - printf " docker container stop --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " CONTAINER" - printf " Container name\n" - echo - - fi -} - -# :command.usage -docker_image_usage() { - if [[ -n $long_usage ]]; then - printf "docker image - Image commands\n" - echo - - else - printf "docker image - Image commands\n" - echo - - fi - - printf "Shortcut: i*\n" - echo - - printf "Usage:\n" - printf " docker image [command]\n" - printf " docker image [command] --help | -h\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " ls Show all images" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -docker_image_ls_usage() { - if [[ -n $long_usage ]]; then - printf "docker image ls - Show all images\n" - echo - - else - printf "docker image ls - Show all images\n" - echo - - fi - - printf "Shortcut: l\n" - echo - - printf "Usage:\n" - printf " docker image ls\n" - printf " docker image ls --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.function -docker_container_run_command() { - # :src/container_run_command.sh - echo "# this file is located in 'src/container_run_command.sh'" - echo "# code for 'docker container run' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -docker_container_stop_command() { - # :src/container_stop_command.sh - echo "# this file is located in 'src/container_stop_command.sh'" - echo "# code for 'docker container stop' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -docker_image_ls_command() { - # :src/image_ls_command.sh - echo "# this file is located in 'src/image_ls_command.sh'" - echo "# code for 'docker image ls' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - docker_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - container | c* ) - action="container" - shift - docker_container_parse_requirements "$@" - shift $# - ;; - - image | i* ) - action="image" - shift - docker_image_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - docker_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -docker_container_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - docker_container_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - run ) - action="run" - shift - docker_container_run_parse_requirements "$@" - shift $# - ;; - - stop ) - action="stop" - shift - docker_container_stop_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - docker_container_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -docker_container_run_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - docker_container_run_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="container run" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[image]=$1 - shift - else - printf "missing required argument: IMAGE\nusage: docker container run IMAGE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[image]} ]]; then - args[image]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -docker_container_stop_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - docker_container_stop_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="container stop" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[container]=$1 - shift - else - printf "missing required argument: CONTAINER\nusage: docker container stop CONTAINER\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[container]} ]]; then - args[container]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -docker_image_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - docker_image_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - ls | l ) - action="ls" - shift - docker_image_ls_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - docker_image_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -docker_image_ls_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - docker_image_ls_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="image ls" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "container" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - docker_container_usage - else - docker_container_command - fi - - elif [[ $action == "container run" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - docker_container_run_usage - else - docker_container_run_command - fi - - elif [[ $action == "container stop" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - docker_container_stop_usage - else - docker_container_stop_command - fi - - elif [[ $action == "image" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - docker_image_usage - else - docker_image_command - fi - - elif [[ $action == "image ls" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - docker_image_ls_usage - else - docker_image_ls_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/environment-variables/cli b/examples/environment-variables/cli deleted file mode 100644 index 11616f06..00000000 --- a/examples/environment-variables/cli +++ /dev/null @@ -1,312 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application that requires environment variables\n" - echo - - else - printf "cli - Sample application that requires environment variables\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " verify Verify your user" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_environment_variables - printf "Environment Variables:\n" - - # :environment_variable.usage - echo " API_KEY" - printf " Set your API key\n" - echo - - fi -} - -# :command.usage -cli_verify_usage() { - if [[ -n $long_usage ]]; then - printf "cli verify - Verify your user\n" - echo - - else - printf "cli verify - Verify your user\n" - echo - - fi - - printf "Shortcut: v\n" - echo - - printf "Usage:\n" - printf " cli verify\n" - printf " cli verify --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_environment_variables - printf "Environment Variables:\n" - - # :environment_variable.usage - echo " MY_SECRET (required)" - printf " Your secret\n" - echo - - # :environment_variable.usage - echo " ENVIRONMENT" - printf " One of development, production or test\n" - printf " Default: development\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -cli_verify_command() { - # :src/verify_command.sh - echo "# this file is located in 'src/verify_command.sh'" - echo "# code for 'cli verify' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args - - echo "environment:" - echo "- API_KEY=$API_KEY" - echo "- ENVIRONMENT=$ENVIRONMENT" - echo "- MY_SECRET=$MY_SECRET" -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - verify | v ) - action="verify" - shift - cli_verify_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - cli_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_verify_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_verify_usage - exit - ;; - - esac - # :command.environment_variables_filter - export ENVIRONMENT="${ENVIRONMENT:-development}" - if [[ -z "$MY_SECRET" ]]; then - printf "missing required environment variable: MY_SECRET\n" - exit 1 - fi - # :command.dependencies_filter - # :command.command_filter - action="verify" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "verify" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_verify_usage - else - cli_verify_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/extensible-delegate/mygit b/examples/extensible-delegate/mygit deleted file mode 100644 index ac637726..00000000 --- a/examples/extensible-delegate/mygit +++ /dev/null @@ -1,388 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -mygit_usage() { - if [[ -n $long_usage ]]; then - printf "mygit - Sample application that delegates unknown commands to a different executable\n" - echo - - else - printf "mygit - Sample application that delegates unknown commands to a different executable\n" - echo - - fi - - printf "Usage:\n" - printf " mygit [command]\n" - printf " mygit [command] --help | -h\n" - printf " mygit --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " push Push to my repository" - echo " pull Pull from my repository" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -mygit_push_usage() { - if [[ -n $long_usage ]]; then - printf "mygit push - Push to my repository\n" - echo - - else - printf "mygit push - Push to my repository\n" - echo - - fi - - printf "Shortcut: p\n" - echo - - printf "Usage:\n" - printf " mygit push\n" - printf " mygit push --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -mygit_pull_usage() { - if [[ -n $long_usage ]]; then - printf "mygit pull - Pull from my repository\n" - echo - - else - printf "mygit pull - Pull from my repository\n" - echo - - fi - - printf "Shortcut: l\n" - echo - - printf "Usage:\n" - printf " mygit pull\n" - printf " mygit pull --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -mygit_push_command() { - # :src/push_command.sh - echo "# this file is located in 'src/push_command.sh'" - echo "# code for 'mygit push' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -mygit_pull_command() { - # :src/pull_command.sh - echo "# this file is located in 'src/pull_command.sh'" - echo "# code for 'mygit pull' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - mygit_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - push | p ) - action="push" - shift - mygit_push_parse_requirements "$@" - shift $# - ;; - - pull | l ) - action="pull" - shift - mygit_pull_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - "" ) - mygit_usage - exit 1 - ;; - - * ) - if [[ -x "$(command -v "git")" ]]; then - exec git "$@" - else - mygit_usage - exit 1 - fi - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -mygit_push_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - mygit_push_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="push" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -mygit_pull_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - mygit_pull_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="pull" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "push" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - mygit_push_usage - else - mygit_push_command - fi - - elif [[ $action == "pull" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - mygit_pull_usage - else - mygit_pull_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/extensible/cli b/examples/extensible/cli deleted file mode 100644 index dd58fa47..00000000 --- a/examples/extensible/cli +++ /dev/null @@ -1,429 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Sample application that can be externally extended\n" - echo - - else - printf "cli - Sample application that can be externally extended\n" - echo - - fi - - printf "Usage:\n" - printf " cli [command]\n" - printf " cli [command] --help | -h\n" - printf " cli --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " upload Upload a file" - echo " download Download a file" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -cli_upload_usage() { - if [[ -n $long_usage ]]; then - printf "cli upload - Upload a file\n" - echo - - else - printf "cli upload - Upload a file\n" - echo - - fi - - printf "Shortcut: u\n" - echo - - printf "Usage:\n" - printf " cli upload SOURCE\n" - printf " cli upload --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " File to upload\n" - echo - - fi -} - -# :command.usage -cli_download_usage() { - if [[ -n $long_usage ]]; then - printf "cli download - Download a file\n" - echo - - else - printf "cli download - Download a file\n" - echo - - fi - - printf "Shortcut: d\n" - echo - - printf "Usage:\n" - printf " cli download SOURCE\n" - printf " cli download --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " File to download\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -cli_upload_command() { - # :src/upload_command.sh - echo "# this file is located in 'src/upload_command.sh'" - echo "# code for 'cli upload' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -cli_download_command() { - # :src/download_command.sh - echo "# this file is located in 'src/download_command.sh'" - echo "# code for 'cli download' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - upload | u ) - action="upload" - shift - cli_upload_parse_requirements "$@" - shift $# - ;; - - download | d ) - action="download" - shift - cli_download_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - "" ) - cli_usage - exit 1 - ;; - - * ) - if [[ -x "$(command -v "cli-$action")" ]]; then - shift - exec "cli-$action" "$@" - else - cli_usage - exit 1 - fi - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_upload_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_upload_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="upload" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli upload SOURCE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -cli_download_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - cli_download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="download" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: cli download SOURCE\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "upload" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_upload_usage - else - cli_upload_command - fi - - elif [[ $action == "download" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - cli_download_usage - else - cli_download_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/footer/download b/examples/footer/download deleted file mode 100644 index 1f34a761..00000000 --- a/examples/footer/download +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -download_usage() { - if [[ -n $long_usage ]]; then - printf "download - Sample application with a help footer\n" - echo - - else - printf "download - Sample application with a help footer\n" - echo - - fi - - printf "Usage:\n" - printf " download [SOURCE]\n" - printf " download --help | -h\n" - printf " download --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - printf "This will appear at the end of the --help message.\n\nIt can contain multiple lines, and \"double\" or 'single' quotes are\nproperly escaped.\n\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/git-like/git b/examples/git-like/git deleted file mode 100644 index 44bf15df..00000000 --- a/examples/git-like/git +++ /dev/null @@ -1,407 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -git_usage() { - if [[ -n $long_usage ]]; then - printf "git - Git example\n" - echo - - else - printf "git - Git example\n" - echo - - fi - - printf "Usage:\n" - printf " git [command]\n" - printf " git [command] --help | -h\n" - printf " git --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " status Show repository status" - echo " commit Commit changes" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - fi -} - -# :command.usage -git_status_usage() { - if [[ -n $long_usage ]]; then - printf "git status - Show repository status\n" - echo - - else - printf "git status - Show repository status\n" - echo - - fi - - printf "Shortcut: s*\n" - echo - - printf "Usage:\n" - printf " git status\n" - printf " git status --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - fi -} - -# :command.usage -git_commit_usage() { - if [[ -n $long_usage ]]; then - printf "git commit - Commit changes\n" - echo - - else - printf "git commit - Commit changes\n" - echo - - fi - - printf "Shortcut: c*\n" - echo - - printf "Usage:\n" - printf " git commit [options]\n" - printf " git commit --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --message, -m MESSAGE" - printf " Commit message\n" - echo - - # :flag.usage - echo " --all, -a" - printf " Automatically stage files\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -git_status_command() { - # :src/status_command.sh - echo "# this file is located in 'src/status_command.sh'" - echo "# code for 'git status' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -git_commit_command() { - # :src/commit_command.sh - echo "# this file is located in 'src/commit_command.sh'" - echo "# code for 'git commit' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - git_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - status | s* ) - action="status" - shift - git_status_parse_requirements "$@" - shift $# - ;; - - commit | c* ) - action="commit" - shift - git_commit_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - git_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -git_status_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - git_status_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="status" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -git_commit_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - git_commit_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="commit" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --message | -m ) - if [[ $2 ]]; then - args[--message]="$2" - shift - shift - else - printf "%s\n" "--message requires an argument: --message, -m MESSAGE" - exit 1 - fi - ;; - - # :flag.case - --all | -a ) - args[--all]=1 - shift - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "status" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - git_status_usage - else - git_status_command - fi - - elif [[ $action == "commit" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - git_commit_usage - else - git_commit_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/minimal/download b/examples/minimal/download deleted file mode 100644 index 7a7c09bb..00000000 --- a/examples/minimal/download +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -download_usage() { - if [[ -n $long_usage ]]; then - printf "download - Sample minimal application without commands\n" - echo - - else - printf "download - Sample minimal application without commands\n" - echo - - fi - - printf "Usage:\n" - printf " download SOURCE [TARGET] [options]\n" - printf " download --help | -h\n" - printf " download --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - # :command.usage_flags - # :flag.usage - echo " --force, -f" - printf " Overwrite existing files\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " SOURCE" - printf " URL to download from\n" - echo - - # :argument.usage - echo " TARGET" - printf " Target filename (default: same as source)\n" - echo - - # :command.usage_examples - printf "Examples:\n" - - printf " download example.com\n" - printf " download example.com ./output -f\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - download_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[source]=$1 - shift - else - printf "missing required argument: SOURCE\nusage: download SOURCE [TARGET] [options]\n" - exit 1 - fi - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --force | -f ) - args[--force]=1 - shift - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[source]} ]]; then - args[source]=$1 - shift - elif [[ ! ${args[target]} ]]; then - args[target]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/minus-v/cli b/examples/minus-v/cli deleted file mode 100644 index c371d1f0..00000000 --- a/examples/minus-v/cli +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -cli_usage() { - if [[ -n $long_usage ]]; then - printf "cli - Example that replaces the default behavior of -v and -h\n" - echo - - else - printf "cli - Example that replaces the default behavior of -v and -h\n" - echo - - fi - - printf "Usage:\n" - printf " cli [options]\n" - printf " cli --help\n" - printf " cli --version\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help" - printf " Show this help\n" - echo - echo " --version" - printf " Show version number\n" - echo - # :command.usage_flags - # :flag.usage - echo " --verbose, -v" - printf " Show verbose output\n" - echo - - # :flag.usage - echo " --host, -h HOST" - printf " Host address\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version ) - version_command - exit - ;; - - --help ) - long_usage=yes - cli_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --verbose | -v ) - args[--verbose]=1 - shift - ;; - - # :flag.case - --host | -h ) - if [[ $2 ]]; then - args[--host]="$2" - shift - shift - else - printf "%s\n" "--host requires an argument: --host, -h HOST" - exit 1 - fi - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/multiline/multi b/examples/multiline/multi deleted file mode 100644 index df895397..00000000 --- a/examples/multiline/multi +++ /dev/null @@ -1,428 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -multi_usage() { - if [[ -n $long_usage ]]; then - printf "multi\n" - echo - - printf " Multiline test\n \n This is a multiline test example. Long lines are going to be properly wrapped\n at the 80 character mark.\n" - echo - - else - printf "multi - Multiline test\n" - echo - - fi - - printf "Usage:\n" - printf " multi [command]\n" - printf " multi [command] --help | -h\n" - printf " multi --version | -v\n" - echo - # :command.usage_commands - printf "Commands:\n" - echo " multiline Do some multiline work." - echo " regular Standard help line" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - - # :command.usage_environment_variables - printf "Environment Variables:\n" - - # :environment_variable.usage - echo " MULTI_VITAMIN" - printf " Environment variables can also use multiple lines. This can be useful if we\n need to explain - in excruciating detail - what the environemnt variable is\n used for.\n" - echo - # :command.usage_examples - printf "Examples:\n" - - printf " Examples can also use multiple lines. This can be useful if we need to explain\n the example, for instance like we are doing here:\n \n multi multiline --flag\n" - echo - - fi -} - -# :command.usage -multi_multiline_usage() { - if [[ -n $long_usage ]]; then - printf "multi multiline\n" - echo - - printf " Do some multiline work.\n \n This is a long process and takes time, therefore it takes a lot of lines to\n describe and this line is particularly long.\n \n But - not all hope is lost. Bashly should respect newlines and word-wrap long\n lines properly at the 80 character mark.\n" - echo - - else - printf "multi multiline - Do some multiline work.\n" - echo - - fi - - printf "Usage:\n" - printf " multi multiline [MY_ARG] [options]\n" - printf " multi multiline --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - # :command.usage_flags - # :flag.usage - echo " --long" - printf " Long flag with long text.\n \n Finally, this will be the last multiline string we type (hopefully), but\n once we are done with this, we will be done with all.\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " MY_ARG" - printf " Argument with multiline.\n \n Once again we gather here to prepare some long lines that will most likely\n seem silly to anyone who reads them.\n \n But, it is just needed for testing - otherwise, it will not only be silly,\n but it will also be buggy!\n" - echo - - fi -} - -# :command.usage -multi_regular_usage() { - if [[ -n $long_usage ]]; then - printf "multi regular - Standard help line\n" - echo - - else - printf "multi regular - Standard help line\n" - echo - - fi - - printf "Usage:\n" - printf " multi regular [REPO]\n" - printf " multi regular --help | -h\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " REPO" - printf " Repository name\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions -# :command.function -multi_multiline_command() { - # :src/multiline_command.sh - echo "# this file is located in 'src/multiline_command.sh'" - echo "# code for 'multi multiline' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.function -multi_regular_command() { - # :src/regular_command.sh - echo "# this file is located in 'src/regular_command.sh'" - echo "# code for 'multi regular' goes here" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - multi_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action=$1 - - case $action in - -* ) - ;; - - multiline ) - action="multiline" - shift - multi_multiline_parse_requirements "$@" - shift $# - ;; - - regular ) - action="regular" - shift - multi_regular_parse_requirements "$@" - shift $# - ;; - - # :command.command_fallback - * ) - multi_usage - exit 1 - ;; - - esac - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - printf "invalid argument: %s\n" "$key" - exit 1 - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -multi_multiline_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - multi_multiline_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="multiline" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --long ) - args[--long]=1 - shift - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[my_arg]} ]]; then - args[my_arg]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.parse_requirements -multi_regular_parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - multi_regular_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="regular" - # :command.required_args_filter - # :command.required_flags_filter - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[repo]} ]]; then - args[repo]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - # :command.whitelist_filter -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "multiline" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - multi_multiline_usage - else - multi_multiline_command - fi - - elif [[ $action == "regular" ]]; then - if [[ ${args[--help]} ]]; then - long_usage=yes - multi_regular_usage - else - multi_regular_command - fi - - elif [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/whitelist/login b/examples/whitelist/login deleted file mode 100644 index 3c3633ca..00000000 --- a/examples/whitelist/login +++ /dev/null @@ -1,263 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - echo "# this file is located in 'src/root_command.sh'" - echo "# you can edit it freely and regenerate (it will not be overwritten)" - inspect_args -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -login_usage() { - if [[ -n $long_usage ]]; then - printf "login - Sample showing the use of arg and flag whitelist (allowed values)\n" - echo - - else - printf "login - Sample showing the use of arg and flag whitelist (allowed values)\n" - echo - - fi - - printf "Usage:\n" - printf " login REGION [ENVIRONMENT] [options]\n" - printf " login --help | -h\n" - printf " login --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - # :command.usage_flags - # :flag.usage - echo " --user, -u NAME (required)" - printf " User name\n" - printf " Allowed: user, admin\n" - echo - - # :flag.usage - echo " --protocol, -p TYPE" - printf " Protocol to connect with\n" - printf " Allowed: ftp, ssh, http\n" - printf " Default: ssh\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " REGION" - printf " Region to connect to\n" - printf " Allowed: eu, us\n" - echo - - # :argument.usage - echo " ENVIRONMENT" - printf " Environment to connect to\n" - printf " Allowed: stage, production, development\n" - printf " Default: development\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.command_functions - -# :command.parse_requirements -parse_requirements() { - # :command.fixed_flag_filter - case "$1" in - --version | -v ) - version_command - exit - ;; - - --help | -h ) - long_usage=yes - login_usage - exit - ;; - - esac - # :command.environment_variables_filter - # :command.dependencies_filter - # :command.command_filter - action="root" - # :command.required_args_filter - if [[ $1 && $1 != -* ]]; then - args[region]=$1 - shift - else - printf "missing required argument: REGION\nusage: login REGION [ENVIRONMENT] [options]\n" - exit 1 - fi - # :command.required_flags_filter - argstring="$*" - if [[ "$argstring" != *--user* && "$argstring" != *-u* ]]; then - printf "missing required flag: --user, -u NAME\n" - exit 1 - fi - # :command.parse_requirements_while - while [[ $# -gt 0 ]]; do - key="$1" - case "$key" in - # :flag.case - --user | -u ) - if [[ $2 ]]; then - args[--user]="$2" - shift - shift - else - printf "%s\n" "--user requires an argument: --user, -u NAME" - exit 1 - fi - ;; - - # :flag.case - --protocol | -p ) - if [[ $2 ]]; then - args[--protocol]="$2" - shift - shift - else - printf "%s\n" "--protocol requires an argument: --protocol, -p TYPE" - exit 1 - fi - ;; - - -* ) - printf "invalid option: %s\n" "$key" - exit 1 - ;; - - * ) - # :command.parse_requirements_case - if [[ ! ${args[region]} ]]; then - args[region]=$1 - shift - elif [[ ! ${args[environment]} ]]; then - args[environment]=$1 - shift - else - printf "invalid argument: %s\n" "$key" - exit 1 - fi - ;; - - esac - done - # :command.catch_all_filter - # :command.default_assignments - [[ -n ${args[environment]} ]] || args[environment]="development" - [[ -n ${args[--protocol]} ]] || args[--protocol]="ssh" - # :command.whitelist_filter - if [[ ! ${args[region]} =~ ^(eu|us)$ ]]; then - printf "%s\n" "region must be one of: eu, us" - exit 1 - fi - if [[ ! ${args[environment]} =~ ^(stage|production|development)$ ]]; then - printf "%s\n" "environment must be one of: stage, production, development" - exit 1 - fi - if [[ ! ${args[--user]} =~ ^(user|admin)$ ]]; then - printf "%s\n" "--user must be one of: user, admin" - exit 1 - fi - if [[ ! ${args[--protocol]} =~ ^(ftp|ssh|http)$ ]]; then - printf "%s\n" "--protocol must be one of: ftp, ssh, http" - exit 1 - fi -} - -# :command.initialize -initialize() { - version="0.1.0" - long_usage='' - set -e - - if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then - printf "bash version 4 or higher is required\n" - exit 1 - fi - - # :src/initialize.sh - # Code here runs inside the initialize() function - # Use it for anything that you need to run before any other function, like - # setting environment vairables: - # CONFIG_FILE=settings.ini - # - # Feel free to empty (but not delete) this file. -} - -# :command.run -run() { - declare -A args - declare -a other_args - declare -a input - normalize_input "$@" - parse_requirements "${input[@]}" - - if [[ $action == "root" ]]; then - root_command - fi -} - -initialize -run "$@" diff --git a/examples/yaml/yaml b/examples/yaml/yaml deleted file mode 100644 index e24845e7..00000000 --- a/examples/yaml/yaml +++ /dev/null @@ -1,278 +0,0 @@ -#!/usr/bin/env bash -# This script was generated by bashly (https://github.com/DannyBen/bashly) -# Modifying it manually is not recommended - -# :command.root_command -root_command() { - # :src/root_command.sh - filename=${args[filename]} - variable=${args[variable]} - prefix=${args[--prefix]} - - if [[ $variable ]]; then - eval "$(yaml_load "$filename" "$prefix")" - value=${!variable} - - if [[ $value ]]; then - echo "$variable=$value" - else - echo "variable not found: $variable" - fi - - else - yaml_load "$filename" "$prefix" - - fi -} - -# :command.version_command -version_command() { - echo "$version" -} - -# :command.usage -yaml_usage() { - if [[ -n $long_usage ]]; then - printf "yaml - Sample application that uses the YAML functions\n" - echo - - else - printf "yaml - Sample application that uses the YAML functions\n" - echo - - fi - - printf "Usage:\n" - printf " yaml FILENAME [VARIABLE] [options]\n" - printf " yaml --help | -h\n" - printf " yaml --version | -v\n" - echo - - if [[ -n $long_usage ]]; then - printf "Options:\n" - # :command.usage_fixed_flags - echo " --help, -h" - printf " Show this help\n" - echo - echo " --version, -v" - printf " Show version number\n" - echo - # :command.usage_flags - # :flag.usage - echo " --prefix, -p PREFIX" - printf "\n" - echo - # :command.usage_args - printf "Arguments:\n" - - # :argument.usage - echo " FILENAME" - printf " The YAML file to read\n" - echo - - # :argument.usage - echo " VARIABLE" - printf " Show only this variable\n" - echo - - # :command.usage_examples - printf "Examples:\n" - - printf " yaml settings.yml\n" - printf " yaml settings.yml --prefix config_\n" - printf " yaml settings.yml server_port\n" - echo - - fi -} - -# :command.normalize_input -normalize_input() { - local arg flags - - while [[ $# -gt 0 ]]; do - arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then - input+=("${BASH_REMATCH[1]}") - input+=("${BASH_REMATCH[2]}") - elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then - flags="${BASH_REMATCH[1]}" - for (( i=0 ; i < ${#flags} ; i++ )); do - input+=("-${flags:i:1}") - done - else - input+=("$arg") - fi - - shift - done -} -# :command.inspect_args -inspect_args() { - readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) - if (( ${#args[@]} )); then - echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done - else - echo args: none - fi - - if (( ${#other_args[@]} )); then - echo - echo other_args: - echo "- \${other_args[*]} = ${other_args[*]}" - for i in "${!other_args[@]}"; do - echo "- \${other_args[$i]} = ${other_args[$i]}" - done - fi -} - -# :command.user_lib -# :src/lib/yaml.sh -# --- -# YAML parser -# This file is a part of Bashly standard library -# Does not support arrays, only hashes -# -# Source: https://stackoverflow.com/a/21189044/413924 -# -# Usage: -# -# yaml_load "settings.yml" # print variables -# yaml_load "settings.yml" "config_" # use prefix -# eval $(yaml_load "settings.yml") # create variables in scope -# -# --- - -yaml_load() { - local prefix=$2 - local s='[[:space:]]*' w='[a-zA-Z0-9_]*' - local fs - - fs=$(echo @|tr @ '\034') - - sed -ne "s|^\($s\):|\1|" \ - -e "s|^\($s\)\($w\)$s:${s}[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ - -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" | - awk -F"$fs" '{ - indent = length($1)/2; - vname[indent] = $2; - for (i in vname) {if (i > indent) {delete vname[i]}} - if (length($3) > 0) { - vn=""; for (i=0; i Date: Sat, 9 Oct 2021 07:42:33 +0000 Subject: [PATCH 2/3] add .gitignore to all examples --- examples/catch-all-advanced/.gitignore | 1 + examples/catch-all/.gitignore | 1 + examples/colors/.gitignore | 1 + examples/command-default/.gitignore | 1 + examples/command-groups/.gitignore | 1 + examples/commands-nested/.gitignore | 1 + examples/commands/.gitignore | 1 + examples/completions/.gitignore | 1 + examples/config-ini/.gitignore | 1 + examples/custom-includes/.gitignore | 1 + examples/custom-strings/.gitignore | 1 + examples/default-values/.gitignore | 1 + examples/dependencies/.gitignore | 1 + examples/docker-like/.gitignore | 1 + examples/environment-variables/.gitignore | 1 + examples/extensible-delegate/.gitignore | 1 + examples/extensible/.gitignore | 1 + examples/footer/.gitignore | 1 + examples/git-like/.gitignore | 1 + examples/minimal/.gitignore | 1 + examples/minus-v/.gitignore | 1 + examples/multiline/.gitignore | 1 + examples/whitelist/.gitignore | 1 + examples/yaml/.gitignore | 1 + 24 files changed, 24 insertions(+) create mode 100644 examples/catch-all-advanced/.gitignore create mode 100644 examples/catch-all/.gitignore create mode 100644 examples/colors/.gitignore create mode 100644 examples/command-default/.gitignore create mode 100644 examples/command-groups/.gitignore create mode 100644 examples/commands-nested/.gitignore create mode 100644 examples/commands/.gitignore create mode 100644 examples/completions/.gitignore create mode 100644 examples/config-ini/.gitignore create mode 100644 examples/custom-includes/.gitignore create mode 100644 examples/custom-strings/.gitignore create mode 100644 examples/default-values/.gitignore create mode 100644 examples/dependencies/.gitignore create mode 100644 examples/docker-like/.gitignore create mode 100644 examples/environment-variables/.gitignore create mode 100644 examples/extensible-delegate/.gitignore create mode 100644 examples/extensible/.gitignore create mode 100644 examples/footer/.gitignore create mode 100644 examples/git-like/.gitignore create mode 100644 examples/minimal/.gitignore create mode 100644 examples/minus-v/.gitignore create mode 100644 examples/multiline/.gitignore create mode 100644 examples/whitelist/.gitignore create mode 100644 examples/yaml/.gitignore diff --git a/examples/catch-all-advanced/.gitignore b/examples/catch-all-advanced/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/catch-all-advanced/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/catch-all/.gitignore b/examples/catch-all/.gitignore new file mode 100644 index 00000000..8a58e1ae --- /dev/null +++ b/examples/catch-all/.gitignore @@ -0,0 +1 @@ +download \ No newline at end of file diff --git a/examples/colors/.gitignore b/examples/colors/.gitignore new file mode 100644 index 00000000..68068ffe --- /dev/null +++ b/examples/colors/.gitignore @@ -0,0 +1 @@ +colorly \ No newline at end of file diff --git a/examples/command-default/.gitignore b/examples/command-default/.gitignore new file mode 100644 index 00000000..d383aab4 --- /dev/null +++ b/examples/command-default/.gitignore @@ -0,0 +1 @@ +ftp \ No newline at end of file diff --git a/examples/command-groups/.gitignore b/examples/command-groups/.gitignore new file mode 100644 index 00000000..d383aab4 --- /dev/null +++ b/examples/command-groups/.gitignore @@ -0,0 +1 @@ +ftp \ No newline at end of file diff --git a/examples/commands-nested/.gitignore b/examples/commands-nested/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/commands-nested/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/commands/.gitignore b/examples/commands/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/commands/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/completions/.gitignore b/examples/completions/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/completions/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/config-ini/.gitignore b/examples/config-ini/.gitignore new file mode 100644 index 00000000..bd44730a --- /dev/null +++ b/examples/config-ini/.gitignore @@ -0,0 +1 @@ +configly \ No newline at end of file diff --git a/examples/custom-includes/.gitignore b/examples/custom-includes/.gitignore new file mode 100644 index 00000000..8a58e1ae --- /dev/null +++ b/examples/custom-includes/.gitignore @@ -0,0 +1 @@ +download \ No newline at end of file diff --git a/examples/custom-strings/.gitignore b/examples/custom-strings/.gitignore new file mode 100644 index 00000000..8a58e1ae --- /dev/null +++ b/examples/custom-strings/.gitignore @@ -0,0 +1 @@ +download \ No newline at end of file diff --git a/examples/default-values/.gitignore b/examples/default-values/.gitignore new file mode 100644 index 00000000..079ae940 --- /dev/null +++ b/examples/default-values/.gitignore @@ -0,0 +1 @@ +convert \ No newline at end of file diff --git a/examples/dependencies/.gitignore b/examples/dependencies/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/dependencies/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/docker-like/.gitignore b/examples/docker-like/.gitignore new file mode 100644 index 00000000..6d0eac4b --- /dev/null +++ b/examples/docker-like/.gitignore @@ -0,0 +1 @@ +docker \ No newline at end of file diff --git a/examples/environment-variables/.gitignore b/examples/environment-variables/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/environment-variables/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/extensible-delegate/.gitignore b/examples/extensible-delegate/.gitignore new file mode 100644 index 00000000..6b078266 --- /dev/null +++ b/examples/extensible-delegate/.gitignore @@ -0,0 +1 @@ +mygit \ No newline at end of file diff --git a/examples/extensible/.gitignore b/examples/extensible/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/extensible/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/footer/.gitignore b/examples/footer/.gitignore new file mode 100644 index 00000000..8a58e1ae --- /dev/null +++ b/examples/footer/.gitignore @@ -0,0 +1 @@ +download \ No newline at end of file diff --git a/examples/git-like/.gitignore b/examples/git-like/.gitignore new file mode 100644 index 00000000..0899c299 --- /dev/null +++ b/examples/git-like/.gitignore @@ -0,0 +1 @@ +git \ No newline at end of file diff --git a/examples/minimal/.gitignore b/examples/minimal/.gitignore new file mode 100644 index 00000000..8a58e1ae --- /dev/null +++ b/examples/minimal/.gitignore @@ -0,0 +1 @@ +download \ No newline at end of file diff --git a/examples/minus-v/.gitignore b/examples/minus-v/.gitignore new file mode 100644 index 00000000..76ec9f59 --- /dev/null +++ b/examples/minus-v/.gitignore @@ -0,0 +1 @@ +cli \ No newline at end of file diff --git a/examples/multiline/.gitignore b/examples/multiline/.gitignore new file mode 100644 index 00000000..5914448d --- /dev/null +++ b/examples/multiline/.gitignore @@ -0,0 +1 @@ +multi \ No newline at end of file diff --git a/examples/whitelist/.gitignore b/examples/whitelist/.gitignore new file mode 100644 index 00000000..e9f12b60 --- /dev/null +++ b/examples/whitelist/.gitignore @@ -0,0 +1 @@ +login \ No newline at end of file diff --git a/examples/yaml/.gitignore b/examples/yaml/.gitignore new file mode 100644 index 00000000..02097926 --- /dev/null +++ b/examples/yaml/.gitignore @@ -0,0 +1 @@ +yaml \ No newline at end of file From 0e1e20ed0904fa3ae483e50d2501c3e5c32e29b8 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 9 Oct 2021 07:45:13 +0000 Subject: [PATCH 3/3] fix integration spec to generate before testing --- spec/bashly/integration/bash_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/bashly/integration/bash_spec.rb b/spec/bashly/integration/bash_spec.rb index d6024144..2aeff74b 100644 --- a/spec/bashly/integration/bash_spec.rb +++ b/spec/bashly/integration/bash_spec.rb @@ -8,6 +8,7 @@ command = "docker run --rm -v $PWD:/app bash:3 bash /app/download" Dir.chdir "examples/minimal" do + system "bashly generate 2>&1 >/dev/null" expect(`#{command} 2>&1`).to match_approval('bash/error') end end