-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a utility library to handle argument processing since it is used by both hooks. Also put the logic for getting unique directory paths there since it makes sense to put that kind of functionality in a utility library.
- Loading branch information
Showing
3 changed files
with
72 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -o pipefail | ||
|
||
####################################### | ||
# Process the command line and separate arguments from files | ||
# Globals: | ||
# ARGS | ||
# FILES | ||
####################################### | ||
function util::parse_cmdline() { | ||
# Global variable arrays | ||
ARGS=() | ||
FILES=() | ||
|
||
while (("$#")); do | ||
case "$1" in | ||
-*) | ||
if [ -f "$1" ]; then | ||
FILES+=("$1") | ||
else | ||
ARGS+=("$1") | ||
fi | ||
shift | ||
;; | ||
*) | ||
FILES+=("$1") | ||
shift | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
####################################### | ||
# Create a list of unique directory paths from a list of file paths | ||
# Globals: | ||
# UNIQUE_PATHS | ||
####################################### | ||
function util::get_unique_directory_paths() { | ||
# Global variable arrays | ||
UNIQUE_PATHS=() | ||
|
||
local -a paths | ||
|
||
index=0 | ||
for file in "$@"; do | ||
paths[index]=$(dirname -- "$file") | ||
((++index)) | ||
done | ||
|
||
UNIQUE_PATHS=() | ||
while IFS='' read -r line; do UNIQUE_PATHS+=("$line"); done < <(printf '%s\n' "${paths[@]}" | sort --unique) | ||
} |