summaryrefslogtreecommitdiff
blob: 144d622f12434fe6d98d5f73d30fc4629053a702 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From cfe7dcd8a0e40b8c18556aad0b657f431c90505a Mon Sep 17 00:00:00 2001
From: Oskari Pirhonen <xxc3ncoredxx@gmail.com>
Date: Sun, 13 Aug 2023 14:25:35 -0500
Subject: [PATCH 1/3] Change arg parsing priority

Read config files before parsing CLI args. Allows all options to be set
via config and overridden on the CLI.
---
See also: https://github.com/zlin/wgetpaste/pull/46
- Oskari

 wgetpaste | 53 ++++++++++++++++++++++++++++-------------------------
 1 file 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}
-- 
2.41.0