Commit 6faf0ded authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix generic help and usage of invalid subcommands in aliases

Plain 'help' would crash the column UI, as would the usage of an invalid
command in an alias.

This case should be handled properly, as the CLI and Prompt mode do.

For this purpose, the generic help text was extracted, such that it can
be printed in column mode (and also in prompt mode, while I was at it).
parent d0342c58
......@@ -29,25 +29,7 @@ MAIN_OPTS = "ac:C:d:ht:v"
MAIN_LONG_OPTS = ('version')
READ_ONLY_COMMANDS = ('List', 'ListContext', 'ListProject')
def usage():
""" Prints the command-line usage of topydo. """
print("""\
Synopsis: topydo [-a] [-c <config>] [-C <colormode>] [-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.
-C : Specify color mode (0 = disable, 1 = enable 16 colors,
16 = enable 16 colors, 256 = enable 256 colors, auto (default))
-d : Specify an alternative archive file (done.txt)
-h : This help text
-t : Specify an alternative todo file
-v : Print version and exit
Available commands:
GENERIC_HELP="""Available commands:
* add
* append (app)
......@@ -66,7 +48,26 @@ Available commands:
* tag
Run `topydo help <subcommand>` for command-specific help.\
""")
"""
def usage():
""" Prints the command-line usage of topydo. """
print("""\
Synopsis: topydo [-a] [-c <config>] [-C <colormode>] [-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.
-C : Specify color mode (0 = disable, 1 = enable 16 colors,
16 = enable 16 colors, 256 = enable 256 colors, auto (default))
-d : Specify an alternative archive file (done.txt)
-h : This help text
-t : Specify an alternative todo file
-v : Print version and exit
""" + GENERIC_HELP)
def write(p_file, p_string):
"""
......
......@@ -32,7 +32,7 @@ from topydo.lib.Utils import get_terminal_size
from topydo.lib.View import View
from topydo.lib.TodoFileWatched import TodoFileWatched
from topydo.lib import TodoList
from topydo.ui.CLIApplicationBase import CLIApplicationBase, error
from topydo.ui.CLIApplicationBase import CLIApplicationBase, error, GENERIC_HELP
from topydo.ui.columns.CommandLineWidget import CommandLineWidget
from topydo.ui.columns.ConsoleWidget import ConsoleWidget
from topydo.ui.columns.KeystateWidget import KeystateWidget
......@@ -301,6 +301,10 @@ class UIApplication(CLIApplicationBase):
'Error: {}. Check your aliases configuration.'.format(cerr))
return
if subcommand is None:
self._print_to_console(GENERIC_HELP)
return
env_args = (self.todolist, p_output, self._output, self._input)
ids = None
......
......@@ -20,7 +20,7 @@ import os.path
import shlex
import sys
from topydo.ui.CLIApplicationBase import CLIApplicationBase, error, usage
from topydo.ui.CLIApplicationBase import CLIApplicationBase, error, GENERIC_HELP
from topydo.ui.prompt.TopydoCompleter import TopydoCompleter
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.history import InMemoryHistory
......@@ -94,7 +94,7 @@ class PromptApplication(CLIApplicationBase):
if self._execute(subcommand, args) != False:
self._post_execute()
except TypeError:
usage()
print(GENERIC_HELP)
def main():
......
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