Repository: fniessink/next-action

Issue:
Make it possible to overwrite the style in the configuration file by not passing a style to the --style argument

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60da2e1..838c5c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
-### Removed
+### Added
+
+- Using the `--style` option without arguments ignores the style specified in the configuration file, if any. Closes #83.
+
+### Changed
 
-- The `--no-config-file` option was removed. To not read any configuration file, use the `--config-file` option without specifying a configuration filename.
+- The `--no-config-file` option was removed. To not read any configuration file, use the `--config-file` option without specifying a configuration filename. Closes #82.
 
 ## [0.12.0] - 2018-05-28
 
diff --git a/README.md b/README.md
index 07408b3..653b98d 100644
--- a/README.md
+++ b/README.md
@@ -38,8 +38,8 @@ Don't know what *Todo.txt* is? See <https://github.com/todotxt/todo.txt> for the
 
 ```console
 $ next-action --help
-usage: next-action [-h] [--version] [-c [<config.cfg>]] [-f <todo.txt>] [-n <number> | -a] [-o] [-p [<priority>]]
-[<context|project> ...]
+usage: next-action [-h] [--version] [-c [<config.cfg>]] [-f <todo.txt>] [-n <number> | -a] [-o] [-p [<priority>]] [-s
+[<style>]] [<context|project> ...]
 
 Show the next action in your todo.txt. The next action is selected from the tasks in the todo.txt file based on task
 properties such as priority, due date, and creation date. Limit the tasks from which the next action is selected by
@@ -61,7 +61,7 @@ optional arguments:
   -o, --overdue         show only overdue next actions
   -p [<priority>], --priority [<priority>]
                         minimum priority (A-Z) of next actions to show (default: None)
-  -s <style>, --style <style>
+  -s [<style>], --style [<style>]
                         colorize the output; available styles: abap, algol, algol_nu, arduino, autumn, borland, bw,
                         colorful, default, emacs, friendly, fruity, igor, lovelace, manni, monokai, murphy, native,
                         paraiso-dark, paraiso-light, pastie, perldoc, rainbow_dash, rrt, tango, trac, vim, vs, xcode
@@ -160,6 +160,8 @@ The next actions can be colorized using the `--style` argument. Run `next-action
 
 When you've decided on a style you prefer, it makes sense to configure the style in the configuration file. See the section below on how to configure *Next-action*.
 
+Not passing an argument to `--style` cancels the style that is configured in the configuration file, if any.
+
 ### Configuring *Next-action*
 
 In addition to specifying options on the command-line, you can also configure options in a configuration file. By default, *Next-action* tries to read a file called [.next-action.cfg](https://raw.githubusercontent.com/fniessink/next-action/master/docs/.next-action.cfg) in your home folder.
@@ -254,9 +256,9 @@ To run the unit tests:
 
 ```console
 $ python -m unittest
-...............................................................................................................................................
+................................................................................................................................................
 ----------------------------------------------------------------------
-Ran 143 tests in 0.420s
+Ran 144 tests in 0.426s
 
 OK
 ```
diff --git a/next_action/arguments/parser.py b/next_action/arguments/parser.py
index 52dc719..8966b0a 100644
--- a/next_action/arguments/parser.py
+++ b/next_action/arguments/parser.py
@@ -23,7 +23,7 @@ class NextActionArgumentParser(argparse.ArgumentParser):
                         "the tasks from which the next action is selected by specifying contexts the tasks must have "
                         "and/or projects the tasks must belong to.",
             usage=textwrap.fill("next-action [-h] [--version] [-c [<config.cfg>]] [-f <todo.txt>] "
-                                "[-n <number> | -a] [-o] [-p [<priority>]] [<context|project> ...]",
+                                "[-n <number> | -a] [-o] [-p [<priority>]] [-s [<style>]] [<context|project> ...]",
                                 width=shutil.get_terminal_size().columns - len("usage: ")))
         self.__default_filenames = ["~/todo.txt"]
         self.add_optional_arguments()
