From 5cf300aafdff5956c4256d2c3a721439fa6532a8 Mon Sep 17 00:00:00 2001
From: Merlin Mathesius <mmathesi@redhat.com>
Date: Apr 09 2019 19:28:00 +0000
Subject: [PATCH 1/2] Enable shell completion for module scratch builds.

Add custom SRPM shell completion with local module builds.
Add missing shell completion options for local module builds.

Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>

---

diff --git a/conf/bash-completion/fedpkg.bash b/conf/bash-completion/fedpkg.bash
index 1d3428c..a045e61 100644
--- a/conf/bash-completion/fedpkg.bash
+++ b/conf/bash-completion/fedpkg.bash
@@ -32,6 +32,7 @@ _fedpkg()
     container-build diff gimmespec giturl help gitbuildhash import install lint \
     local mockbuild mock-config module-build module-build-cancel \
     module-build-local module-build-info module-build-watch module-overview \
+    module-scratch-build \
     new new-sources patch prep pull push retire request-branch request-repo \
     scratch-build sources srpm switch-branch tag unused-patches update upload \
     verify-files verrel override"
@@ -87,7 +88,7 @@ _fedpkg()
     # parse command specific options
 
     local options=
-    local options_target= options_arches= options_branch= options_string= options_file= options_dir= options_srpm= options_mroot= options_builder= options_namespace=
+    local options_target= options_arches= options_branch= options_string= options_file= options_dir= options_srpm= options_srpms= options_mroot= options_builder= options_namespace=
     local options_update_type= options_update_request=
     local after= after_more=
 
@@ -163,17 +164,27 @@ _fedpkg()
             options_mroot="--root --mock-config"
             ;;
         module-build)
-            options="--watch"
-            options_string="--optional"
+            options="--scratch --watch"
+            options_string="--optional --requires --buildrequires"
+            options_file="--file"
+            options_srpms="--srpms"
             ;;
         module-build-local)
             options="--skip-tests"
-            options_string="--add-local-build"
+            options_string="--add-local-build --stream --set-default-stream"
+            options_file="--file"
+            options_srpms="--srpms"
             ;;
         module-overview)
             options="--unfinished"
             options_string="--limit"
             ;;
+        module-scratch-build)
+            options="--watch"
+            options_string="--optional --requires --buildrequires"
+            options_file="--file"
+            options_srpms="--srpms"
+            ;;
         patch)
             options="--rediff"
             options_string="--suffix"
@@ -233,7 +244,7 @@ _fedpkg()
 
     local all_options="--help $options"
     local all_options_value="$options_target $options_arches $options_branch \
-    $options_string $options_file $options_dir $options_srpm $options_mroot \
+    $options_string $options_file $options_dir $options_srpm $options_srpms $options_mroot \
     $options_builder $options_namespace $options_update_type $options_update_request"
 
     # count non-option parameters
@@ -267,6 +278,9 @@ _fedpkg()
     elif [[ -n $options_srpm ]] && in_array "$prev" "$options_srpm"; then
         _filedir_exclude_paths "*.src.rpm"
 
+    elif [[ -n $options_srpms ]] && in_array "$last_option" "$options_srpms"; then
+        _filedir_exclude_paths "*.src.rpm"
+
     elif [[ -n $options_branch ]] && in_array "$prev" "$options_branch"; then
         COMPREPLY=( $(compgen -W "$(_fedpkg_branch "$path")" -- "$cur") )
 
diff --git a/conf/zsh-completion/_fedpkg b/conf/zsh-completion/_fedpkg
index f00687f..1ba63bf 100644
--- a/conf/zsh-completion/_fedpkg
+++ b/conf/zsh-completion/_fedpkg
@@ -222,7 +222,12 @@ _fedpkg-module-build () {
   _arguments -C \
     '(-h --help)'{-h,--help}'[show help message and exit]' \
     '(-w --watch)'{-w,--watch}'[Watch the module build]' \
+    '--buildrequires[Buildrequires to override in the form of "name:stream"]' \
+    '--requires[Requires to override in the form of "name:stream"]' \
     '--optional[MBS optional arguments in the form of "key=value"]:optional' \
+    '--scratch[Perform a scratch build]' \
+    '--file[The modulemd yaml file for module scratch build.]:file:_files' \
+    '--srpms[Include one or more srpms for module scratch build.]:*:srpms:_files -g "*.src.rpm"' \
     ':scm_url' \
     ':branch'
 }
