Repository: fniessink/next-action

Issue:
Next-action can't be told to not read the current configuration file when generating one
```console
$ next-action -w -c
Usage: next-action [-h] [--version] [-c [<config.cfg>] | -w] [-f <todo.txt> ...] [-r <ref>] [-s [<style>]] [-a | -n
<number>] [-d [<due date>] | -o] [-p [<priority>]] [--] [<context|project> ...]
next-action: error: argument -c/--config-file: not allowed with argument -w/--write-config-file
```

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 91e0439..2481f94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
+## [Unreleased] - 2018-07-14
+
+### Fixed
+
+- Allow for using `--config` when generating a configuration file with `--write-config-file` so it is possible to ignore the existing configuration file when generating a new one. Fixes #161.
+
 ## [1.5.2] - 2018-07-07
 
 ### Fixed
diff --git a/README.md b/README.md
index d78de09..ffb50ba 100644
--- a/README.md
+++ b/README.md
@@ -283,7 +283,7 @@ $ next-action --write-config-file
 file: ~/todo.txt
 number: 1
 reference: multiple
-style: native
+style: default
 ```
 
 To make this the configuration that *Next-action* reads by default, redirect the output to `~/.next-action.cfg` like this: `next-action --write-config-file > ~/.next-action.cfg`.
@@ -448,9 +448,9 @@ To run the unit tests:
 
 ```console
 $ python -m unittest
-...........................................................................................................................................................................................................................................
+............................................................................................................................................................................................................................................
 ----------------------------------------------------------------------
-Ran 235 tests in 2.611s
+Ran 236 tests in 2.931s
 
 OK
 ```
@@ -461,9 +461,9 @@ To create the unit test coverage report run the unit tests under coverage with:
 
 ```console
 $ coverage run --branch -m unittest
-...........................................................................................................................................................................................................................................
+............................................................................................................................................................................................................................................
 ----------------------------------------------------------------------
-Ran 235 tests in 2.784s
+Ran 236 tests in 3.557s
 
 OK
 ```
@@ -475,7 +475,7 @@ $ coverage report --fail-under=100 --omit=".venv/*" --skip-covered
 Name    Stmts   Miss Branch BrPart  Cover
 -----------------------------------------
 -----------------------------------------
-TOTAL    1341      0    173      0   100%
+TOTAL    1347      0    173      0   100%
 
 25 files skipped due to complete coverage.
 ```
diff --git a/docs/update_readme.py b/docs/update_readme.py
index acdba69..2ff52b6 100644
--- a/docs/update_readme.py
+++ b/docs/update_readme.py
@@ -10,9 +10,10 @@ import sys
 def do_command(line):
     """Run the command on the line and return its stdout and stderr."""
     command = shlex.split(line[2:])
-    if command[0] == "next-action" and "--write-config-file" not in command:
+    if command[0] == "next-action":
         command.insert(1, "--config")
-        command.insert(2, "docs/.next-action.cfg")
+        if "--write-config-file" not in command:
+            command.insert(2, "docs/.next-action.cfg")
     command_output = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                                     universal_newlines=True)
     stdout = command_output.stdout.strip()
diff --git a/next_action/arguments/parser.py b/next_action/arguments/parser.py
index 35c9f6a..3184c55 100644
--- a/next_action/arguments/parser.py
+++ b/next_action/arguments/parser.py
@@ -50,12 +50,11 @@ class NextActionArgumentParser(argparse.ArgumentParser):
     def add_configuration_options(self) -> None:
         """Add the configuration options to the parser."""
         config_group = self.add_argument_group("Configuration options")
-        config_file = config_group.add_mutually_exclusive_group()
-        config_file.add_argument(
+        config_group.add_argument(
             "-c", "--config-file", metavar="<config.cfg>", type=str, default="~/.next-action.cfg", nargs="?",
             help="filename of configuration file to read (default: %(default)s); omit filename to not read any "
                  "configuration file")
-        config_file.add_argument(
+        config_group.add_argument(
             "-w", "--write-config-file", help="generate a sample configuration file and exit", action="store_true")
 
     def add_input_options(self) -> None:


Test patch:
diff --git a/tests/unittests/arguments/test_config.py b/tests/unittests/arguments/test_config.py
index fadbf58..7eb47f0 100644
--- a/tests/unittests/arguments/test_config.py
+++ b/tests/unittests/arguments/test_config.py
@@ -161,6 +161,16 @@ class WriteConfigFileTest(ConfigTestCase):
         expected += "file: ~/todo.txt\nnumber: 3\nreference: multiple\nstyle: default\n"
         self.assertEqual([call(expected)], mock_stdout_write.call_args_list)
 
+    @patch.object(sys, "argv", ["next-action", "--write-config-file", "--config"])
+    @patch.object(config, "open", mock_open(read_data="number: 3"))
+    @patch.object(sys.stdout, "write")
+    def test_ignore_config(self, mock_stdout_write):
+        """Test that the written config file does not contain the read config file."""
+        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)
+
 
 class FilenameTest(ConfigTestCase):
     """Unit tests for the config file parameter."""