diff options
Diffstat (limited to 'crates/turtle/src/atuin_client/history.rs')
| -rw-r--r-- | crates/turtle/src/atuin_client/history.rs | 61 |
1 files changed, 13 insertions, 48 deletions
diff --git a/crates/turtle/src/atuin_client/history.rs b/crates/turtle/src/atuin_client/history.rs index 5e2f89f2..1f89cd71 100644 --- a/crates/turtle/src/atuin_client/history.rs +++ b/crates/turtle/src/atuin_client/history.rs @@ -61,24 +61,34 @@ pub(crate) struct History { /// /// Stored as `client_id` in the database. pub(crate) id: HistoryId, + /// When the command was run. pub(crate) timestamp: OffsetDateTime, + /// How long the command took to run. pub(crate) duration: i64, + /// The exit code of the command. pub(crate) exit: i64, + /// The command that was run. pub(crate) command: String, + /// The current working directory when the command was run. pub(crate) cwd: String, + /// The session ID, associated with a terminal session. pub(crate) session: String, + /// The hostname of the machine the command was run on. pub(crate) hostname: String, + /// Who wrote this command (human user or automation/agent identity). pub(crate) author: String, + /// Optional rationale for why the command was executed. pub(crate) intent: Option<String>, + /// Timestamp, which is set when the entry is deleted, allowing a soft delete. pub(crate) deleted_at: Option<OffsetDateTime>, } @@ -87,7 +97,7 @@ pub(crate) struct History { pub(crate) struct HistoryStats { /// The command that was ran after this one in the session pub(crate) next: Option<History>, - /// + /// The command that was ran before this one in the session pub(crate) previous: Option<History>, @@ -333,7 +343,7 @@ impl History { Ok(History { id: id.to_owned().into(), - timestamp: OffsetDateTime::from_unix_timestamp_nanos(timestamp as i128)?, + timestamp: OffsetDateTime::from_unix_timestamp_nanos(i128::from(timestamp))?, duration, exit, command: command.to_owned(), @@ -343,7 +353,7 @@ impl History { author: author.unwrap_or_else(|| Self::author_from_hostname(hostname)), intent, deleted_at: deleted_at - .map(|t| OffsetDateTime::from_unix_timestamp_nanos(t as i128)) + .map(|t| OffsetDateTime::from_unix_timestamp_nanos(i128::from(t))) .transpose()?, }) } @@ -357,51 +367,6 @@ impl History { } } - /// Builder for a history entry that is imported from shell history. - /// - /// The only two required fields are `timestamp` and `command`. - /// - /// ## Examples - /// ``` - /// use crate::atuin_client::history::History; - /// - /// let history: History = History::import() - /// .timestamp(time::OffsetDateTime::now_utc()) - /// .command("ls -la") - /// .build() - /// .into(); - /// ``` - /// - /// If shell history contains more information, it can be added to the builder: - /// ``` - /// use crate::atuin_client::history::History; - /// - /// let history: History = History::import() - /// .timestamp(time::OffsetDateTime::now_utc()) - /// .command("ls -la") - /// .cwd("/home/user") - /// .exit(0) - /// .duration(100) - /// .build() - /// .into(); - /// ``` - /// - /// Unknown command or command without timestamp cannot be imported, which - /// is forced at compile time: - /// - /// ```compile_fail - /// use crate::atuin_client::history::History; - /// - /// // this will not compile because timestamp is missing - /// let history: History = History::import() - /// .command("ls -la") - /// .build() - /// .into(); - /// ``` - pub(crate) fn import() -> builder::HistoryImportedBuilder { - builder::HistoryImported::builder() - } - /// Builder for a history entry that is captured via hook. /// /// This builder is used only at the `start` step of the hook, |
