diff options
author | Andrew Cady <d@jerkface.net> | 2023-08-23 19:03:48 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-08-23 19:03:48 -0400 |
commit | 5f8d82c9078b3076d7009bd8aa98e10ea3ac70a3 (patch) | |
tree | 965b20e9a0bc9a3cd2a6c45b7c29d8187c7d1ff8 /src/rpc.main.bash | |
parent | 4f771eac3b737018c44e630d578683abb868846e (diff) |
split up rpc.bash into source-able library
Diffstat (limited to 'src/rpc.main.bash')
-rw-r--r-- | src/rpc.main.bash | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/rpc.main.bash b/src/rpc.main.bash new file mode 100644 index 0000000..b859509 --- /dev/null +++ b/src/rpc.main.bash | |||
@@ -0,0 +1,56 @@ | |||
1 | #!/usr/bin/bash -e | ||
2 | set -e | ||
3 | set -o pipefail | ||
4 | |||
5 | case "$0" in | ||
6 | [^/]* ) PATH=$(realpath -e "$(dirname "$BASH_SOURCE")"):$PATH ;; | ||
7 | esac | ||
8 | |||
9 | . rpc.bash | ||
10 | |||
11 | our_main() | ||
12 | { | ||
13 | REMOTE_DEST=localhost | ||
14 | main2 "$@" | ||
15 | main1 "$@" | ||
16 | } | ||
17 | |||
18 | main1() | ||
19 | { | ||
20 | remote_run_function fudge "$@" | ||
21 | } | ||
22 | |||
23 | main2() | ||
24 | { | ||
25 | funcs=$(find_local_only_functions "$@" </dev/null | xargs) | ||
26 | [ ! "$funcs" ] || printf 'Local-only functions (main2): %s\n' "$funcs" >&2 | ||
27 | } | ||
28 | |||
29 | find_local_only_functions() | ||
30 | { | ||
31 | intersection <(extract_words < "$BASH_SOURCE") \ | ||
32 | <(difference <(all_commands) \ | ||
33 | <(remote_run_function all_commands)) | ||
34 | } | ||
35 | |||
36 | all_commands() | ||
37 | { | ||
38 | : main2 | ||
39 | compgen -A command | sort -u | ||
40 | } | ||
41 | |||
42 | gudge() | ||
43 | { | ||
44 | echo "Hello, ${REPLY@Q}." | ||
45 | topic=${*@Q} | ||
46 | echo "Don't argue with me about ${topic:-punctuation}." | ||
47 | } | ||
48 | |||
49 | fudge() | ||
50 | { | ||
51 | read -p 'Name? ' && gudge "$@" | ||
52 | exit | ||
53 | } | ||
54 | |||
55 | our_main "$@" | ||
56 | |||