zsh-workers
 help / color / mirror / code / Atom feed
From: Marlon Richert <marlon.richert@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: "Lawrence Velázquez" <larryv@zsh.org>,
	"Zsh hackers list" <zsh-workers@zsh.org>
Subject: Re: Let run-help filter cmd_args before calling run-help-<command> (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
Date: Thu, 29 Jul 2021 15:11:16 +0300	[thread overview]
Message-ID: <CAHLkEDu7+k=f=B=A0uLWTj0676VYM9fM_=RcB0e2sgeHPeULoA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7bui37NHJLqSHDdbZwSEWZVD68aU3ReE6Z0wQ7hnOVZvw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1370 bytes --]

On Wed, Jul 28, 2021 at 8:58 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Sun, Jul 18, 2021 at 11:46 AM Lawrence Velázquez <larryv@zsh.org> wrote:
> >
> > On Sun, Jun 20, 2021, at 2:01 PM, Lawrence Velázquez wrote:
> > > On Sat, Jun 5, 2021, at 3:15 PM, Marlon Richert wrote:
> > > > New patch here with test cases, plus a rewrite of run-help-git. All the
> > > > tests succeed for both the new and old versions of the run-help-*
> > > > functions (except for the old run-help-git, because the new
> > > > run-help-git uses `git help` instead of `man`).
> > > >
> > > > Attachments:
> > > > * 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt
> > >
> > > bump
> >
> > bump bump
>
> Nothing obviously wrong with the code patch, but one of the test cases
> fails for me:
>
> --- /tmp/zsh.ztst.50384/ztst.out    2021-07-28 10:56:06.301935368 -0700
> +++ /tmp/zsh.ztst.50384/ztst.tout    2021-07-28 10:56:06.301935368 -0700
> @@ -1,2 +0,0 @@
> -git is WHENCE:{git}
> -GIT:{'help' 'git'}
> Test ./Z03run-help.ztst failed: output differs from expected as shown above for:
>   BUFFER_STACK='git --exec-path'
> Was testing: git with option
> ./Z03run-help.ztst: test failed.

Looks like I somehow managed to omit some lines from the tests in the
patch. Here's a new patch, differing only in the `run-help git` tests:

[-- Attachment #2: 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt --]
[-- Type: text/plain, Size: 5907 bytes --]

From 673123be01b29518921a054aacdcaa4811285473 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Thu, 29 Jul 2021 15:08:11 +0300
Subject: [PATCH] Let run-help filter $cmd_args before calling
 run-help-<command>

---
 Functions/Misc/run-help       |  15 +++--
 Functions/Misc/run-help-btrfs |   4 --
 Functions/Misc/run-help-git   |  10 +---
 Functions/Misc/run-help-ip    |   4 --
 Functions/Misc/run-help-p4    |   2 +-
 Functions/Misc/run-help-svk   |   2 +-
 Functions/Misc/run-help-svn   |   2 +-
 Test/Z03run-help.ztst         | 106 ++++++++++++++++++++++++++++++++++
 8 files changed, 119 insertions(+), 26 deletions(-)
 create mode 100644 Test/Z03run-help.ztst

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..d52c1b032 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -101,12 +101,15 @@ do
 		builtin getln cmd_args
 		builtin print -z "$cmd_args"
 		cmd_args=( ${(z)cmd_args} )
-		# Discard environment assignments, etc.
-		while [[ $cmd_args[1] != ${run_help_orig_cmd:-$1} ]]
-		do
-		    shift cmd_args || return 1
-		done
-		eval "run-help-$1:t ${(q@)cmd_args[2,-1]}"
+
+                # Discard the command itself & everything before it.
+                shift $cmd_args[(i)${run_help_orig_cmd:-$1}] cmd_args ||
+                    return
+
+                # Discard options, parameter assignments & paths.
+                cmd_args=( ${cmd_args[@]:#([-+]*|*=*|*/*|\~*)} )
+
+                eval "run-help-$1:t ${(@q)cmd_args}"
 	    else
 		POSIXLY_CORRECT=1 man $@:t
 	    fi
diff --git a/Functions/Misc/run-help-btrfs b/Functions/Misc/run-help-btrfs
index 0dc1dabcb..cb139e9b7 100644
--- a/Functions/Misc/run-help-btrfs
+++ b/Functions/Misc/run-help-btrfs
@@ -1,7 +1,3 @@
-while [[ $# != 0 && $1 == -* ]]; do
-    shift
-done
-
 case $1 in
     (b*)    man btrfs-balance          ;;
     (c*)    man btrfs-check            ;;
diff --git a/Functions/Misc/run-help-git b/Functions/Misc/run-help-git
index ce94d0d02..a841f89d6 100644
--- a/Functions/Misc/run-help-git
+++ b/Functions/Misc/run-help-git
@@ -1,9 +1 @@
-if [ $# -eq 0 ]; then
-    man git
-else
-    local al
-    if al=$(git config --get "alias.$1"); then
-        1=${al%% *}
-    fi
-    man git-$1
-fi
+git help ${1:-git}
diff --git a/Functions/Misc/run-help-ip b/Functions/Misc/run-help-ip
index 8807f9ef1..b811ce352 100644
--- a/Functions/Misc/run-help-ip
+++ b/Functions/Misc/run-help-ip
@@ -14,10 +14,6 @@ if ! man -w ip-address >/dev/null 2>&1; then
     return
 fi
 
-while [[ $# != 0 && $1 == -* ]]; do
-    shift
-done
-
 case $1 in
     (addrl*) man ip-addrlabel ;;
     (a*) man ip-address ;;
diff --git a/Functions/Misc/run-help-p4 b/Functions/Misc/run-help-p4
index 662ce94fe..e48a4d068 100644
--- a/Functions/Misc/run-help-p4
+++ b/Functions/Misc/run-help-p4
@@ -2,4 +2,4 @@ if (( ! $# )); then
   p4 help commands
 else
   p4 help $1
-fi | ${=PAGER:-less}
+fi | ${=PAGER:-more}
diff --git a/Functions/Misc/run-help-svk b/Functions/Misc/run-help-svk
index 92438a53f..782538246 100644
--- a/Functions/Misc/run-help-svk
+++ b/Functions/Misc/run-help-svk
@@ -1 +1 @@
-svk help ${${@:#-*}[1]} | ${=PAGER:-more}
+svk help $1 | ${=PAGER:-more}
diff --git a/Functions/Misc/run-help-svn b/Functions/Misc/run-help-svn
index 5d1068588..d55a493a6 100644
--- a/Functions/Misc/run-help-svn
+++ b/Functions/Misc/run-help-svn
@@ -1 +1 @@
-svn help ${${@:#-*}[1]} | ${=PAGER:-more}
+svn help $1 | ${=PAGER:-more}
diff --git a/Test/Z03run-help.ztst b/Test/Z03run-help.ztst
new file mode 100644
index 000000000..2bb3bceed
--- /dev/null
+++ b/Test/Z03run-help.ztst
@@ -0,0 +1,106 @@
+%prep
+  PAGER=cat
+  unalias run-help
+  autoload +X -Uz $PWD/../Functions/Misc/run-help*
+  builtin() {
+    case "$1 $2" in
+      ( 'getln cmd_args' )
+        cmd_args="$BUFFER_STACK"
+      ;;
+      ( 'print -z' )
+      ;;
+      ( 'whence -va' )
+        print -l "$3 is WHENCE:{$3}"
+      ;;
+      ( * )
+        eval $@
+      ;;
+    esac
+  }
+  man() {
+    [[ $1 == -w && -n $NO_SUBCMD_MANUALS ]] &&
+        return 1
+    print "MAN:{${(qq)@}}"
+  }
+  git svn () {
+    print "${(U)0}:{${(qq)@}}"
+  }
+
+
+%test
+
+  BUFFER_STACK='btrfs --help'
+  run-help btrfs
+0:btrfs with option flag, no subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs'}
+
+  BUFFER_STACK='btrfs subvolume snapshot –r /btrfs/SV1 /btrfs/SV1-rosnap'
+  run-help btrfs
+0:btrfs with subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs-subvolume'}
+
+  BUFFER_STACK="sudo $BUFFER_STACK"
+  run-help btrfs
+0:sudo btrfs with subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs-subvolume'}
+
+  BUFFER_STACK='ip addr add 192.168.50.5 dev eth1'
+  run-help ip
+0:ip with subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-address'}
+
+  NO_SUBCMD_MANUALS=1
+  run-help ip
+  unset NO_SUBCMD_MANUALS
+0:ip with subcmd, but no subcmd manuals
+>ip is WHENCE:{ip}
+>MAN:{'ip'}
+
+  BUFFER_STACK='ip -s -s link ls up'
+  run-help ip
+0:ip with options and subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-link'}
+
+  BUFFER_STACK="sudo $BUFFER_STACK"
+  run-help ip
+0:sudo ip with options and subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-link'}
+
+  BUFFER_STACK='svn -vq'
+  run-help svn
+0:svn with options
+>svn is WHENCE:{svn}
+>SVN:{'help'}
+
+  BUFFER_STACK+=' commit -m "log messages"'
+  run-help svn
+0:svn with options and subcmd
+>svn is WHENCE:{svn}
+>SVN:{'help' 'commit'}
+
+  BUFFER_STACK='git --exec-path'
+  run-help git
+0:git with option
+>git is WHENCE:{git}
+>GIT:{'help' 'git'}
+
+  BUFFER_STACK='git -C $PWD/.. difftool --no-prompt --tool opendiff --dir-diff'
+  run-help git
+0:git with option, file & subcmd
+>git is WHENCE:{git}
+>GIT:{'help' 'difftool'}
+
+  BUFFER_STACK='git -c http.proxy=someproxy clone https://github.com/user/repo.git'
+  run-help git
+0:git with option, assignment & subcmd
+>git is WHENCE:{git}
+>GIT:{'help' 'clone'}
+
+
+%clean
-- 
2.30.1 (Apple Git-130)


  reply	other threads:[~2021-07-29 12:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 20:47 [RFC][PATCH] Try calling command with help flags in run-help Marlon Richert
2021-05-25 20:57 ` Bart Schaefer
2021-06-02 18:26   ` [PATCH] Let run-help try to show function source from file (was Re: [RFC][PATCH] Try calling command with help flags in run-help) Marlon Richert
2021-06-20 21:23     ` Lawrence Velázquez
2021-07-18 18:38       ` Lawrence Velázquez
2021-07-28  2:03       ` Bart Schaefer
2021-06-02 20:58   ` Let run-help filter cmd_args before calling run-help-<command> " Marlon Richert
2021-06-03  4:34     ` Bart Schaefer
2021-06-03  4:38       ` Bart Schaefer
2021-06-03 21:26       ` Marlon Richert
2021-06-03 21:45         ` Lawrence Velázquez
2021-06-03 21:52           ` Bart Schaefer
2021-06-03 22:00             ` Lawrence Velázquez
2021-06-03 23:33         ` Bart Schaefer
2021-06-05 19:15           ` Marlon Richert
2021-06-20 18:01             ` Lawrence Velázquez
2021-07-18 18:45               ` Lawrence Velázquez
2021-07-28 17:58                 ` Bart Schaefer
2021-07-29 12:11                   ` Marlon Richert [this message]
2021-07-30 16:55                     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHLkEDu7+k=f=B=A0uLWTj0676VYM9fM_=RcB0e2sgeHPeULoA@mail.gmail.com' \
    --to=marlon.richert@gmail.com \
    --cc=larryv@zsh.org \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).