-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathv1-v2-refactor.sh
executable file
·115 lines (102 loc) · 2.68 KB
/
v1-v2-refactor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
# helper for refactoring to v2
ignores=(
CHANGELOG.md
v2-refactor.sh
tests/bats/tmp
common/lib/shell-helpers.sh
)
funcs=(
__error_code@__exit_code
__local_docker@docker/local
__local_docker_compose@docker/local-compose
__deactivate_machine@docker/deactivate-machine
clone_or_pull@git/clone_or_pull
docker_safe_name@docker/get/safe-name
error@die
error_noent@die/noent
error_perms@die/perms
error_exception@die/exception
fetch-url@network/fetch
get_cmd@get/cmd
get_group_id@get/gid_from_name
is_dirty@git/is/dirty
line_in_file@file/interpolate
log@p/log
normalize_flags@args/normalize
normalize_flags_first@args/normalize_flags_first
prompt_confirm@prompt/confirm
prompt_echo@prompt
runfunc@shell/execfn
set_cmd@_deprecated_
sed_inplace@file/sed_inplace
shell_detect@shell/detect
shell_eval_export@shell/evaluable_export
shell_eval_message@shell/evaluable_entrypoint
unrecognized_flag@args/unknown
unrecognized_arg@args/unknown
warn@p/warn
)
# p/prompt - prompt for input, useful for assigning variiable values
# usage: p/prompt <prompt message> [fallback value*]
# * uses fallback value if no input recieved or a tty is not available
# example:
# name=$(p/prompt "name to encrypt")
# port=$(p/prompt "port" 8080)
p/prompt(){
local input=
local prompt="${1:-value}"
local default="$2"
[ -z "$default" ] || prompt+=" [$default]"
while ((i++)) ; [ -z "$input" ]; do
if [ -t 0 ]; then
# user input
read -r -p " $prompt : " input </dev/tty
else
# piped input
read input
fi
[[ -n "$default" && -z "$input" ]] && input="$default"
[ -z "$input" ] && p/warn "invalid input"
done
echo "$input"
}
# p/prompt_confirm - pause before continuing
# usage: p/prompt_confirm [message]
# examples:
# p/prompt_confirm "really?" || exit 0
p/prompt_confirm() {
while true; do
case $(p/prompt "${@:-Continue?} [y/n]") in
[yY]) return 0 ;;
[nN]) return 1 ;;
*) p/warn "invalid input"
esac
done
}
p/notice(){
p/blockquote "\e[33m" "➜ " "$@" >&2
}
p/blockquote(){
local escape="$1" ; shift
local prefix="$1" ; shift
local indent="$(printf '%*s' ${#prefix})"
while [ $# -ne 0 ]; do
printf "$escape$prefix%b\n\e[0m" "$1"
prefix="$indent"
shift
done
}
for fn in "${funcs[@]}"; do
IFS="@" read -r fn replace <<< "$fn"
flags=
for ignore in "${ignores[@]}"; do
flags+=" --ignore $ignore"
done
p/notice "working with $fn [use $replace as replacement]"
ag $flags "$fn"
while p/prompt_confirm "re-print $fn matches (y) or continue (n)" ; do
p/notice "working with $fn [use $replace as replacement]"
ag $flags "$fn"
done
done