From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id a4f252db for ; Sat, 2 Nov 2019 02:15:35 +0000 (UTC) Received: (qmail 13857 invoked by alias); 2 Nov 2019 02:15:25 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44883 Received: (qmail 13983 invoked by uid 1010); 2 Nov 2019 02:15:25 -0000 X-Qmail-Scanner-Diagnostics: from mail-yw1-f68.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25615. spamassassin: 3.4.2. Clear:RC:0(209.85.161.68):SA:0(-1.9/5.0):. Processed in 2.073852 secs); 02 Nov 2019 02:15:25 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.161.68 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=Ii4ga4s9zkyiUyNw8Lz8X2D64qdsGvwYpUofusR/Ytc=; b=IBWutAFkdEJspyIL1di1CLnX4ZvoIdIUzmq8AEN2IMg+4qLnD6vbEljYbPTFnv0Ace WEPDPdXEFcA6GvHBdOY3/fdkWnrFhBq0aZnw2UD9p09ZQN6vYxhBWi9+dASIVYLr5HPk /GrLHgTPIWy+ojiblx4RMmPWZqAzcRdO/nBav2P0iNYr8DrFnS9xJeGOW9qN2vANfIiq EWtNfgf5s5lhYQmyYDhC4jC80T8jR51elyIIknEJVEceK7+b7zgTg7OO1ls3jtmfzRb5 or66yfwwDV+5W11fFJUAdgmAwPhCxI0jS634VhDnzy6rtHOs7BMGIFXa80qltaClPAsD WrQw== X-Gm-Message-State: APjAAAXXH9we/rkHvFLpyZbcwvrDJJiSvLBx1GNgiZczL5JiU5eZEnWk YsuQrIOpqEg4VLk4L94/1DlIBeD1lZ49zA== X-Google-Smtp-Source: APXvYqzxd2UuJF7QK1XJSuXlPEKn9VFtRX9iEc+23EPbc60/7jyF+yIAX5DqAjK0IlyqaIlk4Sh82A== X-Received: by 2002:a0d:f8c4:: with SMTP id i187mr11340290ywf.122.1572660888236; Fri, 01 Nov 2019 19:14:48 -0700 (PDT) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [PATCH] Completion: Add _log_priorities, _logger Message-Id: Date: Fri, 1 Nov 2019 21:14:46 -0500 To: Zsh hackers list X-Mailer: Apple Mail (2.3445.104.11) 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=3D( + kern + user + mail + daemon + auth + syslog + lpr + news + uucp + cron + authpriv + ftp + ntp + security + local{0..7} +) +levels=3D( + 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=3D( ${(@U)facilities} ) + levels=3D( ${(@U)levels} ) +elif (( ! $+opts[-z] )); then + ca_opts+=3D( -M 'm:{a-zA-Z}=3D{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+=3D( -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() { =20 case $OSTYPE in openbsd*) - pfctl_debug_level=3D( - emerg alert crit err warning notice info debug - ) + _log_priorities -Y -O pfctl_debug_level args=3D( '-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+=3D( '--ecn-tcp-remove[remove all ECN bits from TCP = header]' ) ;; LOG) args+=3D( - '--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=3D0 ;; (#i)syslogfacility=3D*) - _wanted facilities expl 'facility' compadd -M 'm:{a-z}=3D{A-Z}'= DAEMON USER AUTH LOCAL{0,1,2,3,4,5,6,7} && ret=3D0 + _log_priorities -y && ret=3D0 ;; (#i)(verifyhostkeydns|updatehostkeys)=3D*) _wanted values expl 'truthish value' compadd yes no ask && = ret=3D0 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=3D( -A '-*' ) + +_pick_variant -r variant util-linux=3Dutil-linux $OSTYPE --version + +case $variant in + *) + args+=3D( + '(-f -e --file --journald --prio-prefix --skip-empty)*: :_guard = "^-*" message' + '(: * --journald)'{-f+,--file=3D}'[log contents of specified = file]: :_files' + '(--id)-i[log with PID of logger process]' + '(-p --priority)'{-p+,--priority=3D}'[log with specified = priority]: :_log_priorities' + '(-t --tag)'{-t+,--tag=3D}'[log with specified tag]:tag' + ) + ;| + darwin*|dragonfly*|freebsd*|linux*|netbsd*|openbsd*) + args+=3D( + '(-s --stderr)'{-s,--stderr}'[also log to stderr (LOG_PERROR)]' + ) + ;| + netbsd*|openbsd*) + args+=3D( + '-c[log to console if unable to log normally (LOG_CONS)]' + ) + ;| + dragonfly*|freebsd*) + args+=3D( + '(-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+=3D( + '-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+=3D( + '-d+[log specified structured data]:structured data' + '-m+[specify RFC5424 MSGID]:MSGID' + '-n[open log connection immediately (LOG_NDELAY)]' + ) + ;; + util-linux) + aopts=3D( ) + args+=3D( + '(-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=3D-[log with PID of logger process or specified PID]:: = :_pids' + '(--rfc3164)--msgid=3D[specify RFC5424 MSGID]:MSGID' + '(-n --server)'{-n+,--server=3D}'[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=3D}'[log to specified port (with = -n)]:remote syslog port:_ports' + '(: *)--prio-prefix[look for priority prefix on each line = (with -f or stdin)]' + '(--msgid --rfc5424 --sd-id --sd-param)--rfc3164[use RFC3164 BSD = syslog protocol]' + '(--rfc3164)--rfc5424=3D-[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=3D[specify RFC5424 structured-data element = ID]:structured-data element ID' + '(--rfc3164)*--sd-param=3D[specify RFC5424 structured-data = element parameter]:structured-data element parameter (name=3Dvalue)' + '--size=3D[specify maximum message size]:message size (bytes)' + '--socket-errors=3D-[specify socket error-printing = behavior]:mode::(auto off on)' + '(-u --socket)'{-u+,--socket=3D}'[write to specified socket = instead of default]:syslog socket:_files -g "*(-=3DD)"' + '(-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+=3D( + '(: * -f --file)--journald=3D-[log systemd journal entry from = stdin or specified file]: ::_files' + ) + ;; +esac + +[[ $variant =3D=3D util-linux ]] || args=3D( = ${args:#(\([^\)]#\)|)(\*|)--*} ) + +_arguments -s -S $aopts : $args