diff options
author | Daniel Silverstone <dsilvers+gitlab@digital-scurf.org> | 2021-04-12 15:48:33 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers+gitlab@digital-scurf.org> | 2021-04-12 15:48:33 +0000 |
commit | 438c1afb936f0e1e646ff41157fd0494a4312b9e (patch) | |
tree | f0d39eb5e19be1ebf6f3f53ceb83dfd2ae184e93 /src/bin/jt2.rs | |
parent | 924fc1add2de3edac4ad4b1097a3bbbb73d0ad50 (diff) | |
parent | 3a1f32c817f0b3f28afb9c87215a7502fe48864c (diff) | |
download | jt2-438c1afb936f0e1e646ff41157fd0494a4312b9e.tar.gz |
Merge branch 'topics' into 'main'
feat: add "new-topic" command and "new --topic" option
Closes #13
See merge request larswirzenius/jt!12
Diffstat (limited to 'src/bin/jt2.rs')
-rw-r--r-- | src/bin/jt2.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/bin/jt2.rs b/src/bin/jt2.rs index 25a3a13..677bb35 100644 --- a/src/bin/jt2.rs +++ b/src/bin/jt2.rs @@ -3,7 +3,7 @@ use jt2::error::JournalError; use jt2::journal::Journal; use jt2::opt::{Opt, SubCommand}; -use std::path::Path; +use std::path::{Path, PathBuf}; use structopt::StructOpt; fn main() -> anyhow::Result<()> { @@ -17,7 +17,8 @@ fn main() -> anyhow::Result<()> { description, } => init(&config.dirname, &journalname, &description, &config)?, SubCommand::IsJournal => is_journal(&config)?, - SubCommand::New { title } => new_draft(&title, &config)?, + SubCommand::New { title, topic } => new_draft(&title, &topic, &config)?, + SubCommand::NewTopic { path, title } => new_topic(&path, &title, &config)?, SubCommand::Edit { draft } => edit_draft(&draft, &config)?, SubCommand::Finish { draft, basename } => finish_draft(&draft, &basename, &config)?, } @@ -41,9 +42,15 @@ fn is_journal(config: &Configuration) -> anyhow::Result<()> { Ok(()) } -fn new_draft(title: &str, config: &Configuration) -> anyhow::Result<()> { +fn new_draft(title: &str, topic: &Option<PathBuf>, config: &Configuration) -> anyhow::Result<()> { let journal = Journal::new(&config.dirname, &config.entries)?; - journal.new_draft(title, &config.editor)?; + journal.new_draft(title, topic, &config.editor)?; + Ok(()) +} + +fn new_topic(path: &Path, title: &str, config: &Configuration) -> anyhow::Result<()> { + let journal = Journal::new(&config.dirname, &config.entries)?; + journal.new_topic(path, title, &config.editor)?; Ok(()) } |