mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
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.
This commit is contained in:
parent
c20d5accba
commit
3450967eb3
2 changed files with 21 additions and 0 deletions
|
@ -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).
|
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
|
Composing Entries
|
||||||
-----------------
|
-----------------
|
||||||
|
|
13
jrnl/cli.py
13
jrnl/cli.py
|
@ -26,6 +26,7 @@ PYCRYPTO = install.module_exists("Crypto")
|
||||||
def parse_args(args=None):
|
def parse_args(args=None):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-v', '--version', dest='version', action="store_true", help="prints version information and exits")
|
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 = 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="*")
|
composing.add_argument('text', metavar='', nargs="*")
|
||||||
|
@ -87,6 +88,14 @@ def touch_journal(filename):
|
||||||
util.prompt("[Journal created at {0}]".format(filename))
|
util.prompt("[Journal created at {0}]".format(filename))
|
||||||
open(filename, 'a').close()
|
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):
|
def update_config(config, new_config, scope, force_local=False):
|
||||||
"""Updates a config dict with new values - either global if scope is None
|
"""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,
|
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)
|
config = util.load_and_fix_json(CONFIG_PATH)
|
||||||
install.upgrade_config(config, config_path=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()
|
original_config = config.copy()
|
||||||
# check if the configuration is supported by available modules
|
# check if the configuration is supported by available modules
|
||||||
if config['encrypt'] and not PYCRYPTO:
|
if config['encrypt'] and not PYCRYPTO:
|
||||||
|
|
Loading…
Add table
Reference in a new issue