feat(riot): better help and fix option quite->quiet

This commit is contained in:
Dict Xiong 2026-08-13 14:28:36 +08:00
parent 8660bf2f02
commit aa5c2e86b6
No known key found for this signature in database
GPG Key ID: 7B97FAAC15EB0628
3 changed files with 103 additions and 21 deletions

View File

@ -427,21 +427,103 @@ remove_hostkey() {
# main # main
print_help() print_help()
{ {
fmt_info "usage: $0 [-Ddghlqt] [--dry-run] [--dev] [--gpg] [--help] [--lite] [--quite] [--trust] [--tmux] [--password] [[-o ssh-option]...] remote [command] [--] [command-args]" local pager=(cat)
cat <<EOF if [[ -t 1 ]] && command -v less > /dev/null 2>&1; then
options: pager=(less -R)
- -g, --gpg: forward the local GPG agent during an interactive SSH login (trusted remotes only) fi
available commands:
- ssh [ssh-command-args] (default) cat <<EOF | "${pager[@]}"
- tmux [ssh-command-args] (run ssh in multiple tmux windows) NAME
- git [git-command-args] (run git on remote machine) riot - connect to remote hosts using SSH presets
- sshl [local-port:remote-host:]remote-port (ssh -L)
- sshd [local-port] (ssh -D) SYNOPSIS
- zssh [ssh-command-args] ${0##*/} [OPTION]... REMOTE [COMMAND] [--] [COMMAND-ARG]...
- sftp
- scp source destination DESCRIPTION
- rm (remove host keys) Connect to REMOTE using the matching configuration from riot-config.sh.
- ping/ping4/ping6 (ping the remote servers) COMMAND defaults to ssh. Separate multiple remotes with commas and jump
hosts with slashes.
OPTIONS
-4
Force ssh to use IPv4 addresses only.
-6
Force ssh to use IPv6 addresses only.
-D, --dry-run
Print commands without executing them.
-d, --dev
Enable shell execution tracing.
-g, --gpg
Forward the local GPG agent during an interactive SSH login. Use only
with trusted remote hosts.
-h, --help
Display this help and exit.
-l, --lite
Enable dotfiles lite mode for loaded configuration.
-o SSH-OPTION
Pass an option to ssh. This option may be specified multiple times.
-p, --password
Use password authentication instead of public-key authentication.
-q, --quiet
Enable dotfiles quiet mode for loaded configuration.
-t, --trust
Trust the remote and enable X11 and SSH agent forwarding.
-v
Enable verbose ssh output.
--color
Force colored output.
--tmux
Open SSH sessions in tmux windows.
--
End option parsing.
COMMANDS
ssh [SSH-ARG]...
Open an SSH session. This is the default command.
tmux [SSH-ARG]...
Open SSH sessions in multiple tmux windows.
git [GIT-ARG]...
Run git on the remote host.
sshl [LOCAL-PORT:REMOTE-HOST:]REMOTE-PORT
Create local port forwarding with ssh -L.
sshr [REMOTE-HOST:]REMOTE-PORT
Create remote port forwarding with ssh -R.
sshd [LOCAL-PORT]
Create dynamic port forwarding with ssh -D.
zssh [SSH-ARG]...
Open a zssh session.
sftp [SFTP-ARG]...
Open an SFTP session.
scp SOURCE DESTINATION
Copy files to or from the remote host.
rm
Remove the remote host key from known_hosts.
ping, ping4, ping6
Ping the remote host.
EOF EOF
} }
@ -462,7 +544,7 @@ router() {
--tmux ) --tmux )
USE_TMUX=1 USE_TMUX=1
;; ;;
--password ) -p|--password )
EXTRA_SSH_OPTIONS+=("-o" "PasswordAuthentication=yes" "-o" "PubkeyAuthentication=no") EXTRA_SSH_OPTIONS+=("-o" "PasswordAuthentication=yes" "-o" "PubkeyAuthentication=no")
;; ;;
-o ) -o )

View File

@ -18,7 +18,7 @@ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
ARG="$1"; shift; ARG="$1"; shift;
fi fi
case $ARG in case $ARG in
-q*|--quite ) export DFS_QUIET=1 ;; -q*|--quiet ) export DFS_QUIET=1 ;;
-l*|--lite ) export DFS_LITE=1 ;; -l*|--lite ) export DFS_LITE=1 ;;
-d*|--dev ) export DFS_DEV=1; set -x ;; -d*|--dev ) export DFS_DEV=1; set -x ;;
-D*|--dry-run ) export DFS_DRY_RUN=1 ;; -D*|--dry-run ) export DFS_DRY_RUN=1 ;;

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex set -ex
OPTS='-a -bcl --color --arg1=1 --arg2 2 " 1 2" yes' OPTS='-a -bcl --color --quiet --arg1=1 --arg2 2 " 1 2" yes'
TARGET_OPTS='-a -b -c --arg1 1 --arg2 2 1 2 yes' TARGET_OPTS='-a -b -c --arg1 1 --arg2 2 1 2 yes'
eval set -- $OPTS eval set -- $OPTS
@ -8,14 +8,14 @@ THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/common.sh" source "$THIS_DIR/common.sh"
test "${GOT_OPTS[*]}" = "$TARGET_OPTS" test "${GOT_OPTS[*]}" = "$TARGET_OPTS"
test $# -eq 8 test $# -eq 9
test "$*" = "${OPTS//\"/}" test "$*" = "${OPTS//\"/}"
test "$DFS_LITE" = "1" test "$DFS_LITE" = "1"
is_tty is_tty
test -z "$DFS_QUIET" test "$DFS_QUIET" = "1"
set +x set +x
echo "test passed, args:" echo "test passed, args:"
for i in "${GOT_OPTS[@]}"; do for i in "${GOT_OPTS[@]}"; do
echo "$i" echo "$i"
done done