[PATCH v5 2/3] send-email: programmatically generate bash completions
From: Thiago Perrotta <hidden>
Date: 2021-09-24 02:47:10
Subsystem:
the rest · Maintainer:
Linus Torvalds
"git send-email --git-completion-helper" only prints "format-patch" flags. Make it print "send-email" flags as well, generating them programmatically from the usage. Introduce a uniq subroutine, otherwise --dump-aliases would show up twice in the flags. Add a completion test for "send-email --validate", a send-email option. Signed-off-by: Thiago Perrotta <redacted> --- contrib/completion/git-completion.bash | 11 +---------- git-send-email.perl | 21 +++++++++++++++++---- t/t9902-completion.sh | 3 +++ 3 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4bdd27ddc8..1b73a4dcc0 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash@@ -2359,16 +2359,7 @@ _git_send_email () return ;; --*) - __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to - --compose --confirm= --dry-run --envelope-sender - --from --identity - --in-reply-to --no-chain-reply-to --no-signed-off-by-cc - --no-suppress-from --no-thread --quiet --reply-to - --signed-off-by-cc --smtp-pass --smtp-server - --smtp-server-port --smtp-encryption= --smtp-user - --subject --suppress-cc= --suppress-from --thread --to - --validate --no-validate - $__git_format_patch_extra_options" + __gitcomp_builtin send-email "$__git_format_patch_extra_options" return ;; esac
diff --git a/git-send-email.perl b/git-send-email.perl
index d1731c1755..3d4836aa48 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl@@ -38,9 +38,8 @@ sub readline { package main; -sub usage { - print <<EOT; -git send-email [options] <file | directory | rev-list options > +my $USAGE = <<EOT +git send-email [options] <file | directory | rev-list options> git send-email --dump-aliases Composing:
@@ -110,11 +109,25 @@ sub usage { --dump-aliases * Dump configured aliases and exit. EOT +; + +sub usage { + print $USAGE; exit(1); } +sub uniq { + my %seen; + grep !$seen{$_}++, @_; +} + sub completion_helper { - print Git::command('format-patch', '--git-completion-helper'), "\n"; + my @no_only_flags; + push @no_only_flags, "--$1", "--no-$1" while ($USAGE =~ /--\[no-](\w+(?:-\w+)*)/g); + + my @all_flags = uniq($USAGE =~ /--\w+(?:-\w+)*/g, @no_only_flags); + + print "@all_flags", Git::command('format-patch', '--git-completion-helper'), "\n"; exit(0); }
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 11573936d5..a4faf64184 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh@@ -2139,6 +2139,9 @@ test_expect_success PERL 'send-email' ' --cover-from-description=Z --cover-letter Z EOF + test_completion "git send-email --val" <<-\EOF && + --validate Z + EOF test_completion "git send-email ma" "main " '
--
2.33.0