diff --git a/romscope b/romscope index b2d3032..f8fc4d4 100755 --- a/romscope +++ b/romscope @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# This script was generated by bashly 1.1.10 (https://bashly.dannyb.co) +# This script was generated by bashly 1.2.13 (https://bashly.dev) # Modifying it manually is not recommended # :wrapper.bash3_bouncer @@ -17,15 +17,7 @@ version_command() { # :command.usage romscope_usage() { - if [[ -n $long_usage ]]; then - printf "romscope - A tool for comparing firmware binaries\n" - echo - - else - printf "romscope - A tool for comparing firmware binaries\n" - echo - - fi + printf "romscope - A tool for comparing firmware binaries\n\n" printf "%s\n" "Usage:" printf " romscope COMMAND\n" @@ -39,7 +31,7 @@ romscope_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -55,16 +47,7 @@ romscope_usage() { # :command.usage romscope_extract_usage() { - if [[ -n $long_usage ]]; then - printf "romscope extract - Extract subregions from a firmware binary\n" - echo - - else - printf "romscope extract - Extract subregions from a firmware binary\n" - echo - - fi - + printf "romscope extract - Extract subregions from a firmware binary\n\n" printf "Alias: e\n" echo @@ -74,7 +57,7 @@ romscope_extract_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -105,16 +88,7 @@ romscope_extract_usage() { # :command.usage romscope_compare_usage() { - if [[ -n $long_usage ]]; then - printf "romscope compare - Compare two binaries\n" - echo - - else - printf "romscope compare - Compare two binaries\n" - echo - - fi - + printf "romscope compare - Compare two binaries\n\n" printf "Alias: c\n" echo @@ -124,7 +98,7 @@ romscope_compare_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -156,7 +130,7 @@ romscope_compare_usage() { # :command.normalize_input # :command.normalize_input_function normalize_input() { - local arg flags passthru + local arg passthru flags passthru=false while [[ $# -gt 0 ]]; do @@ -197,15 +171,6 @@ inspect_args() { 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 - if ((${#deps[@]})); then readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort) echo @@ -301,6 +266,7 @@ rom_extract() { # :command.command_functions # :command.function romscope_extract_command() { + # src/extract_command.sh # SPDX-FileCopyrightText: 2024 3mdeb Sp. z o. o. # @@ -315,6 +281,7 @@ romscope_extract_command() { # :command.function romscope_compare_command() { + # src/compare_command.sh # SPDX-FileCopyrightText: 2024 3mdeb Sp. z o. o. # @@ -416,7 +383,8 @@ romscope_compare_command() { parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --version | -v) version_command exit @@ -436,27 +404,35 @@ parse_requirements() { done # :command.dependencies_filter - if command -v cbfstool >/dev/null 2>&1; then - deps['cbfstool']="$(command -v cbfstool | head -n1)" - else + missing_deps= + # :dependency.filter + if ! command -v cbfstool >/dev/null 2>&1; then printf "missing dependency: cbfstool\n" >&2 - printf "%s\n" "You can install from your distribution's package repositories or build from source code: https://review.coreboot.org/coreboot.git\n" >&2 - exit 1 + printf "%s\n\n" "You can install from your distribution's package repositories or build from source code: https://review.coreboot.org/coreboot.git\n" >&2 + missing_deps=1 + else + deps['cbfstool']="$(command -v cbfstool | head -n1)" fi - if command -v ifdtool >/dev/null 2>&1; then - deps['ifdtool']="$(command -v ifdtool | head -n1)" - else + # :dependency.filter + if ! command -v ifdtool >/dev/null 2>&1; then printf "missing dependency: ifdtool\n" >&2 - printf "%s\n" "You can install from your distribution's package repositories or build from source code: https://review.coreboot.org/coreboot.git\n" >&2 - exit 1 + printf "%s\n\n" "You can install from your distribution's package repositories or build from source code: https://review.coreboot.org/coreboot.git\n" >&2 + missing_deps=1 + else + deps['ifdtool']="$(command -v ifdtool | head -n1)" fi - if command -v ifdtool >/dev/null 2>&1; then - deps['diffoscope']="$(command -v ifdtool | head -n1)" - else + # :dependency.filter + if ! command -v ifdtool >/dev/null 2>&1; then printf "missing dependency: diffoscope\n" >&2 - printf "%s\n" "You can install from your distribution's package repositories or build from source code: https://diffoscope.org/\n" >&2 + printf "%s\n\n" "You can install from your distribution's package repositories or build from source code: https://diffoscope.org/\n" >&2 + missing_deps=1 + else + deps['diffoscope']="$(command -v ifdtool | head -n1)" + fi + + if [[ -n $missing_deps ]]; then exit 1 fi @@ -520,7 +496,8 @@ parse_requirements() { romscope_extract_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes romscope_extract_usage @@ -571,6 +548,7 @@ romscope_extract_parse_requirements() { # :command.required_args_filter if [[ -z ${args['rom']+x} ]]; then printf "missing required argument: ROM\nusage: romscope extract ROM [OUTPUT]\n" >&2 + exit 1 fi @@ -580,7 +558,8 @@ romscope_extract_parse_requirements() { romscope_compare_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes romscope_compare_usage @@ -635,10 +614,13 @@ romscope_compare_parse_requirements() { # :command.required_args_filter if [[ -z ${args['rom1']+x} ]]; then printf "missing required argument: ROM1\nusage: romscope compare ROM1 ROM2 [OUTPUT]\n" >&2 + exit 1 fi + if [[ -z ${args['rom2']+x} ]]; then printf "missing required argument: ROM2\nusage: romscope compare ROM1 ROM2 [OUTPUT]\n" >&2 + exit 1 fi @@ -646,19 +628,20 @@ romscope_compare_parse_requirements() { # :command.initialize initialize() { - version="0.1.0" - long_usage='' + declare -g version="0.1.0" set -e } # :command.run run() { - declare -A args=() - declare -A deps=() - declare -a other_args=() - declare -a env_var_names=() - declare -a input=() + # :command.globals + declare -g long_usage='' + declare -g -A args=() + declare -g -A deps=() + declare -g -a env_var_names=() + declare -g -a input=() + normalize_input "$@" parse_requirements "${input[@]}" @@ -668,5 +651,7 @@ run() { esac } -initialize -run "$@" +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + initialize + run "$@" +fi