ez-token 0.1.0

CLI tool for generating OAuth2 access tokens via PKCE and Client Credentials for Microsoft Entra ID and Auth0
Documentation
//! History management for interactive CLI prompts.

use dialoguer::BasicHistory;

/// File-based history persistence.
pub mod file;

/// Identifies which input field's history to load or save.
///
/// Each variant maps to a separate history file on disk, allowing
/// independent completion history for each prompt.
#[derive(Clone, Copy)]
pub enum HistoryKey {
    /// History for the Tenant ID prompt.
    Tenant,
    /// History for the Client ID prompt.
    Client,
    /// History for the Scopes prompt.
    Scopes,
    /// Auth0 domain prompt history.
    Domain,
    /// Auth0 audience prompt history.
    Audience,
}

impl HistoryKey {
    /// Returns the filename stem used for this key's history file.
    ///
    /// For example, [`HistoryKey::Tenant`] returns `"tenant"`,
    /// which maps to `.tenant_history` on disk.
    pub fn as_str(&self) -> &'static str {
        match self {
            HistoryKey::Tenant => "tenant",
            HistoryKey::Client => "client",
            HistoryKey::Scopes => "scopes",
            HistoryKey::Domain => "domain",
            HistoryKey::Audience => "audience",
        }
    }
}

/// Abstraction over loading and saving prompt history.
///
/// This trait allows the history backend to be swapped out — for example,
/// using an in-memory implementation in tests instead of writing to disk
/// via [`file::FileHistoryManager`].
pub trait HistoryManager {
    /// Loads the history for the given [`HistoryKey`].
    ///
    /// Returns an empty [`BasicHistory`] if the history file does not exist
    /// or cannot be read.
    fn load(&self, key: HistoryKey) -> BasicHistory;

    /// Persists the current history for the given [`HistoryKey`].
    ///
    /// Failures are silently ignored to avoid interrupting the CLI flow.
    fn save(&self, key: HistoryKey, history: &BasicHistory);
}