summaryrefslogtreecommitdiff
path: root/alot/__main__.py
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2016-12-29 16:44:51 +0100
committerLucas Hoffmann <l-m-h@web.de>2017-01-10 08:56:26 +0100
commitdf0f29fb763429729c0db35c72d24e6c2344e99a (patch)
tree8733e2976bb53e1e7941fea241340df65d7b866a /alot/__main__.py
parent5d88264efcf2e2ad846ed92d5578288435c4d26e (diff)
Use the internal parser for initial command line parsing
This again sightly changes the help output and also the possible options for the compose subcommand.
Diffstat (limited to 'alot/__main__.py')
-rw-r--r--alot/__main__.py42
1 files changed, 13 insertions, 29 deletions
diff --git a/alot/__main__.py b/alot/__main__.py
index c7114c8c..4a52f50b 100644
--- a/alot/__main__.py
+++ b/alot/__main__.py
@@ -12,7 +12,7 @@ from alot.settings.errors import ConfigError
from alot.db.manager import DBManager
from alot.ui import UI
from alot.commands import *
-from alot.commands import CommandParseError
+from alot.commands import CommandParseError, COMMANDS
def main():
@@ -41,27 +41,14 @@ def main():
options = parser.parse_args()
if options.command:
# We have a command after the initial options so we also parse that.
+ # But we just use the parser that is already defined for the internal
+ # command that will back this subcommand.
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand')
- search = subparsers.add_parser('search')
- search.add_argument('--sort', default='newest_first',
- help='sort order',
- choices=('oldest_first', 'newest_first',
- 'message_id', 'unsorted'))
- search.add_argument('terms', nargs='+')
- compose = subparsers.add_parser('compose')
- compose.add_argument('--omit_signature', action='store_true',
- help='do not add signature')
- compose.add_argument('--sender', help='From line')
- compose.add_argument('--subject', help='subject line')
- compose.add_argument('--to', help='recipients')
- compose.add_argument('--cc', help='copy to')
- compose.add_argument('--bcc', help='blind copy to')
- compose.add_argument('--template', type=argparse.FileType('r'),
- help='path to template file')
- compose.add_argument('--attach', type=argparse.FileType('r'),
- help='files to attach')
-
+ subparsers.add_parser('search',
+ parents=[COMMANDS['global']['search'][1]])
+ subparsers.add_parser('compose',
+ parents=[COMMANDS['global']['compose'][1]])
command = parser.parse_args(options.command)
else:
command = None
@@ -109,16 +96,13 @@ def main():
dbman = DBManager(path=indexpath, ro=options.read_only)
# determine what to do
- try:
- if command is None:
+ if command is None:
+ try:
cmdstring = settings.get('initial_command')
- elif command.subcommand == 'search':
- query = ' '.join(command.terms)
- cmdstring = 'search --sort {} {}'.format(command.sort, query)
- elif command.subcommand == 'compose':
- cmdstring = ' '.join(options.command)
- except CommandParseError as err:
- sys.exit(err)
+ except CommandParseError as err:
+ sys.exit(err)
+ elif command.subcommand in ('compose', 'search'):
+ cmdstring = ' '.join(options.command)
# set up and start interface
UI(dbman, cmdstring)