Skip to content

Commit 42b4c61

Browse files
devydevy
authored andcommitted
add has_flag function
1 parent db6c0e8 commit 42b4c61

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

functions/index.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source $dotfile_dir/functions/shared/validators.sh
33

44
source $dotfile_dir/functions/shared/join_args.sh
5+
source $dotfile_dir/functions/shared/has_flag.sh
56

67
# Barrel file for functions
78
source $dotfile_dir/functions/localhost.sh

functions/shared/has_flag.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Helper function to determine if a bash function contains a flag
2+
has_flag() {
3+
local flag="$1"
4+
shift
5+
6+
for arg in "$@"; do
7+
if [ "$arg" = "$flag" ]; then
8+
return 0 # found
9+
fi
10+
done
11+
12+
return 1 # not found
13+
}
14+
15+
# Helper function to strip flags from args
16+
strip_flags() {
17+
local result=()
18+
19+
for arg in "$@"; do
20+
if [[ "$arg" != -* ]]; then
21+
result+=("$arg")
22+
fi
23+
done
24+
25+
echo "${result[@]}"
26+
}

0 commit comments

Comments
 (0)