From b76d81b4fff5d1c4587645839262886c5d2f133a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 4 Oct 2022 22:47:25 -0500 Subject: add -q and better logic for -c --- vienna | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/vienna b/vienna index e09427f..0ae7027 100755 --- a/vienna +++ b/vienna @@ -11,12 +11,14 @@ VIENNA: a tiny, tasty ssg by C. Duckworth USAGE: vienna [-h] - vienna [-C DIR] [-d DOMAIN] [-o DIR] [COMMAND] + vienna [-q] [-c CONFIG] [-C DIR] [-d DOMAIN] [-o DIR] [COMMAND] FLAGS: -h view this help + -q don't output any diagnostic information OPTIONS: + -c CONFIG source CONFIG instead of \$VIENNA_CONFIG when building -C DIR operate in DIR, instead of \$PWD. -d DOMAIN use DOMAIN as basis for urls. default: example.com -o DIR output built site to DIR. default: ./out @@ -54,12 +56,18 @@ configure() { # Logging LOG=true ## Parse command line arguments - while getopts d:C:o:hq opt; do + while getopts C:c:d:ho:q opt; do case "$opt" in - d) DOMAIN="$OPTARG" ;; C) WORKD="$OPTARG" ;; - o) OUTD="$OPTARG" ;; + c) + CONFIG="$OPTARG" + # To error later if a config is specified on the command + # line but doesn't exist. + CONFIG_ARG=1 + ;; + d) DOMAIN="$OPTARG" ;; h) usage 0 ;; + o) OUTD="$OPTARG" ;; q) LOG=false ;; *) exit 1 ;; esac @@ -94,6 +102,17 @@ main() { # Prepare cd "$WORKD" || exit 2 test -f "$CONFIG" && . "$CONFIG" # Source ./.vienna.sh, if it exists. + if test -f "$CONFIG"; then + # Source ./.vienna.sh, if it exists. + . "$CONFIG" + elif test -n "$CONFIG_ARG"; then + # If a -c option was passed on the command line but the file + # doesn't exist, that's an error. If we're just looking for the + # default file, however, there is no error---the user might want + # to use the default configuration. + log "Can't find configuration \`$CONFIG'." + exit 2 + fi mkdir -p "$OUTD" || exit 2 mkdir -p "$TMPD" || exit 2 # Build pages -- cgit 1.4.1-21-gabe81