ez_token/cli/history/mod.rs
1//! History management for interactive CLI prompts.
2
3use dialoguer::BasicHistory;
4
5/// File-based history persistence.
6pub mod file;
7
8/// Identifies which input field's history to load or save.
9///
10/// Each variant maps to a separate history file on disk, allowing
11/// independent completion history for each prompt.
12#[derive(Clone, Copy)]
13pub enum HistoryKey {
14 /// History for the Tenant ID prompt.
15 Tenant,
16 /// History for the Client ID prompt.
17 Client,
18 /// History for the Scopes prompt.
19 Scopes,
20 /// Auth0 domain prompt history.
21 Domain,
22 /// Auth0 audience prompt history.
23 Audience,
24}
25
26impl HistoryKey {
27 /// Returns the filename stem used for this key's history file.
28 ///
29 /// For example, [`HistoryKey::Tenant`] returns `"tenant"`,
30 /// which maps to `.tenant_history` on disk.
31 pub fn as_str(&self) -> &'static str {
32 match self {
33 HistoryKey::Tenant => "tenant",
34 HistoryKey::Client => "client",
35 HistoryKey::Scopes => "scopes",
36 HistoryKey::Domain => "domain",
37 HistoryKey::Audience => "audience",
38 }
39 }
40}
41
42/// Abstraction over loading and saving prompt history.
43///
44/// This trait allows the history backend to be swapped out — for example,
45/// using an in-memory implementation in tests instead of writing to disk
46/// via [`file::FileHistoryManager`].
47pub trait HistoryManager {
48 /// Loads the history for the given [`HistoryKey`].
49 ///
50 /// Returns an empty [`BasicHistory`] if the history file does not exist
51 /// or cannot be read.
52 fn load(&self, key: HistoryKey) -> BasicHistory;
53
54 /// Persists the current history for the given [`HistoryKey`].
55 ///
56 /// Failures are silently ignored to avoid interrupting the CLI flow.
57 fn save(&self, key: HistoryKey, history: &BasicHistory);
58}