@@ -247,6 +252,10 @@ _fedpkg-module-build-local () {
     '(-h --help)'{-h,--help}'[show help message and exit]' \
     '--skip-tests[Adds a macro for skipping the check section]' \
     '--add-local-build[Import previously finished local module builds into MBS]:build_id' \
+    '--stream[The module'\''s stream/SCM branch.]:stream' \
+    '(--set-default-stream -s)'{--set-default-stream,-s}'[Set the default stream for given module dependency.]:default_stream' \
+    '--file[The module'\''s modulemd yaml file.]:file:_files' \
+    '--srpms[Include one or more srpms for module build.]:*:srpms:_files -g "*.src.rpm"' \
     ':scm_url' \
     ':branch'
 }
@@ -266,6 +275,20 @@ _fedpkg-module-build-watch () {
     ':build_id'
 }
 
+(( $+functions[_fedpkg-module-scratch-build] )) ||
+_fedpkg-module-scratch-build () {
+  _arguments -C \
+    '(-h --help)'{-h,--help}'[show help message and exit]' \
+    '(-w --watch)'{-w,--watch}'[Watch the module build]' \
+    '--buildrequires[Buildrequires to override in the form of "name:stream"]' \
+    '--requires[Requires to override in the form of "name:stream"]' \
+    '--optional[MBS optional arguments in the form of "key=value"]:optional' \
+    '--file[The modulemd yaml file for module scratch build.]:file:_files' \
+    '--srpms[Include one or more srpms for module scratch build.]:*:srpms:_files -g "*.src.rpm"' \
+    ':scm_url' \
+    ':branch'
+}
+
 (( $+functions[_fedpkg-new] )) ||
 _fedpkg-new () {
   _arguments -C \
@@ -458,6 +481,7 @@ _fedpkg_commands () {
     module-build-local:'build a module locally using the mbs-manager command'
     module-build-watch:'watch an MBS build'
     module-overview:'shows an overview of MBS builds'
+    module-scratch-build:'build a scratch module using MBS'
     new:'diff against last tag'
     new-sources:'upload new source files'
     patch:'create and add a gendiff patch file'

From 9962939d70e11f51bfd000aac7053dc2da81ca55 Mon Sep 17 00:00:00 2001
From: Merlin Mathesius <mmathesi@redhat.com>
Date: Apr 09 2019 19:28:00 +0000
Subject: [PATCH 2/2] Revise shell completion for module scratch builds to require SRPMs to be

specified individually using multiple '--srpm SRPM' options, and enable
completion of modulemd file path by yaml extension.

Signed-off-by: Merlin Mathesius <mmathesi@redhat.com>

---

diff --git a/conf/bash-completion/fedpkg.bash b/conf/bash-completion/fedpkg.bash
index a045e61..2a1d11e 100644
--- a/conf/bash-completion/fedpkg.bash
+++ b/conf/bash-completion/fedpkg.bash
@@ -88,8 +88,9 @@ _fedpkg()
     # parse command specific options
 
     local options=
-    local options_target= options_arches= options_branch= options_string= options_file= options_dir= options_srpm= options_srpms= options_mroot= options_builder= options_namespace=
+    local options_target= options_arches= options_branch= options_string= options_file= options_dir= options_srpm= options_mroot= options_builder= options_namespace=
     local options_update_type= options_update_request=
+    local options_yaml=
     local after= after_more=
 
     case $command in
@@ -166,14 +167,14 @@ _fedpkg()
         module-build)
             options="--scratch --watch"
             options_string="--optional --requires --buildrequires"
-            options_file="--file"
-            options_srpms="--srpms"
+            options_yaml="--file"
+            options_srpm="--srpm"
             ;;
         module-build-local)
             options="--skip-tests"
             options_string="--add-local-build --stream --set-default-stream"
-            options_file="--file"
-            options_srpms="--srpms"
+            options_yaml="--file"
+            options_srpm="--srpm"
             ;;
         module-overview)
             options="--unfinished"
