mise 2026.9.4

Dev tools, env vars, and tasks in one CLI
use crate::cli::token::github::Github;

/// Display the GitHub token mise will use for a given host
///
/// Shows which token source mise would use, useful for debugging
/// authentication issues. The token is masked by default.
#[derive(Debug, usage_rs::Args)]
#[usage(
    verbatim_doc_comment,
    example(
        r###"mise github token
github.com: ghp_…xxxx (source: GITHUB_TOKEN)"###
    ),
    example(
        r###"mise github token --unmask
github.com: ghp_xxxxxxxxxxxx (source: GITHUB_TOKEN)"###
    ),
    example(
        r###"mise github token github.mycompany.com
github.mycompany.com: (none)"###
    ),
    hide = true
)]
pub(crate) struct Token {
    /// GitHub hostname
    #[usage(default = "github.com")]
    host: String,

    /// Force native GitHub OAuth device flow instead of normal token resolution
    #[usage(long)]
    oauth: bool,

    /// Print only the token value
    #[usage(long)]
    raw: bool,

    /// Mint a fresh OAuth token even if the cached one has not
    /// expired, via the refresh-token grant or a new device-code flow
    #[usage(long, requires = "oauth")]
    refresh: bool,

    /// Show the full unmasked token
    #[usage(long)]
    unmask: bool,
}

impl Token {
    pub(crate) fn run(self) -> eyre::Result<()> {
        Github::from(self).run()
    }
}

impl From<Token> for Github {
    fn from(t: Token) -> Self {
        Github {
            host: t.host,
            git_credential: None,
            oauth: t.oauth,
            refresh: t.refresh,
            raw: t.raw,
            unmask: t.unmask,
        }
    }
}