-
-
Notifications
You must be signed in to change notification settings - Fork 524
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
Add ability to use template with --template
#1667
Conversation
a881181
to
8c4550d
Compare
@@ -39,6 +39,7 @@ def expected_args(**kwargs): | |||
"start_date": None, | |||
"strict": False, | |||
"tags": False, | |||
"template": None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's odd that the tests fail when this value is set to False
. I didn't expect that.
f5ae7b7
to
813b4e7
Compare
--template
--template
--template
and $JRNL_TEMPLATE_DIR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR. I like the --template
idea and I think it's a lot more fluent and easy to use than the current method of --config-overide template file
. I also really appreciate the changes to the docs here too.
These are a few different changes, though, and I feel particularly hesitant about the environment variable change. Could you remove that part from this PR? I think we need a broader conversation about how jrnl could handle environment variables, and I think that will take some time, but I don't want it to hold up this nice --template
change.
I think we could use some BDD tests for --template
as well. There's a new template.feature
file in there that could use these tests. Let me know if you'd like any help with that.
06a785a
to
3f2090e
Compare
--template
and $JRNL_TEMPLATE_DIR
--template
c08301a
to
0b8380d
Compare
I've made the default template path I'm unsure how to handle two test cases:
Do you have any ideas about how I can mock that behavior out? And it's unclear to me why |
Update jrnl/args.py
--template
--template
This looks nice! Thanks for your work on this. I'll plan on taking a deeper look at this later but wanted to get to your questions for now.
My instinct would be to create a new fixture in
I'm not sure. I'm looking through other tests we've done with path inputs, such as
Due to #1653, jrnl now ignores entries that are exactly the same as the template, so the entry isn't being added. You can copy a couple lines from an earlier test in template.feature to add some text to the entry and get it working:
|
Fixed.
Makes sense to me. What I've got in the last commit seems like it should work, but the
I think Pathlib does all the work here, and it's acceptable to drop this test entirely. Plus, the risk is low: worst case, a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one note about a long function. Otherwise, it looks good. Thanks for your work on this!
@@ -123,9 +124,78 @@ def _is_write_mode(args: "Namespace", config: dict, **kwargs) -> bool: | |||
return write_mode | |||
|
|||
|
|||
def _read_template_file(template_arg: str, template_path_from_config: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that this function should be split up into shorter functions and at least some of them should be moved elsewhere. editor.py
has previously been the only file involved with templates and I think some of these concerns belong there. Ideally, the controller is just telling other classes what to do, rather than doing the work itself.
Though let me know if you're not interested in that work -- we're happy to do it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that this function should be split up into shorter functions and at least some of them should be moved elsewhere.
Seems reasonable enough to me. I don't have a strong opinion on it.
Though let me know if you're not interested in that work -- we're happy to do it as well.
I'll pass on implementing it myself :) I'm already running a serious open-source time deficit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be alright shipping this as is, and cutting a follow-up task for the changes you suggested, @micahellison.
Thanks for the reviews!
@@ -123,9 +124,78 @@ def _is_write_mode(args: "Namespace", config: dict, **kwargs) -> bool: | |||
return write_mode | |||
|
|||
|
|||
def _read_template_file(template_arg: str, template_path_from_config: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that this function should be split up into shorter functions and at least some of them should be moved elsewhere.
Seems reasonable enough to me. I don't have a strong opinion on it.
Though let me know if you're not interested in that work -- we're happy to do it as well.
I'll pass on implementing it myself :) I'm already running a serious open-source time deficit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your work on this!
You can use this CLI argument in two ways:
I've updated the docs for the Templates feature.
Also, see https://github.com/alichtman/jrnl-templates
Checklist
for the same issue.