Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make journal selection behavior more consistent when there's a colon with no date #1164

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions features/multiple_journals.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ Feature: Multiple journals
And journal "work" should have 1 entry
And journal "work" should contain "2012-07-23"

Scenario: Write to specified journal without a timestamp but with colon
Given we use the config "multiple.yaml"
When we run "jrnl work : a long day in the office"
Then journal "default" should have 2 entries
And journal "work" should have 1 entry
And journal "work" should contain "a long day in the office"

Scenario: Write to specified journal without a timestamp but with colon
Given we use the config "multiple.yaml"
When we run "jrnl work: a long day in the office"
Then journal "default" should have 2 entries
And journal "work" should have 1 entry
And journal "work" should contain "a long day in the office"

Scenario: Create new journals as required
Given we use the config "multiple.yaml"
Then journal "ideas" should not exist
Expand Down
16 changes: 12 additions & 4 deletions jrnl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,18 @@ def update_config(config, new_config, scope, force_local=False):

def get_journal_name(args, config):
args.journal_name = DEFAULT_JOURNAL_KEY
if args.text and args.text[0] in config["journals"]:
args.journal_name = args.text[0]
args.text = args.text[1:]
elif DEFAULT_JOURNAL_KEY not in config["journals"]:

# The first arg might be a journal name
if args.text:
potential_journal_name = args.text[0]
if potential_journal_name[-1] == ":":
potential_journal_name = potential_journal_name[0:-1]

if potential_journal_name in config["journals"]:
args.journal_name = potential_journal_name
args.text = args.text[1:]

if args.journal_name not in config["journals"]:
print("No default journal configured.", file=sys.stderr)
print(list_journals(config), file=sys.stderr)
sys.exit(1)
Expand Down