Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Completion: Add _log_priorities, _logger
- X-seq: zsh-workers 44883
- From: dana <dana@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Completion: Add _log_priorities, _logger
- Date: Fri, 1 Nov 2019 21:14:46 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=Ii4ga4s9zkyiUyNw8Lz8X2D64qdsGvwYpUofusR/Ytc=; b=J8TTNRk5/PCg7c4vemtakHz7KetLmkkSEd/DPEkR9Z+uKfCf6as+8NX/h7Ji1r5fab zqwKcn3D0wU5r5dbQ8RKrqV4Z5dLueniH1eo6qbtcqO+FTMJDv+ZfdiYfOAtwJCnNKyj kFw+fpTcR6oG3JSEcJ12owmWHKwdNu/dXO82RlD0TtUQL1MMROHpmovWa/wyXVCHfRdp K8MCzS6FvYxfx+iRNfXH5CWZpYVVFhIRKA0TJ2rwl7n6+MAy0xPSpgGMVCuOQkbmVXSP X214YWg4V2HgqCpScwScmfkUzQWJq2cPTSpZQ1LupH6srtPWtkqHwDkURPt8DJ3cCx7h VpuQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
This patch does the following:
* Adds a new type function called _log_priorities, which completes
syslog-style facilities and severity levels
* Updates the four functions i found that already take syslog priorities to
use _log_priorities
* Adds a new function for the logger utility (which also uses _log_priorities
obv)
I tried to make _log_priorities featureful enough to suit all of the obvious
use cases i could think of; let me know if it seems weird though. (The strange
option letters were, as with _bind_addresses, chosen to avoid conflicting with
compadd. Daniel once suggested that we come up with some standard calling
convention that resolves this head ache, but i haven't personally given it
much further thought)
This is also another case where i needed a host-with-port utility function
that properly handles IPv6 bracket syntax. I mentioned that i was working on
that a while ago, but i had trouble coming up with a good generalised API.
Might revisit some day
dana
diff --git a/Completion/Unix/Type/_log_priorities b/Completion/Unix/Type/_log_priorities
new file mode 100644
index 000000000..42cf485dc
--- /dev/null
+++ b/Completion/Unix/Type/_log_priorities
@@ -0,0 +1,70 @@
+#autoload
+
+# Complete syslog-style priorities/facilities/levels
+#
+# Note: 'Priority' according to syslog(3) refers to a severity level optionally
+# ORed with a facility. We use it here in a somewhat similar manner, as this
+# seems to cover the most ground, though we also support completing facilities
+# alone.
+#
+# By default, a case-insensitive facility.level pair is completed.
+#
+# Some tools that accept symbolic facility/level names also accept numbers
+# corresponding to their associated values defined in syslog.h. Since these
+# numbers vary across systems, we don't attempt to complete them.
+#
+# Options:
+# -y Complete only facilities
+# -Y Complete only severity levels
+# -z Complete only lower-case names
+# -Z Complete only upper-case names
+
+local -a expl facilities levels ca_opts
+local -A opts
+
+# Facilities vary across systems too, but these seem common enough
+facilities=(
+ kern
+ user
+ mail
+ daemon
+ auth
+ syslog
+ lpr
+ news
+ uucp
+ cron
+ authpriv
+ ftp
+ ntp
+ security
+ local{0..7}
+)
+levels=(
+ emerg # 'panic' is deprecated
+ alert
+ crit
+ err # 'error' is deprecated
+ warning # 'warn' is deprecated
+ notice
+ info
+ debug
+)
+
+zparseopts -A opts -D -E -- y Y z Z
+
+if (( $+opts[-Z] )); then
+ facilities=( ${(@U)facilities} )
+ levels=( ${(@U)levels} )
+elif (( ! $+opts[-z] )); then
+ ca_opts+=( -M 'm:{a-zA-Z}={A-Za-z}' )
+fi
+
+if (( $+opts[-Y] )) || { (( ! $+opts[-y] )) && compset -P '[^.]##.' }; then
+ _wanted levels expl 'log severity level' \
+ compadd -a "$@" "${(@)ca_opts}" - levels
+else
+ (( ! $+opts[-y] )) && ! compset -S '.[^.]##' && ca_opts+=( -qS. )
+ _wanted facilities expl 'log facility' \
+ compadd -a "$@" "${(@)ca_opts}" - facilities
+fi
diff --git a/Completion/BSD/Command/_pfctl b/Completion/BSD/Command/_pfctl
index 23898882f..a2a81b5db 100644
--- a/Completion/BSD/Command/_pfctl
+++ b/Completion/BSD/Command/_pfctl
@@ -58,9 +58,7 @@ _pf_tables() {
case $OSTYPE in
openbsd*)
- pfctl_debug_level=(
- emerg alert crit err warning notice info debug
- )
+ _log_priorities -Y -O pfctl_debug_level
args=(
'-L+[load pf states from specified state file]:file:_files'
"-N[don't perform domain name resolution]"
diff --git a/Completion/Linux/Command/_iptables b/Completion/Linux/Command/_iptables
index 27c801da1..d4d678579 100644
--- a/Completion/Linux/Command/_iptables
+++ b/Completion/Linux/Command/_iptables
@@ -57,7 +57,7 @@ case ${prev[${prev[(I)-j|--jump]}+1]}; in
ECN) args+=( '--ecn-tcp-remove[remove all ECN bits from TCP header]' ) ;;
LOG)
args+=(
- '--log-level[specify level of logging]:log level:(debug info notice warning err crit alert emerg)'
+ '--log-level[specify level of logging]: :_log_priorities -Y'
'--log-prefix[specify prefix string for log message]:string'
'--log-tcp-sequence[log TCP sequence numbers]'
'--log-tcp-options[log TCP options]'
diff --git a/Completion/Unix/Command/_rclone b/Completion/Unix/Command/_rclone
index 01d851fa1..698a94772 100644
--- a/Completion/Unix/Command/_rclone
+++ b/Completion/Unix/Command/_rclone
@@ -147,7 +147,7 @@ _arguments -C \
'--streaming-upload-cutoff[specify size cutoff for switching to chunked upload]:size [100k]' \
'--suffix[specify suffix for use with --backup-dir]:string' \
'--syslog[use syslog for logging]' \
- '--syslog-facility[facility for syslog, eg KERN,USER,...]:string [DAEMON]' \
+ '--syslog-facility[specify syslog facility]:log facility [DAEMON]:_log_priorities -yZ' \
'--timeout[specify IO idle timeout]:duration [5m0s]' \
'--tpslimit[limit HTTP transactions per second to this]:float' \
'--tpslimit-burst[max burst of transactions for --tpslimit]:int [1]' \
diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh
index 0775590e6..cc7ed563c 100644
--- a/Completion/Unix/Command/_ssh
+++ b/Completion/Unix/Command/_ssh
@@ -441,7 +441,7 @@ _ssh () {
_wanted values expl 'value' compadd yes no ask accept-new off && ret=0
;;
(#i)syslogfacility=*)
- _wanted facilities expl 'facility' compadd -M 'm:{a-z}={A-Z}' DAEMON USER AUTH LOCAL{0,1,2,3,4,5,6,7} && ret=0
+ _log_priorities -y && ret=0
;;
(#i)(verifyhostkeydns|updatehostkeys)=*)
_wanted values expl 'truthish value' compadd yes no ask && ret=0
diff --git a/Completion/Unix/Command/_logger b/Completion/Unix/Command/_logger
new file mode 100644
index 000000000..180e35b89
--- /dev/null
+++ b/Completion/Unix/Command/_logger
@@ -0,0 +1,93 @@
+#compdef logger
+
+local variant
+local -a args aopts=( -A '-*' )
+
+_pick_variant -r variant util-linux=util-linux $OSTYPE --version
+
+case $variant in
+ *)
+ args+=(
+ '(-f -e --file --journald --prio-prefix --skip-empty)*: :_guard "^-*" message'
+ '(: * --journald)'{-f+,--file=}'[log contents of specified file]: :_files'
+ '(--id)-i[log with PID of logger process]'
+ '(-p --priority)'{-p+,--priority=}'[log with specified priority]: :_log_priorities'
+ '(-t --tag)'{-t+,--tag=}'[log with specified tag]:tag'
+ )
+ ;|
+ darwin*|dragonfly*|freebsd*|linux*|netbsd*|openbsd*)
+ args+=(
+ '(-s --stderr)'{-s,--stderr}'[also log to stderr (LOG_PERROR)]'
+ )
+ ;|
+ netbsd*|openbsd*)
+ args+=(
+ '-c[log to console if unable to log normally (LOG_CONS)]'
+ )
+ ;|
+ dragonfly*|freebsd*)
+ args+=(
+ '(-6)-4[log via IPv4 only]'
+ '(-4)-6[log via IPv6 only]'
+ '-A[log to all IP addresses associated with remote host name]'
+ # @todo Complete UNIX-domain sockets
+ '-h+[log to specified remote host or UNIX-domain socket]:remote syslog host:_hosts'
+ )
+ ;|
+ freebsd*)
+ args+=(
+ '-H+[specify host name for message header]: :_hosts'
+ '-P+[log to specified port (with -h)]:remote syslog port:_ports'
+ # @todo This is another case where we need a dedicated _hosts_ports
+ # function which can properly handle bracketed IPv6 address syntax
+ '-S+[specify source address/port (with -h)]: :_bind_addresses -0bh'
+ )
+ ;;
+ netbsd*)
+ args+=(
+ '-d+[log specified structured data]:structured data'
+ '-m+[specify RFC5424 MSGID]:MSGID'
+ '-n[open log connection immediately (LOG_NDELAY)]'
+ )
+ ;;
+ util-linux)
+ aopts=( )
+ args+=(
+ '(-d -T --tcp --udp)'{-d,--udp}'[log via UDP only (with -n)]'
+ '(: * -e --skip-empty)'{-e,--skip-empty}'[ignore empty lines in input (with -f or stdin)]'
+ '(-i)--id=-[log with PID of logger process or specified PID]:: :_pids'
+ '(--rfc3164)--msgid=[specify RFC5424 MSGID]:MSGID'
+ '(-n --server)'{-n+,--server=}'[log to specified remote host]:remote syslog host:_hosts'
+ '--no-act[do not actually log]'
+ '--octet-count[use RFC6587 octet counting]'
+ '(-P --port)'{-P+,--port=}'[log to specified port (with -n)]:remote syslog port:_ports'
+ '(: *)--prio-prefix[look for priority prefix <n> on each line (with -f or stdin)]'
+ '(--msgid --rfc5424 --sd-id --sd-param)--rfc3164[use RFC3164 BSD syslog protocol]'
+ '(--rfc3164)--rfc5424=-[use RFC5424 syslog protocol with optional exceptions]:protocol exceptions:((
+ nohost\:"suppress gethostname(2) information"
+ notime\:"suppress complete sender time stamp (implies notq)"
+ notq\:"suppress time-quality structured data"
+ ))'
+ # @todo We could do a better job of completing these next two. The
+ # util-linux man page describes the format and some of the known values.
+ # Also, this is one of those cases where the options have to be given in
+ # order, i.e., each --sd-param must be preceded by --sd-id and vice versa
+ '(--rfc3164)*--sd-id=[specify RFC5424 structured-data element ID]:structured-data element ID'
+ '(--rfc3164)*--sd-param=[specify RFC5424 structured-data element parameter]:structured-data element parameter (name=value)'
+ '--size=[specify maximum message size]:message size (bytes)'
+ '--socket-errors=-[specify socket error-printing behavior]:mode::(auto off on)'
+ '(-u --socket)'{-u+,--socket=}'[write to specified socket instead of default]:syslog socket:_files -g "*(-=D)"'
+ '(-d -T --tcp --udp)'{-t,--tcp}'[log via TCP only (with -n)]'
+ '(: * -)'{-V,--version}'[display version information]'
+ '(: * -)'{-h,--help}'[display help information]'
+ )
+ # This option actually ignores many other options, like -p
+ (( $+commands[journalctl] )) && args+=(
+ '(: * -f --file)--journald=-[log systemd journal entry from stdin or specified file]: ::_files'
+ )
+ ;;
+esac
+
+[[ $variant == util-linux ]] || args=( ${args:#(\([^\)]#\)|)(\*|)--*} )
+
+_arguments -s -S $aopts : $args
Messages sorted by:
Reverse Date,
Date,
Thread,
Author