Skip to content

Commit c74c521

Browse files
Add support for new environment argument 'RSC_HELP_URL'
1 parent 99ab2e4 commit c74c521

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## Version (development version)
22

3-
* ...
3+
### New Features
4+
5+
* Add new environment argument `RSC_HELP_URL`, which if set will be
6+
mentioned in the `--help` output as well as being appended to any
7+
error messages produced.
48

59

610
## Version 0.17.0 [2024-11-10]

bin/rsc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
### rsc reset --force
7676
### rsc reset --which=sessions
7777
###
78-
### Version: 0.17.0-9000
78+
### {{SEE_ALSO}}
79+
###
80+
### Version: 0.17.0-9002
7981
### Copyright: Henrik Bengtsson (2022-2024) and Harry Putnam (2022)
8082
### License: ISC
8183

@@ -135,7 +137,10 @@ function rsc_error {
135137
if [[ -n ${extra} ]]; then
136138
msg="${msg} ${extra}"
137139
fi
138-
error "$msg"
140+
if [[ -n ${RSC_HELP_URL} ]]; then
141+
msg="${msg} See also <${RSC_HELP_URL}>, which may have additional details on and suggestions how to solve this."
142+
fi
143+
error "${msg}"
139144
}
140145

141146
# -------------------------------------------------------------------------
@@ -293,7 +298,7 @@ function acquire_lock_file {
293298
if [[ -f "${lockfile}" ]]; then
294299
msg="${USER}, another RStudio Server instance of yours is already running on $(rserver_hostname) on this system. Call '${blue}rsc status --full${undo}' for details on how to reconnect. If you want to start a new instance, please terminate the existing one first by calling '${blue}rsc stop${undo}' from that machine."
295300
msg="${msg} As a last resort, for instance, if that machine is no longer available or down for maintenance, try ${blue}rsc reset --force${undo}."
296-
error "${msg}"
301+
rsc_error "${msg}"
297302
fi
298303
echo "${PPID}" > "${lockfile}"
299304
assert_file_is_not_empty "${lockfile}"
@@ -575,7 +580,7 @@ function check_pid {
575580
if [[ ${okay} -ne 0 ]]; then
576581
## Remove empty leading lines
577582
res=$(sed -e '/./,$!d' <<< "${res}")
578-
error "Failed to check process PID ${pid} on ${hostname} over SSH. Reason was: ${res}"
583+
rsc_error "Failed to check process PID ${pid} on ${hostname} over SSH. Reason was: ${res}"
579584
fi
580585
[[ "${res}" == "true" ]] && pid_exists=true
581586
else
@@ -961,7 +966,7 @@ function assert_no_rsession {
961966
if [[ $(rserver_status) == "not running" ]]; then
962967
error "Detected stray 'rsession' processes. Use 'rsc stop' to terminate them"
963968
else
964-
error "[INTERNAL] Detected unexpected 'rsession' processes"
969+
rsc_error "[INTERNAL] Detected unexpected 'rsession' processes"
965970
fi
966971
fi
967972

@@ -1483,6 +1488,18 @@ function display_access_instructions {
14831488
message "\n${msg}"
14841489
}
14851490

1491+
function rsc_help {
1492+
local -a bfr
1493+
mapfile -t bfr < <(help "${@}")
1494+
if grep -q -F "{{SEE_ALSO}}" <<< "${bfr[@]}"; then
1495+
if [[ -n ${RSC_HELP_URL} ]]; then
1496+
mapfile -t bfr < <(printf "%s\n" "${bfr[@]}" | sed "s/{{SEE_ALSO}}/See also:\n * ${RSC_HELP_URL}/")
1497+
else
1498+
mapfile -t bfr < <(printf "%s\n" "${bfr[@]}" | sed "/{{SEE_ALSO}}/{ N; d }")
1499+
fi
1500+
fi
1501+
printf "%s\n" "${bfr[@]}"
1502+
}
14861503

14871504
# =========================================================================
14881505
# MAIN
@@ -1622,10 +1639,10 @@ done
16221639

16231640
## --help should always be available prior to any validation errors
16241641
if [[ -z $action ]]; then
1625-
help
1642+
rsc_help
16261643
_exit 0
16271644
elif [[ $action == "help" ]]; then
1628-
help full
1645+
rsc_help full
16291646
_exit 0
16301647
elif [[ $action == "version" ]]; then
16311648
if $full; then
@@ -1882,7 +1899,7 @@ elif [[ "${action}" == "stop" ]]; then
18821899
## If running, make sure we're stopping from the correct machine
18831900
if [[ -f "${lockfile}" ]] && [[ "$(hostname)" != "$(rserver_hostname)" ]]; then
18841901
file="${workdir}/rserver.hostname"
1885-
error "Stopping the RStudio Server can only be made from the machine ($(rserver_hostname)) where it was started from - not from $(hostname) [${file}: $(file_info "${file}")]"
1902+
rsc_error "Stopping the RStudio Server can only be made from the machine ($(rserver_hostname)) where it was started from - not from $(hostname) [${file}: $(file_info "${file}")]"
18861903
fi
18871904

18881905
## Terminate rsession
@@ -2006,7 +2023,7 @@ elif [[ "${action}" == "start" ]]; then
20062023
secure_dir
20072024

20082025
rs_pid="$(rserver_pid)"
2009-
[[ -z "${rs_pid}" ]] && error "RStudio Server failed to start for unknown reasons. One reason for this might be that the port (${port}) is already occupied"
2026+
[[ -z "${rs_pid}" ]] && rsc_error "RStudio Server failed to start for unknown reasons. One reason for this might be that the port (${port}) is already occupied"
20102027
pids=("${rs_pid}")
20112028

20122029
## Update 'port', in case it 'port4me' was used
@@ -2015,7 +2032,7 @@ elif [[ "${action}" == "start" ]]; then
20152032
## Launch rserver monitor
20162033
launch_rserver_monitor
20172034
pid="$(rserver_monitor_pid)"
2018-
[[ -z "${pid}" ]] && error "rserver monitor failed to start for unknown reasons"
2035+
[[ -z "${pid}" ]] && rsc_error "rserver monitor failed to start for unknown reasons"
20192036
pids=("${pid}")
20202037

20212038
## Launch reverse SSH tunnel?

0 commit comments

Comments
 (0)