From a3afa112ab4ab122121219814eead34fa62a04c7 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Fri, 21 Feb 2020 18:36:16 -0800 Subject: [PATCH] Clean up shortcut for Limit This piece of code has bothered me for more than 6 years! (See #131) - this moves parsing arguments to where it belongs. --- jrnl/cli.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/jrnl/cli.py b/jrnl/cli.py index 1c53dc29..408f3518 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -15,6 +15,7 @@ from .util import ERROR_COLOR, RESET_COLOR, UserAbort import jrnl import argparse import sys +import re import logging log = logging.getLogger(__name__) @@ -173,7 +174,11 @@ def parse_args(args=None): action="store_true", ) - return parser.parse_args(args) + # Handle '-123' as a shortcut for '-n 123' + num = re.compile(r"^-(\d+)$") + if args is None: + args = sys.argv[1:] + return parser.parse_args([num.sub(r"-n \1", a) for a in args]) def guess_mode(args, config): @@ -309,14 +314,6 @@ def run(manual_args=None): config = util.scope_config(config, journal_name) - # If the first remaining argument looks like e.g. '-3', interpret that as a limiter - if not args.limit and args.text and args.text[0].startswith("-"): - try: - args.limit = int(args.text[0].lstrip("-")) - args.text = args.text[1:] - except ValueError: - pass - log.debug('Using journal "%s"', journal_name) mode_compose, mode_export, mode_import = guess_mode(args, config)