diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-01-10 13:27:37 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-01-25 10:37:27 -0800 |
commit | 83d706d86142c693cdc92c4824b38c96ad0e4988 (patch) | |
tree | e407d744d29f5acf1023d3b1eddf8cd41a012158 /alot/__main__.py | |
parent | 03371459f0372f312073b7af84f5754526d04f10 (diff) |
alot/__main__: use the new validators instead of type=argparse.FileType
This replaces the use of type as a validator with the validator keyword.
This is both cleaner and allows the type keyword to be used for setting
the type (if it ever becomes necessary). It also has the advantage of
not opening and closing the file (thus truncating it) or breaking pipes
(like a fifo).
Fixes #996
Diffstat (limited to 'alot/__main__.py')
-rw-r--r-- | alot/__main__.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/alot/__main__.py b/alot/__main__.py index 637097e9..48826f53 100644 --- a/alot/__main__.py +++ b/alot/__main__.py @@ -15,6 +15,7 @@ from alot.db.manager import DBManager from alot.ui import UI from alot.commands import * from alot.commands import CommandParseError, COMMANDS +from alot.utils import argparse as cargparse _SUBCOMMANDS = ['search', 'compose', 'bufferlist', 'taglist', 'pyshell'] @@ -27,23 +28,29 @@ def parser(): version=alot.__version__) parser.add_argument('-r', '--read-only', action='store_true', help='open db in read only mode') - parser.add_argument('-c', '--config', help='config file', - type=lambda x: argparse.FileType('r')(x).name) + parser.add_argument('-c', '--config', + action=cargparse.ValidatedStoreAction, + validator=cargparse.require_file, + help='config file') parser.add_argument('-n', '--notmuch-config', default=os.environ.get( 'NOTMUCH_CONFIG', os.path.expanduser('~/.notmuch-config')), - type=lambda x: argparse.FileType('r')(x).name, + action=cargparse.ValidatedStoreAction, + validator=cargparse.require_file, help='notmuch config') parser.add_argument('-C', '--colour-mode', choices=(1, 16, 256), type=int, default=256, help='terminal colour mode [default: %(default)s].') - parser.add_argument('-p', '--mailindex-path', #type=directory, + parser.add_argument('-p', '--mailindex-path', + action=cargparse.ValidatedStoreAction, + validator=cargparse.require_dir, help='path to notmuch index') parser.add_argument('-d', '--debug-level', default='info', choices=('debug', 'info', 'warning', 'error'), help='debug log [default: %(default)s]') parser.add_argument('-l', '--logfile', default='/dev/null', - type=lambda x: argparse.FileType('w')(x).name, + action=cargparse.ValidatedStoreAction, + validator=cargparse.optional_file_like, help='logfile [default: %(default)s]') # We will handle the subcommands in a seperate run of argparse as argparse # does not support optional subcommands until now. |