From: Jun T <takimoto-j@kba.biglobe.ne.jp> To: zsh-workers@zsh.org Subject: [PATCH] _arguments --: correctly handle optional argument in help text Date: Mon, 18 Oct 2021 18:42:09 +0900 [thread overview] Message-ID: <C7B168A2-31ED-4512-8297-2C895F1EAF81@kba.biglobe.ne.jp> (raw) 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
reply other threads:[~2021-10-18 9:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=C7B168A2-31ED-4512-8297-2C895F1EAF81@kba.biglobe.ne.jp \ --to=takimoto-j@kba.biglobe.ne.jp \ --cc=zsh-workers@zsh.org \ --subject='Re: [PATCH] _arguments --: correctly handle optional argument in help text' \ /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
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).