Repository: fniessink/next-action

Issue:
--write-config-file ignores --priority

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2864bbb..5ced4b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 ### Fixed
 
 - When generating a configuration file with `--write-config-file` also include context and project filters passed on the command-line. Closes #141.
+- When generating a configuration file with `--write-config-file` also include the minimum priority if passed on the command-line. Closes #142.
 
 ## [1.5.0] - 2018-06-30
 
diff --git a/README.md b/README.md
index 279bfb1..69b3265 100644
--- a/README.md
+++ b/README.md
@@ -291,12 +291,13 @@ To make this the configuration that *Next-action* reads by default, redirect the
 Any additional options specified on the command line are used to generate the configuration file:
 
 ```console
-$ next-action --write-config-file --number 3 --file ~/tasks.txt --style fruity -@waiting
+$ next-action --write-config-file --number 3 --file ~/tasks.txt --style fruity --priority Z -@waiting
 # Configuration file for Next-action. Edit the settings below as you like.
 file: ~/tasks.txt
 filters:
 - -@waiting
 number: 3
+priority: Z
 reference: multiple
 style: fruity
 ```
@@ -447,9 +448,9 @@ To run the unit tests:
 
 ```console
 $ python -m unittest
-.........................................................................................................................................................................................................................................
+..........................................................................................................................................................................................................................................
 ----------------------------------------------------------------------
-Ran 233 tests in 2.089s
+Ran 234 tests in 2.059s
 
 OK
 ```
@@ -460,9 +461,9 @@ To create the unit test coverage report run the unit tests under coverage with:
 
 ```console
 $ coverage run --branch -m unittest
-.........................................................................................................................................................................................................................................
+..........................................................................................................................................................................................................................................
 ----------------------------------------------------------------------
-Ran 233 tests in 3.098s
+Ran 234 tests in 2.740s
 
 OK
 ```
@@ -474,7 +475,7 @@ $ coverage report --fail-under=100 --omit=".venv/*" --skip-covered
 Name    Stmts   Miss Branch BrPart  Cover
 -----------------------------------------
 -----------------------------------------
-TOTAL    1320      0    168      0   100%
+TOTAL    1329      0    170      0   100%
 
 25 files skipped due to complete coverage.
 ```
diff --git a/next_action/arguments/config.py b/next_action/arguments/config.py
index d273327..3c50661 100644
--- a/next_action/arguments/config.py
+++ b/next_action/arguments/config.py
@@ -42,6 +42,8 @@ def write_config_file(namespace: argparse.Namespace) -> None:
         options["all"] = True
     else:
         options["number"] = namespace.number
+    if namespace.priority:
+        options["priority"] = namespace.priority
     config = yaml.dump(options, default_flow_style=False)
     sys.stdout.write(intro + config)
 


Test patch:
diff --git a/tests/unittests/arguments/test_config.py b/tests/unittests/arguments/test_config.py
index bab1c3a..134a73a 100644
--- a/tests/unittests/arguments/test_config.py
+++ b/tests/unittests/arguments/test_config.py
@@ -107,7 +107,7 @@ class WriteConfigFileTest(ConfigTestCase):
         self.assertEqual([call(expected)], mock_stdout_write.call_args_list)
 
     @patch.object(sys, "argv", ["next-action", "--write-config-file", "--number", "3", "--reference", "never",
-                                "--style", "fruity", "--file", "~/tasks.txt", "@context", "+project",
+                                "--style", "fruity", "--file", "~/tasks.txt", "--priority", "Z", "@context", "+project",
                                 "-@excluded_context", "-+excluded_project"])
     @patch.object(config, "open", mock_open(read_data=""))
     @patch.object(sys.stdout, "write")
@@ -116,7 +116,7 @@ class WriteConfigFileTest(ConfigTestCase):
         self.assertRaises(SystemExit, parse_arguments)
         expected = "# Configuration file for Next-action. Edit the settings below as you like.\n" \
             "file: ~/tasks.txt\nfilters:\n- '@context'\n- +project\n- -@excluded_context\n- -+excluded_project\n" \
-            "number: 3\nreference: never\nstyle: fruity\n"
+            "number: 3\npriority: Z\nreference: never\nstyle: fruity\n"
         self.assertEqual([call(expected)], mock_stdout_write.call_args_list)
 
     @patch.object(sys, "argv", ["next-action", "--write-config-file", "--file", "~/tasks.txt", "--file", "project.txt"])
@@ -139,6 +139,16 @@ class WriteConfigFileTest(ConfigTestCase):
         expected += "all: true\nfile: ~/todo.txt\nreference: multiple\nstyle: default\n"
         self.assertEqual([call(expected)], mock_stdout_write.call_args_list)
 
+    @patch.object(sys, "argv", ["next-action", "--write-config-file", "--priority"])
+    @patch.object(config, "open", mock_open(read_data=""))
+    @patch.object(sys.stdout, "write")
+    def test_priority(self, mock_stdout_write):
+        """ Test that priority without argument is processed correctly. """
+        self.assertRaises(SystemExit, parse_arguments)
+        expected = "# Configuration file for Next-action. Edit the settings below as you like.\n"
+        expected += "file: ~/todo.txt\nnumber: 1\nreference: multiple\nstyle: default\n"
+        self.assertEqual([call(expected)], mock_stdout_write.call_args_list)
+
     @patch.object(sys, "argv", ["next-action", "--write-config-file"])
     @patch.object(config, "open", mock_open(read_data="number: 3"))
     @patch.object(sys.stdout, "write")