From 774678a982bb86d2e90e46240a548b59e9951fb0 Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Oct 09 2017 12:23:37 +0000
Subject: Allow to specify alternative Copr config file


Fix #184

Signed-off-by: Chenxiong Qi <cqi@redhat.com>

---

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 017b545..5c6c789 100644
--- a/pyrpkg/__init__.py
+++ b/pyrpkg/__init__.py
@@ -2655,8 +2655,11 @@ class Commands(object):
         else:
             self.log.info('Nothing to be done')
 
-    def copr_build(self, project, srpm_name, nowait):
-        cmd = ['copr-cli', 'build']
+    def copr_build(self, project, srpm_name, nowait, config_file):
+        cmd = ['copr-cli']
+        if config_file:
+            cmd.extend(['--config', config_file])
+        cmd.append('build')
         if nowait:
             cmd.append('--nowait')
         cmd.extend([project, srpm_name])
diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index 80e8b91..ac72148 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -829,6 +829,10 @@ see API KEY section of copr-cli(1) man page.
 """)
 
         copr_parser.add_argument(
+            '--config', required=False,
+            metavar='CONFIG', dest='copr_config',
+            help="Path to an alternative Copr configuration file")
+        copr_parser.add_argument(
             '--nowait', action='store_true', default=False,
             help="Don't wait on build")
         copr_parser.add_argument(
@@ -1232,7 +1236,10 @@ see API KEY section of copr-cli(1) man page.
         self.args.hash = None
         self.srpm()
         srpm_name = '%s.src.rpm' % self.cmd.nvr
-        self.cmd.copr_build(self.args.project[0], srpm_name, self.args.nowait)
+        self.cmd.copr_build(self.args.project[0],
+                            srpm_name,
+                            self.args.nowait,
+                            self.args.copr_config)
 
     def diff(self):
         self.cmd.diff(self.args.cached, self.args.files)
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 9493b58..d39b2ef 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1327,16 +1327,19 @@ class TestCoprBuild(CliTestCase):
         self.nvr_patcher.stop()
         super(TestCoprBuild, self).tearDown()
 
-    def test_copr_build(self):
-        cli_cmd = ['rpkg', '--path', self.cloned_repo_path,
-                   'copr-build', 'user/project']
-
+    def assert_copr_build(self, cli_cmd, expected_copr_cli):
         with patch('sys.argv', new=cli_cmd):
             cli = self.new_cli()
             cli.copr_build()
 
         self.mock_srpm.assert_called_once()
-        self.mock_run_command.assert_called_once_with([
+        self.mock_run_command.assert_called_once_with(expected_copr_cli)
+
+    def test_copr_build(self):
+        cli_cmd = ['rpkg', '--path', self.cloned_repo_path,
+                   'copr-build', 'user/project']
+
+        self.assert_copr_build(cli_cmd, [
             'copr-cli', 'build', 'user/project',
             '{0}.src.rpm'.format(self.mock_nvr.return_value)
         ])
@@ -1345,16 +1348,22 @@ class TestCoprBuild(CliTestCase):
         cli_cmd = ['rpkg', '--path', self.cloned_repo_path,
                    'copr-build', '--nowait', 'user/project']
 
-        with patch('sys.argv', new=cli_cmd):
-            cli = self.new_cli()
-            cli.copr_build()
-
-        self.mock_srpm.assert_called_once()
-        self.mock_run_command.assert_called_once_with([
+        self.assert_copr_build(cli_cmd, [
             'copr-cli', 'build', '--nowait', 'user/project',
             '{0}.src.rpm'.format(self.mock_nvr.return_value)
         ])
 
+    def test_copr_build_with_alternative_config_file(self):
+        cli_cmd = ['rpkg', '--path', self.cloned_repo_path,
+                   'copr-build', '--config', '/path/to/alternative/config',
+                   'user/project']
+
+        self.assert_copr_build(cli_cmd, [
+            'copr-cli', '--config', '/path/to/alternative/config',
+            'build', 'user/project',
+            '{0}.src.rpm'.format(self.mock_nvr.return_value)
+        ])
+
 
 class TestMockConfig(CliTestCase):
     """Test mockconfig command"""

