From 92c6e38c70e77f149e310abbe5e99f286424a9d9 Mon Sep 17 00:00:00 2001 From: Salt Date: Thu, 23 Jan 2020 15:11:11 -0600 Subject: [PATCH] Reorganize pre-flight checks Dude why the fuck did you have to have a valid backend to check the help text What was I smoking --- ptgdp | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/ptgdp b/ptgdp index 1cc64fa..453da80 100755 --- a/ptgdp +++ b/ptgdp @@ -349,6 +349,8 @@ main() { ;; esac done + # Early hook for help + [ -n "$_opthelp" ] && printhelp && exit 0 # Parse out a config file if it exists if [ -f "$_optconfigfile" ]; then log "Loading config file" 2 @@ -370,30 +372,30 @@ main() { _args+=("$arg") done # Validate critical options - ( - for backend in ${_supportedbackends[@]}; do - if [ "$backend" = "${_config[backend]}" ]; then - return 0 - fi - done - return 1 - ) || error "Unsupported backend: ${_config[backend]}" 50 - if [ -z "$_optmachinemode" ] && ! backend-validate; then - errorcode=$? - case $errorcode in - 1) - error "Missing dependency for backend ${_config[backend]}: $_return" 50 - ;; - *) - error "Backend error: $errorcode: $_return" 50 - ;; - esac + if [ -z "$_optmachinemode" ]; then + # Ensure we have a good backend, assuming we're not in a scripting mode + ( + for backend in ${_supportedbackends[@]}; do + if [ "$backend" = "${_config[backend]}" ]; then + return 0 + fi + done + return 1 + ) || error "Unsupported backend: ${_config[backend]}" 50 + # Ensure we meet its requirements + if ! backend-validate; then + errorcode=$? + case $errorcode in + 1) + error "Missing dependency for backend ${_config[backend]}: $_return" 50 + ;; + *) + error "Backend error: $errorcode: $_return" 50 + ;; + esac + fi fi - - # Pre-really-do-stuff hooks like help text - [ -n "$_opthelp" ] && printhelp && exit 0 - - # Ensure we're ready to do the do + # Validate core program dependencies log "Validating dependencies" 2 if ! has youtube-dl pgrep; then error "Failed to find program: $_return" 1