@@ -182,8 +183,8 @@ _fedpkg()
         module-scratch-build)
             options="--watch"
             options_string="--optional --requires --buildrequires"
-            options_file="--file"
-            options_srpms="--srpms"
+            options_yaml="--file"
+            options_srpm="--srpm"
             ;;
         patch)
             options="--rediff"
@@ -244,8 +245,9 @@ _fedpkg()
 
     local all_options="--help $options"
     local all_options_value="$options_target $options_arches $options_branch \
-    $options_string $options_file $options_dir $options_srpm $options_srpms $options_mroot \
-    $options_builder $options_namespace $options_update_type $options_update_request"
+    $options_string $options_file $options_dir $options_srpm $options_mroot \
+    $options_builder $options_namespace $options_update_type $options_update_request \
+    $options_yaml"
 
     # count non-option parameters
 
@@ -278,8 +280,8 @@ _fedpkg()
     elif [[ -n $options_srpm ]] && in_array "$prev" "$options_srpm"; then
         _filedir_exclude_paths "*.src.rpm"
 
-    elif [[ -n $options_srpms ]] && in_array "$last_option" "$options_srpms"; then
-        _filedir_exclude_paths "*.src.rpm"
+    elif [[ -n $options_yaml ]] && in_array "$prev" "$options_yaml"; then
+        _filedir_exclude_paths "yaml"
 
     elif [[ -n $options_branch ]] && in_array "$prev" "$options_branch"; then
         COMPREPLY=( $(compgen -W "$(_fedpkg_branch "$path")" -- "$cur") )
diff --git a/conf/zsh-completion/_fedpkg b/conf/zsh-completion/_fedpkg
index 1ba63bf..405f13c 100644
--- a/conf/zsh-completion/_fedpkg
+++ b/conf/zsh-completion/_fedpkg
@@ -226,8 +226,8 @@ _fedpkg-module-build () {
     '--requires[Requires to override in the form of "name:stream"]' \
     '--optional[MBS optional arguments in the form of "key=value"]:optional' \
     '--scratch[Perform a scratch build]' \
-    '--file[The modulemd yaml file for module scratch build.]:file:_files' \
-    '--srpms[Include one or more srpms for module scratch build.]:*:srpms:_files -g "*.src.rpm"' \
+    '--file[The modulemd yaml file for module scratch build.]:file:_files -g "*.yaml"' \
+    '*--srpm[Include srpm for module scratch build.]:srpm:_files -g "*.src.rpm"' \
     ':scm_url' \
     ':branch'
 }
@@ -254,8 +254,8 @@ _fedpkg-module-build-local () {
     '--add-local-build[Import previously finished local module builds into MBS]:build_id' \
     '--stream[The module'\''s stream/SCM branch.]:stream' \
     '(--set-default-stream -s)'{--set-default-stream,-s}'[Set the default stream for given module dependency.]:default_stream' \
-    '--file[The module'\''s modulemd yaml file.]:file:_files' \
-    '--srpms[Include one or more srpms for module build.]:*:srpms:_files -g "*.src.rpm"' \
+    '--file[The module'\''s modulemd yaml file.]:file:_files -g "*.yaml"' \
+    '*--srpm[Include srpm for module build.]:srpm:_files -g "*.src.rpm"' \
     ':scm_url' \
     ':branch'
 }
@@ -283,8 +283,8 @@ _fedpkg-module-scratch-build () {
     '--buildrequires[Buildrequires to override in the form of "name:stream"]' \
     '--requires[Requires to override in the form of "name:stream"]' \
     '--optional[MBS optional arguments in the form of "key=value"]:optional' \
-    '--file[The modulemd yaml file for module scratch build.]:file:_files' \
-    '--srpms[Include one or more srpms for module scratch build.]:*:srpms:_files -g "*.src.rpm"' \
+    '--file[The modulemd yaml file for module scratch build.]:file:_files -g "*.yaml"' \
+    '*--srpm[Include srpm for module scratch build.]:srpm:_files -g "*.src.rpm"' \
     ':scm_url' \
     ':branch'
 }

