From 9c884f9304d4dae798157390941082cc320a8a87 Mon Sep 17 00:00:00 2001 From: Nora Date: Fri, 26 Apr 2019 22:51:50 +0200 Subject: actions/new: extract path assembly to helper function --- src/actions/new.rs | 13 ++++++++++--- 1 file 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 -- cgit v1.2.3