summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index cb24474..c5117c8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,8 @@
use anyhow::Result;
+use log::debug;
use std::fs;
use std::path::{Path, PathBuf};
+use std::process::Command;
use structopt::StructOpt;
use thiserror::Error;
@@ -32,6 +34,17 @@ enum JT {
#[structopt(help = "Title of new draft")]
title: String,
},
+ Edit {
+ #[structopt(long, short, help = "Use DIRNAME as the location of the journal")]
+ dirname: PathBuf,
+ #[structopt(
+ long,
+ short,
+ help = "Invoke EDITOR for user to edit draft",
+ default_value = "/usr/bin/editor"
+ )]
+ editor: String,
+ },
Finish {
#[structopt(long, short, help = "Use DIRNAME as the location of the journal")]
dirname: PathBuf,
@@ -45,6 +58,7 @@ enum JournalError {
}
fn main() -> Result<()> {
+ pretty_env_logger::init_custom_env("JT_LOG");
let opt = JT::from_args();
match opt {
JT::Init {
@@ -58,6 +72,7 @@ fn main() -> Result<()> {
dirname,
editor,
} => new_draft(&title, &dirname, &editor)?,
+ JT::Edit { dirname, editor } => edit_draft(&dirname, &editor)?,
JT::Finish { dirname } => finish_draft(&dirname)?,
}
Ok(())
@@ -86,6 +101,17 @@ fn new_draft(title: &str, dirname: &Path, editor: &str) -> anyhow::Result<()> {
Ok(())
}
+fn edit_draft(dirname: &Path, editor: &str) -> anyhow::Result<()> {
+ debug!("edit_draft: dirname={:?}", dirname);
+ debug!("edit_draft: editor={:?}", editor);
+ let drafts = dirname.join("drafts");
+ let draft_filename = drafts.join("0.md");
+ debug!("edit_draft: draft_filename={:?}", draft_filename);
+ let status = Command::new(editor).arg(draft_filename).status()?;
+ debug!("edit_draft: editor finished");
+ Ok(())
+}
+
fn finish_draft(dirname: &Path) -> anyhow::Result<()> {
let drafts = dirname.join("drafts");
let draft = drafts.join("0.md");