Merge pull request #138 from jtan189/master

Added ability to list accessible journals.
This commit is contained in:
Manuel Ebert 2014-02-23 21:02:35 -08:00
commit 129595e1c7
2 changed files with 21 additions and 0 deletions

View file

@ -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
-----------------

View file

@ -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(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: