zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _arguments --: correctly handle optional argument in help text
@ 2021-10-18  9:42 Jun T
  0 siblings, 0 replies; only message in thread
From: Jun T @ 2021-10-18  9:42 UTC (permalink / raw)
  To: zsh-workers

Help text (output of 'cmd --help') can include a line like

    --log[=FILE]    log file (default stderr)

Here [=FILE] indicates the argument is optional.

But with the current _arguments:

% cmd () { echo "\t--add\n\t--del\n\t--log[=FILE]  log file" }
% compdef _gnu_generic cmd
% cmd --log -<TAB>
No match for: `file'

Since the argument to --log is optional, options --add and --del
should be offered here.

This is due to the lines 135-136 of _arguments. The comments say the
lines are for handling the following help text of fetchmail command

    --[fetch]all    maybe some explanation here

but the pattern (*)\[(*)\](*) used there also matches
--log[=FILE], and it is converted into --log=FILE and --log.

In the patch below, I used more restrictive pattern
--\[(*)\](*) so that it only matches [...] just after --.


_BUT_, there is already a completion function for fetchmail
(Completion/Unix/Command/_fetchmail), although it is not updated
at least since 2001.

I kept the lines 135-6 (with fix) in case some other command(s) use
--[xxx]yyy in help texts, but if it's better to remove the lines
rather than fixing them, please let me know.




diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments
index 3f1b39304..cab7c929e 100644
--- a/Completion/Base/Utility/_arguments
+++ b/Completion/Base/Utility/_arguments
@@ -132,8 +132,8 @@ if (( long )); then
 	 # variant syntax seen in fetchmail:
 	 # --[fetch]all  means --fetchall or --all.
 	 # maybe needs to be more general
-	 if [[ $start = (#b)(*)\[(*)\](*) ]]; then
-	   tmp+=("${match[1]}${match[2]}${match[3]}" "${match[1]}${match[3]}")
+	 if [[ $start = (#b)--\[(*)\](*) ]]; then
+	   tmp+=("--${match[1]}${match[2]}" "--${match[2]}")
 	 else
 	   tmp+=($start)
 	 fi







^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-18  9:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18  9:42 [PATCH] _arguments --: correctly handle optional argument in help text Jun T

Code repositories for project(s) associated with this 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).