@@ -56,7 +56,7 @@ class NextActionArgumentParser(argparse.ArgumentParser):
             help="minimum priority (A-Z) of next actions to show (default: %(default)s)")
         styles = sorted(list(get_all_styles()))
         self.add_argument(
-            "-s", "--style", metavar="<style>", choices=styles, default=None,
+            "-s", "--style", metavar="<style>", choices=styles, default=None, nargs="?",
             help="colorize the output; available styles: {0} (default: %(default)s)".format(", ".join(styles)))
 
     def add_positional_arguments(self) -> None:


Test patch:
diff --git a/tests/unittests/arguments/test_config.py b/tests/unittests/arguments/test_config.py
index 6f126d8..2efa764 100644
--- a/tests/unittests/arguments/test_config.py
+++ b/tests/unittests/arguments/test_config.py
@@ -240,6 +240,12 @@ class ConfigStyleTest(ConfigTestCase):
         """ Test that a command line style overrides the style in the config file. """
         self.assertEqual("vim", parse_arguments()[1].style)
 
+    @patch.object(sys, "argv", ["next-action", "--style"])
+    @patch.object(config, "open", mock_open(read_data="style: default"))
+    def test_cancel_style(self):
+        """ Test that --style without style cancels the style in the config file. """
+        self.assertEqual(None, parse_arguments()[1].style)
+
     @patch.object(sys, "argv", ["next-action"])
     @patch.object(config, "open", mock_open(read_data="style: invalid_style"))
     @patch.object(sys.stderr, "write")
diff --git a/tests/unittests/arguments/test_parser.py b/tests/unittests/arguments/test_parser.py
index 6a262af..f9eebd5 100644
--- a/tests/unittests/arguments/test_parser.py
+++ b/tests/unittests/arguments/test_parser.py
@@ -11,7 +11,7 @@ from next_action.arguments import config, parse_arguments
 
 USAGE_MESSAGE = textwrap.fill(
     "usage: next-action [-h] [--version] [-c [<config.cfg>]] [-f <todo.txt>] [-n <number> | -a] [-o] "
-    "[-p [<priority>]] [<context|project> ...]", 120) + "\n"
+    "[-p [<priority>]] [-s [<style>]] [<context|project> ...]", 120) + "\n"
 
 
 class ParserTestCase(unittest.TestCase):
diff --git a/tests/unittests/test_cli.py b/tests/unittests/test_cli.py
index f26c609..b477698 100644
--- a/tests/unittests/test_cli.py
+++ b/tests/unittests/test_cli.py
@@ -65,8 +65,8 @@ class CLITest(unittest.TestCase):
         os.environ['COLUMNS'] = "120"  # Fake that the terminal is wide enough.
         self.assertRaises(SystemExit, next_action)
         self.assertEqual(call("""\
-usage: next-action [-h] [--version] [-c [<config.cfg>]] [-f <todo.txt>] [-n <number> | -a] [-o] [-p [<priority>]]
-[<context|project> ...]
+usage: next-action [-h] [--version] [-c [<config.cfg>]] [-f <todo.txt>] [-n <number> | -a] [-o] [-p [<priority>]] [-s
+[<style>]] [<context|project> ...]
 
 Show the next action in your todo.txt. The next action is selected from the tasks in the todo.txt file based on task
 properties such as priority, due date, and creation date. Limit the tasks from which the next action is selected by
@@ -88,7 +88,7 @@ optional arguments:
   -o, --overdue         show only overdue next actions
   -p [<priority>], --priority [<priority>]
                         minimum priority (A-Z) of next actions to show (default: None)
-  -s <style>, --style <style>
+  -s [<style>], --style [<style>]
                         colorize the output; available styles: abap, algol, algol_nu, arduino, autumn, borland, bw,
                         colorful, default, emacs, friendly, fruity, igor, lovelace, manni, monokai, murphy, native,
                         paraiso-dark, paraiso-light, pastie, perldoc, rainbow_dash, rrt, tango, trac, vim, vs, xcode