Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Commit f9c881e

Browse files
committed
## Version 1.0.17
- Args refactor
1 parent 6797973 commit f9c881e

File tree

6 files changed

+196
-162
lines changed

6 files changed

+196
-162
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Version 1.0.17
2+
- Args refactor
3+
14
## Version 1.0.16
25
- Help Cleanup
36

smud-cli/include.sh

Lines changed: 1 addition & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ contains() {
5353
# if [ ${#contains_list__[@]} -gt 1 ]; then
5454
# contains_list__="${contains_list__[@]}"
5555
# fi
56-
if [[ ! " ${contains_list__[@]} " =~ " (|'"'|"'")$2(|'"'|"'") " ]]; then
56+
if [] ! " ${contains_list__[@]} " =~ " (|'"'|"'")$2(|'"'|"'") " ]; then
5757
echo 'true'
5858
fi
5959
# [[ $contains_list__ =~ (^|[[:space:]])(|'"'|"'")$2(|'"'|"'")($|[[:space:]]) ]] && echo 'true' || echo ''
@@ -81,156 +81,6 @@ string_to_array()
8181
IFS=$old_SEP
8282
}
8383

84-
parse_arguments()
85-
{
86-
local old_SEP=$IFS
87-
local -n parse_arguments_args="$1"
88-
# echo "0.str: $@"
89-
if [ $# -gt 0 ];then
90-
has_args="true"
91-
local str="$(echo " $@"|sed -e 's/--/-_sep_/g' |sed -e 's/ -/§/g')"
92-
# echo "str: $str"
93-
IFS="§"; read -ra array <<< " $str";
94-
local c=$(echo "${array[0]}" | grep '-' -c)
95-
if [ $c -eq 0 ]; then
96-
shift
97-
if [ $# -eq 0 ];then
98-
IFS=$old_SEP
99-
return
100-
fi
101-
local str="$(echo " $@"|sed -e 's/--/-_sep_/g' |sed -e 's/ -/§/g')"
102-
# echo "str: $str"
103-
IFS="§"; read -ra array <<< " $str";
104-
fi
105-
# echo "str: $str"
106-
# echo "array: ${array[@]}"
107-
for s in "${array[@]}"
108-
do
109-
# echo "0:s: $s"
110-
if [ ! "$s" ] || [ "$s" = " " ]; then
111-
continue
112-
fi
113-
local s="$(echo "$s"|xargs -d ' '| tr -d '\n')"
114-
# echo "s: $s"
115-
local s="$(echo "-$s" |sed -e 's/_sep_/-/g')"
116-
# echo "s: $s"
117-
arg=()
118-
if [ $(grep '=' -c <<< $s) -gt 0 ]; then
119-
IFS='='; read -ra arg <<< "$s"
120-
# echo "eq.arg: { key: ${arg[0]}, value: ${arg[1]} }"
121-
else
122-
IFS=' '; read -ra arg_ <<< "$s"
123-
arg[0]="${arg_[0]}"
124-
arg[1]="${arg_[@]:1}"
125-
# echo "space.arg: { key: ${arg[0]}, value: ${arg[1]} }"
126-
fi
127-
# echo "%%% ${arg[@]}"
128-
129-
local key="${arg[0]}"
130-
# echo "key: $key"
131-
if [ ! "$key" = "-n" ]; then
132-
local key="$(echo "${arg[0]}"|xargs -d ' '| tr -d '\n')"
133-
fi
134-
local value="${arg[1]}"
135-
# echo "key: $key, value: $value"
136-
137-
if [ ! "$value" ]; then
138-
local c=$(echo "$s" | grep ' ' -c)
139-
if [ $c -gt 0 ]; then
140-
IFS=' ';read -ra arg <<< "$s"
141-
local key="$(echo "${arg[0]}")"
142-
local value="$(echo "$s"|sed -e "s/$key //g"|xargs -d ' '| tr -d '\n')"
143-
fi
144-
fi
145-
local value="${value:-true}"
146-
if [ "$key" ]; then
147-
if [ "$key" != "-n" ]; then
148-
key="$(echo "$key"|sed -e "s/---/--/g"|xargs -d ' '| tr -d '\n')"
149-
fi
150-
if [ "$key" != "-" ]; then
151-
local value=$(echo "$value"|xargs -d ' '| tr -d '\n')
152-
old_value=${parse_arguments_args["$key"]}
153-
if [ "$old_value" != "$value" ]; then
154-
if [ "$old_value" ] && [ "$value" != "true" ]; then
155-
if [ ! "$argument_single_mode" ] && [ "$value" ]; then
156-
value="$old_value,$value"
157-
else
158-
value="$old_value"
159-
fi
160-
fi
161-
# if [ "$old_value" ]; then
162-
# print_gray "old_value: [$old_value], value: [$value]"
163-
# fi
164-
165-
parse_arguments_args["$key"]="$value"
166-
fi
167-
fi
168-
fi
169-
done
170-
fi
171-
172-
get_arg verbose '--verbose'
173-
if [ "$verbose" ]; then
174-
debug="true"
175-
for key in "${!parse_arguments_args[@]}";
176-
do
177-
key="${key}"
178-
value="${parse_arguments_args[${key}]}"
179-
done
180-
fi
181-
IFS=$old_SEP
182-
}
183-
184-
get_arg()
185-
{
186-
local -n value="$1"
187-
local old_SEP=$IFS
188-
local global="true"
189-
if [ "$4" ];then
190-
local -n get_arg_args="$4"
191-
fi
192-
193-
if [ "$5" ];then
194-
local global="$5"
195-
fi
196-
197-
if [ "$global" != "true" ]; then
198-
value=""
199-
fi
200-
201-
# echo "keys: $2"
202-
IFS=","; read -ra keys <<< "$2";
203-
for key in "${keys[@]}"
204-
do
205-
if [ ! "$key" = "-n" ]; then
206-
key="$(echo "$key"|xargs -d ' '| tr -d '\n')"
207-
fi
208-
key_value=""
209-
if [ ! "$4" ];then
210-
key_value="${ARGS[$key]}"
211-
else
212-
key_value="${get_arg_args[$key]}"
213-
fi
214-
if [ "$key_value" ]; then
215-
if [ ! "$argument_single_mode" ] && [ "$value" ] && [ "$value" != "true" ];then
216-
value="$value,$key_value"
217-
else
218-
value="$key_value"
219-
fi
220-
fi
221-
done
222-
223-
if [ ! "$value" ] && [ "$3" ]; then
224-
value="$3"
225-
fi
226-
IFS=$old_SEP
227-
if [ "$value" ] && [ "$1" != "debug" ] && [ "$1" != "verbose" ]; then
228-
if [ "$global" == "true" ]; then
229-
print_verbose "Loaded argument $1:'$value'"
230-
fi
231-
fi
232-
}
233-
23484
fix_print_message()
23585
{
23686
msg="$(echo "$1"| sed -e 's/%/%%/g')"
@@ -738,18 +588,8 @@ git__setup()
738588
}
739589

740590
if [ ! "$include_loaded" ]; then
741-
declare -A ARGS
742-
743-
first_param="$3"
744-
shift
745-
parse_arguments ARGS $@
746-
747591
curr_dir="$(pwd)"
748592
namespace_filter="-A"
749-
750-
get_arg silent '--silent'
751-
get_arg verbose '--verbose'
752-
get_arg debug '--debug' "$verbose"
753593

754594
include_main
755595
fi

smud-cli/include_args.sh

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$_" = "/usr/bin/sh" ] || [ "$_" = "/bin/sh" ]; then
4+
echo "Native '$_' not supported here :-("
5+
echo "Please run this inside bash!"
6+
exit
7+
fi
8+
9+
parse_arguments()
10+
{
11+
local old_SEP=$IFS
12+
local -n parse_arguments_args="$1"
13+
# echo "0.str: $@"
14+
if [ $# -gt 0 ];then
15+
has_args="true"
16+
local str="$(echo " $@"|sed -e 's/--/-_sep_/g' |sed -e 's/ -/§/g')"
17+
# echo "str: $str"
18+
IFS="§"; read -ra array <<< " $str";
19+
local c=$(echo "${array[0]}" | grep '-' -c)
20+
if [ $c -eq 0 ]; then
21+
shift
22+
if [ $# -eq 0 ];then
23+
IFS=$old_SEP
24+
return
25+
fi
26+
local str="$(echo " $@"|sed -e 's/--/-_sep_/g' |sed -e 's/ -/§/g')"
27+
# echo "str: $str"
28+
IFS="§"; read -ra array <<< " $str";
29+
fi
30+
# echo "str: $str"
31+
# echo "array: ${array[@]}"
32+
for s in "${array[@]}"
33+
do
34+
# echo "0:s: $s"
35+
if [ ! "$s" ] || [ "$s" = " " ]; then
36+
continue
37+
fi
38+
local s="$(echo "$s"|xargs -d ' '| tr -d '\n')"
39+
# echo "s: $s"
40+
local s="$(echo "-$s" |sed -e 's/_sep_/-/g')"
41+
# echo "s: $s"
42+
arg=()
43+
if [ $(grep '=' -c <<< $s) -gt 0 ]; then
44+
IFS='='; read -ra arg <<< "$s"
45+
# echo "eq.arg: { key: ${arg[0]}, value: ${arg[1]} }"
46+
else
47+
IFS=' '; read -ra arg_ <<< "$s"
48+
arg[0]="${arg_[0]}"
49+
arg[1]="${arg_[@]:1}"
50+
# echo "space.arg: { key: ${arg[0]}, value: ${arg[1]} }"
51+
fi
52+
# echo "%%% ${arg[@]}"
53+
54+
local key="${arg[0]}"
55+
# echo "key: $key"
56+
if [ ! "$key" = "-n" ]; then
57+
local key="$(echo "${arg[0]}"|xargs -d ' '| tr -d '\n')"
58+
fi
59+
local value="${arg[1]}"
60+
# echo "key: $key, value: $value"
61+
62+
if [ ! "$value" ]; then
63+
local c=$(echo "$s" | grep ' ' -c)
64+
if [ $c -gt 0 ]; then
65+
IFS=' ';read -ra arg <<< "$s"
66+
local key="$(echo "${arg[0]}")"
67+
local value="$(echo "$s"|sed -e "s/$key //g"|xargs -d ' '| tr -d '\n')"
68+
fi
69+
fi
70+
local value="${value:-true}"
71+
if [ "$key" ]; then
72+
if [ "$key" != "-n" ]; then
73+
key="$(echo "$key"|sed -e "s/---/--/g"|xargs -d ' '| tr -d '\n')"
74+
fi
75+
if [ "$key" != "-" ]; then
76+
local value=$(echo "$value"|xargs -d ' '| tr -d '\n')
77+
old_value=${parse_arguments_args["$key"]}
78+
if [ "$old_value" != "$value" ]; then
79+
if [ "$old_value" ] && [ "$value" != "true" ]; then
80+
if [ ! "$argument_single_mode" ] && [ "$value" ]; then
81+
value="$old_value,$value"
82+
else
83+
value="$old_value"
84+
fi
85+
fi
86+
# if [ "$old_value" ]; then
87+
# print_gray "old_value: [$old_value], value: [$value]"
88+
# fi
89+
90+
parse_arguments_args["$key"]="$value"
91+
fi
92+
fi
93+
fi
94+
done
95+
fi
96+
97+
get_arg verbose '--verbose'
98+
if [ "$verbose" ]; then
99+
debug="true"
100+
for key in "${!parse_arguments_args[@]}";
101+
do
102+
key="${key}"
103+
value="${parse_arguments_args[${key}]}"
104+
done
105+
fi
106+
IFS=$old_SEP
107+
}
108+
109+
get_arg()
110+
{
111+
local -n value="$1"
112+
local old_SEP=$IFS
113+
local global="true"
114+
if [ "$4" ];then
115+
local -n get_arg_args="$4"
116+
fi
117+
118+
if [ "$5" ];then
119+
local global="$5"
120+
fi
121+
122+
if [ "$global" != "true" ]; then
123+
value=""
124+
fi
125+
126+
# echo "keys: $2"
127+
IFS=","; read -ra keys <<< "$2";
128+
for key in "${keys[@]}"
129+
do
130+
if [ ! "$key" = "-n" ]; then
131+
key="$(echo "$key"|xargs -d ' '| tr -d '\n')"
132+
fi
133+
key_value=""
134+
if [ ! "$4" ];then
135+
key_value="${ARGS[$key]}"
136+
else
137+
key_value="${get_arg_args[$key]}"
138+
fi
139+
if [ "$key_value" ]; then
140+
if [ ! "$argument_single_mode" ] && [ "$value" ] && [ "$value" != "true" ];then
141+
value="$value,$key_value"
142+
else
143+
value="$key_value"
144+
fi
145+
fi
146+
done
147+
148+
if [ ! "$value" ] && [ "$3" ]; then
149+
value="$3"
150+
fi
151+
IFS=$old_SEP
152+
if [ "$value" ] && [ "$1" != "debug" ] && [ "$1" != "verbose" ]; then
153+
if [ "$global" == "true" ]; then
154+
print_verbose_args "Loaded argument $1:'$value'"
155+
fi
156+
fi
157+
}
158+
print_verbose_args()
159+
{
160+
if [ "$verbose" ]; then
161+
if [ "$1" ]; then
162+
printf "\x1b[1;90m$1$(tput sgr0)\n"
163+
else
164+
echo ""
165+
fi
166+
fi
167+
}
168+
169+
if [ ! "$include_args_loaded" ]; then
170+
declare -A ARGS
171+
172+
first_param="$3"
173+
if [ "$startup_shift" ]; then
174+
shift
175+
fi
176+
177+
parse_arguments ARGS $@
178+
179+
get_arg silent '--silent'
180+
get_arg verbose '--verbose'
181+
get_arg debug '--debug' "$verbose"
182+
183+
IFS=$'\n'
184+
include_args_loaded="true"
185+
fi

smud-cli/install-cli.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,7 @@ if [ $HOMEDRIVE ] && [ -f $HOME_ABS_DIR/.bash_profile ]; then
7373
elif [ -f $HOME_ABS_DIR/.bashrc ]; then
7474
. ~/.bashrc
7575
fi
76-
76+
if [ -f "$DEST_DIR/smud.sh" ]; then
77+
chmod +x $DEST_DIR/smud.sh
78+
fi
7779
print_verbose "**** END: install-cli.sh"

smud-cli/smud-main.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#!/usr/bin/env bash
2+
3+
startup_shift="true"
4+
. $(dirname "$0")/include_args.sh "$@"
5+
26
if [ ! "$smud_main_loaded" ]; then
37

48
smud_main_loaded="true"

smud-cli/smud.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)