summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Pirhonen <xxc3ncoredxx@gmail.com>2023-08-13 14:25:35 -0500
committerRasmus Thomsen <oss@cogitri.dev>2023-11-10 09:33:42 +0100
commitcfe7dcd8a0e40b8c18556aad0b657f431c90505a (patch)
tree71d01873a3d2beca0925141f905a2dfa5e75d7e1
parentf1906f0bfe39af5b02a1b6d7c8255790fc6008f6 (diff)
downloadwgetpaste-cfe7dcd8a0e40b8c18556aad0b657f431c90505a.tar.gz
Change arg parsing priority
Read config files before parsing CLI args. Allows all options to be set via config and overridden on the CLI.
-rwxr-xr-xwgetpaste53
1 files changed, 28 insertions, 25 deletions
diff --git a/wgetpaste b/wgetpaste
index fc0b559..5f4152d 100755
--- a/wgetpaste
+++ b/wgetpaste
@@ -720,7 +720,32 @@ geturl() {
fi | tail -n1
}
-### read cli options
+# read the config files
+load_configs() {
+ if [[ ! $IGNORECONFIGS ]]; then
+ # compatibility code
+ local f deprecated=
+ for f in {/etc/,~/.}wgetpaste{.d/*.bash,}; do
+ if [[ -f $f ]]; then
+ if [[ -z $deprecated ]]; then
+ echo "The config files for wgetpaste have changed to *.conf.$N" >&2
+ deprecated=0
+ fi
+ echo "Please move ${f} to ${f%.bash}.conf" >&2
+ source "$f" || die "Failed to source $f"
+ fi
+ done
+ [[ -n $deprecated ]] && echo >&2
+ # new locations override old ones in case they collide
+ for f in {/etc/,~/.}wgetpaste{.d/*,}.conf; do
+ if [[ -f $f ]]; then
+ source "$f" || die "Failed to source $f"
+ fi
+ done
+ fi
+}
+
+### get runtime options
# separate groups of short options. replace --foo=bar with --foo bar
while [[ -n $1 ]]; do
@@ -756,6 +781,8 @@ done
# set the separated options as input options.
set -- "${ARGS[@]}"
+load_configs
+
while [[ -n $1 ]]; do
((args=1))
case "$1" in
@@ -859,30 +886,6 @@ if [[ $NOANSI ]]; then
fi
### defaults
-load_configs() {
- if [[ ! $IGNORECONFIGS ]]; then
- # compatibility code
- local f deprecated=
- for f in {/etc/,~/.}wgetpaste{.d/*.bash,}; do
- if [[ -f $f ]]; then
- if [[ -z $deprecated ]]; then
- echo "The config files for wgetpaste have changed to *.conf.$N" >&2
- deprecated=0
- fi
- echo "Please move ${f} to ${f%.bash}.conf" >&2
- source "$f" || die "Failed to source $f"
- fi
- done
- [[ -n $deprecated ]] && echo >&2
- # new locations override old ones in case they collide
- for f in {/etc/,~/.}wgetpaste{.d/*,}.conf; do
- if [[ -f $f ]]; then
- source "$f" || die "Failed to source $f"
- fi
- done
- fi
-}
-load_configs
[[ $SERVICESET ]] && verifyservice "$SERVICESET" && SERVICE=$(escape "$SERVICESET")
DEFAULT_NICK=${DEFAULT_NICK:-$(whoami)} || die "whoami failed"
DEFAULT_SERVICE=${DEFAULT_SERVICE:-bpaste}