From 8bcffc6b11131d989cf92cea52aa849790f1580f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 20 Aug 2003 12:03:07 +0000 Subject: [PATCH] 18951: Better option handling (c.f. 18948) --- ChangeLog | 4 +++ Completion/Unix/Command/_perforce | 49 +++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0f80fd7c9..ceccdd4a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2003-08-20 Peter Stephenson + * 18951: Completion/Unix/Command/_perforce: Improve 18948 to + limit options retained, also make argument to p4 -p complete + better. + * 18942: Completion/Unix/Command/_perforce: Fix autoremoval of slashes which were stomped on by the special suffix handler. diff --git a/Completion/Unix/Command/_perforce b/Completion/Unix/Command/_perforce index cde4cf013..6803ad6da 100644 --- a/Completion/Unix/Command/_perforce +++ b/Completion/Unix/Command/_perforce @@ -251,26 +251,40 @@ _perforce() { fi fi - # We need to try and check if we are before or after the - # subcommand, since some of the options with arguments, in particular -c, - # work differently. It didn't work if I just added '*::...' to the - # end of the arguments list, anyway. - for (( i = 2; i < CURRENT; i++ )); do - if [[ $words[i] = -[cCdHLpPux] ]]; then - # word with following argument - (( i++ )) - elif [[ $words[i] != -* ]]; then - break - fi - done + # Options with arguments we need to pass down when calling + # p4 from completers. There are no options without arguments + # we need to pass. (Don't pass down -L language since we + # parse based on English output.) + local argopts_pass="cCdHpPu" + # Other options which have arguments but we shouldn't pass down. + # There are some debugging options, but they tend to get used + # with the argument in the same word as the option, in which + # case they will be handled OK anyway. + local argopts_ignore="Lx" # If we are at or after the command word, remember the # global arguments to p4 as we will need to pass these down # when generating completion lists. local -a _perforce_global_options - if (( i <= CURRENT && i > 2 )); then - _perforce_global_options=(${words[2,i-1]}) - fi + + # We need to try and check if we are before or after the + # subcommand, since some of the options with arguments, in particular -c, + # work differently. It didn't work if I just added '*::...' to the + # end of the arguments list, anyway. + for (( i = 2; i < CURRENT; i++ )); do + if [[ $words[i] = -[$argopts_pass$argopts_ignore] ]]; then + # word with following argument + if [[ $words[i] = -[$argopts_pass] ]]; then + _perforce_global_options+=(${words[i,i+1]}) + fi + (( i++ )) + elif [[ $words[i] = -[$argopts_pass]* ]]; then + # word including argument which we want to keep + _perforce_global_options+=(${words[i]}) + elif [[ $words[i] != -* ]]; then + break + fi + done if (( i >= CURRENT )); then _arguments -s : \ @@ -280,7 +294,7 @@ _perforce() { '-H+[hostname]:host:_hosts' \ '-G[python output]' \ '-L+[message language]:language: ' \ - '-p+[server port]:port:_ports' \ + '-p+[server port]:port:_perforce_hosts_ports' \ '-P+[password on server]:password: ' \ '-s[output script tags]' \ '-u+[user]:user name:_users' \ @@ -305,6 +319,9 @@ _perforce() { _perforce_call_p4() { local cp_tag=$1 shift + # This is for our own use for parsing, and we need English output, + # so... + local +x P4LANGUAGE _call_program $cp_tag p4 "${_perforce_global_options[@]}" "$@" }