diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-04-26 22:51:50 +0200 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-04-26 22:51:50 +0200 |
commit | 9c884f9304d4dae798157390941082cc320a8a87 (patch) | |
tree | 769da53c2de4e533008beb9db37da5a3da615ccc | |
parent | 6436ac3242f97a9d125ae88cd6ef6622dde73f52 (diff) |
actions/new: extract path assembly to helper function
-rw-r--r-- | src/actions/new.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/actions/new.rs b/src/actions/new.rs index 39cfe0b..e75dd34 100644 --- a/src/actions/new.rs +++ b/src/actions/new.rs @@ -5,6 +5,7 @@ use crate::icalwrap::{IcalTime, IcalVCalendar}; use crate::khline::KhLine; use crate::utils::{fileutil, misc}; use crate::KhResult; +use std::path::PathBuf; use structopt::StructOpt; #[derive(Debug, StructOpt)] @@ -96,9 +97,7 @@ pub fn do_new(args: &NewArgs) -> KhResult<()> { let uid = misc::make_new_uid(); let ep = EventProperties::parse_from_args(args)?; - let mut path = defaults::get_caldir(); - path.push(&ep.calendar); - path.push(&(uid.clone() + ".ics")); + let path = assemble_file_path(&ep.calendar, &uid); let new_cal = IcalVCalendar::from_str(TEMPLATE_EVENT, Some(&path))? .with_uid(&uid)? @@ -116,6 +115,14 @@ pub fn do_new(args: &NewArgs) -> KhResult<()> { Ok(()) } +fn assemble_file_path(cal_name: &String, uid: &String ) -> PathBuf { + let mut path = defaults::get_caldir(); + path.push(cal_name); + path.push(uid); + path.set_extension("ics"); + path +} + impl IcalVCalendar { fn with_eventprops(self, ep: &EventProperties) -> Self { self |