Commit a9576e22 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix previous commit and also support -a for disabling auto-archive.

The previous commit had the archive condition on the wrong place,
resulting that todo.txt files were not written out at all if archiving
was disabled.

Also introduce the (overall) -a flag to disable auto archiving. -a comes
from the original todo.txt CLI.

It would have been nicer to have DoCommand support the -a flag, however,
DoCommand doesn't know anything about archiving and I would like to keep
it that way.

Addresses issue #42.
parent 2190ac70
......@@ -24,16 +24,17 @@ import sys
from six import PY2
from six.moves import input
MAIN_OPTS = "c:d:ht:v"
MAIN_OPTS = "ac:d:ht:v"
def usage():
""" Prints the command-line usage of topydo. """
print("""\
Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
Synopsis: topydo [-a] [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
topydo -h
topydo -v
-a : Do not archive todo items on completion.
-c : Specify an alternative configuration file.
-d : Specify an alternative archive file (done.txt)
-h : This help text
......@@ -112,6 +113,7 @@ class CLIApplicationBase(object):
def __init__(self):
self.todolist = TodoList.TodoList([])
self.todofile = None
self.do_archive = True
def _usage(self):
usage()
......@@ -133,7 +135,9 @@ class CLIApplicationBase(object):
overrides = {}
for opt, value in opts:
if opt == "-c":
if opt == "-a":
self.do_archive = False
elif opt == "-c":
alt_config_path = value
elif opt == "-t":
overrides[('topydo', 'filename')] = value
......@@ -206,8 +210,9 @@ class CLIApplicationBase(object):
# do not archive when the value of the filename is an empty string
# (i.e. explicitly left empty in the configuration
if self.todolist.is_dirty() and config().archive():
self._archive()
if self.todolist.is_dirty():
if self.do_archive and config().archive():
self._archive()
if config().keep_sorted():
self._execute(SortCommand, [])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment