From 3450967eb3bedb99c8c79463e73db8e154094771 Mon Sep 17 00:00:00 2001 From: Josh Tan Date: Fri, 21 Feb 2014 13:56:07 -0600 Subject: [PATCH] Added ability to list accessible journals. Previously, if a user forgot the exact name of a journal, they could check the configuration file to retrieve this information. This patch adds support for performing this task using the jrnl interface. The newly added '-ls' option retrieves the available journals from the jrnl configuration files and displays each journal name on a separate line. This patch also updates the jrnl help display and the usage documentation to reflect these changes. --- docs/usage.rst | 8 ++++++++ jrnl/cli.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/docs/usage.rst b/docs/usage.rst index 0b7f487f..2f42b9c2 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -7,6 +7,14 @@ Basic Usage We intentionally break a convention on command line arguments: all arguments starting with a `single dash` will `filter` your journal before viewing it, and can be combined arbitrarily. Arguments with a `double dash` will control how your journal is displayed or exported and are mutually exclusive (ie. you can only specify one way to display or export your journal at a time). +Listing Journals +---------------- + +You can list the journals accessible by jrnl:: + + jrnl -ls + +The journals displayed correspond to those specified in the jrnl configuration file. Composing Entries ----------------- diff --git a/jrnl/cli.py b/jrnl/cli.py index fe00977d..c092f4d1 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -26,6 +26,7 @@ PYCRYPTO = install.module_exists("Crypto") def parse_args(args=None): parser = argparse.ArgumentParser() parser.add_argument('-v', '--version', dest='version', action="store_true", help="prints version information and exits") + parser.add_argument('-ls', dest='ls', action="store_true", help="displays accessible journals") composing = parser.add_argument_group('Composing', 'To write an entry simply write it on the command line, e.g. "jrnl yesterday at 1pm: Went to the gym."') composing.add_argument('text', metavar='', nargs="*") @@ -87,6 +88,14 @@ def touch_journal(filename): util.prompt("[Journal created at {0}]".format(filename)) open(filename, 'a').close() +def list_journals(config): + """List the journals specified in the configuration file""" + + sep = "\n" + journal_list = sep.join(j for j in config['journals']) + + return journal_list + def update_config(config, new_config, scope, force_local=False): """Updates a config dict with new values - either global if scope is None or config['journals'][scope] is just a string pointing to a journal file, @@ -113,6 +122,10 @@ def run(manual_args=None): config = util.load_and_fix_json(CONFIG_PATH) install.upgrade_config(config, config_path=CONFIG_PATH) + if args.ls: + print(util.py2encode(list_journals(config))) + sys.exit(0) + original_config = config.copy() # check if the configuration is supported by available modules if config['encrypt'] and not PYCRYPTO: