-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a46aab
commit 0658cb8
Showing
20 changed files
with
1,111 additions
and
69 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
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,88 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | ||
THIS_PROG="$0" | ||
SUBPROGRAM="ls" | ||
|
||
. "$DIR"/_utils.sh | ||
|
||
|
||
function show_help { | ||
cat <<-EOF | ||
USAGE: $THIS_PROG VERSION_NUMBER | ||
This script will fill all placeholder values in the lookatme me project. | ||
Specifically: | ||
* {{VERSION}} will be replaced with the version number (no 'v' prefix!) | ||
* {{LOOKATME_HELP_OUTPUT}} will be replaced with output from "lookatme --help" | ||
* {{LOOKATME_HELP_OUTPUT_INDENTED}} will be replaced with the indented | ||
output of "lookatme --help" | ||
EOF | ||
} | ||
|
||
function replace_in_files { | ||
local placeholder="$1" | ||
local replacement="$2" | ||
|
||
log "==== Replacing $placeholder" | ||
( | ||
cd "$DIR"/.. | ||
files_to_replace=$(grep -rl "$placeholder" $(git ls-files) | grep -v bin/fill_placeholders) | ||
python3 <(cat <<-EOF | ||
import sys | ||
placeholder = sys.argv[1] | ||
replacement = sys.argv[2] | ||
files_to_replace = sys.argv[3:] | ||
for file in files_to_replace: | ||
with open(file, "r") as f: | ||
data = f.read() | ||
new_data = data.replace(placeholder, replacement) | ||
if new_data != data: | ||
print(" replacing {}".format(file)) | ||
with open(file, "w") as f: | ||
f.write(new_data) | ||
EOF | ||
) "$placeholder" "$replacement" $files_to_replace | ||
) | ||
} | ||
|
||
function set_version { | ||
replace_in_files "{{VERSION}}" "$VERSION" | ||
} | ||
|
||
function set_help_output { | ||
local help_output=$(cd "$DIR"/.. ; python3 -m lookatme --help) | ||
replace_in_files "{{LOOKATME_HELP_OUTPUT}}" "$help_output" | ||
|
||
local help_output_indented=$(sed 's/^/ /' <<<$help_output) | ||
replace_in_files "{{LOOKATME_HELP_OUTPUT_INDENTED}}" "$help_output_indented" | ||
} | ||
|
||
|
||
function parse_args { | ||
VERSION="" | ||
while [ $# -ne 0 ] ; do | ||
param="$1" | ||
shift | ||
|
||
case "$param" in | ||
--help|-h) | ||
show_help | ||
exit 1 | ||
;; | ||
*) | ||
VERSION="$param" | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
parse_args "$@" | ||
# needs to come first, can contain {{VERSION}} placeholders | ||
set_help_output | ||
set_version |
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
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
Oops, something went wrong.