From 4077c33adfdacaf0ed68657a1955a7b69a78d373 Mon Sep 17 00:00:00 2001 From: Vlad Stepanov <8uk.8ak@gmail.com> Date: Thu, 15 Jun 2023 14:29:40 +0400 Subject: Builder interface for History objects (#933) * [feature] store env variables in History records WIP: remove `HistoryWithoutDelete`, add some docstrings, tests * Create History objects through builders. Assure in compile-time that all required fields are set for the given construction scenario * (from #882) split Cmd::run into subfns * Update `History` doc * remove rmp-serde from history * update warning --------- Co-authored-by: Conrad Ludgate --- atuin-client/src/import/zsh.rs | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'atuin-client/src/import/zsh.rs') diff --git a/atuin-client/src/import/zsh.rs b/atuin-client/src/import/zsh.rs index 19917daf..e98819e2 100644 --- a/atuin-client/src/import/zsh.rs +++ b/atuin-client/src/import/zsh.rs @@ -82,17 +82,12 @@ impl Importer for Zsh { let offset = chrono::Duration::seconds(counter); counter += 1; - h.push(History::new( - now - offset, // preserve ordering - command.trim_end().to_string(), - String::from("unknown"), - -1, - -1, - None, - None, - None, - )) - .await?; + let imported = History::import() + // preserve ordering + .timestamp(now - offset) + .command(command.trim_end().to_string()); + + h.push(imported.build().into()).await?; } } } @@ -113,19 +108,15 @@ fn parse_extended(line: &str, counter: i64) -> History { let time = Utc.timestamp(time, 0); let time = time + offset; + // use nanos, because why the hell not? we won't display them. let duration = duration.parse::().map_or(-1, |t| t * 1_000_000_000); - // use nanos, because why the hell not? we won't display them. - History::new( - time, - command.trim_end().to_string(), - String::from("unknown"), - 0, // assume 0, we have no way of knowing :( - duration, - None, - None, - None, - ) + let imported = History::import() + .timestamp(time) + .command(command.trim_end().to_string()) + .duration(duration); + + imported.build().into() } #[cfg(test)] -- cgit v1.3.1