File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 4
4
set -e
5
5
6
6
source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /os.sh"
7
+ source " $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /string.sh"
7
8
8
9
# Returns true (0) if the given file exists and is a file and false (1) otherwise
9
10
function file_exists {
@@ -63,3 +64,21 @@ function file_replace_or_append_text {
63
64
file_append_text " $replacement_text " " $file "
64
65
fi
65
66
}
67
+
68
+ # Replace a specific template string in a file with a value. Provided as an array of TEMPLATE-STRING=VALUE
69
+ function file_fill_template {
70
+ local -r file=" $1 "
71
+ shift 1
72
+ local -ar auto_fill=(" $@ " )
73
+
74
+ if [[ -z " ${auto_fill[@]} " ]]; then
75
+ log_info " No auto-fill params specified."
76
+ return
77
+ fi
78
+
79
+ for param in " ${auto_fill[@]} " ; do
80
+ local -r name=" $( string_strip_suffix " $param " " =*" ) "
81
+ local -r value=" $( string_strip_prefix " $param " " *=" ) "
82
+ file_replace_text " $name " " $value " " $file "
83
+ done
84
+ }
You can’t perform that action at this time.
0 commit comments