diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebd937..30645fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support negated globs in `workspace_members` field by @daimond113 - Make `includes` use glob patterns by @daimond113 - Use symlinks for workspace dependencies to not require reinstalling by @daimond113 +- Add `auth token` command to print the auth token for the index by @daimond113 ### Fixed - Install dependencies of packages in `x` command diff --git a/docs/src/content/docs/reference/cli.mdx b/docs/src/content/docs/reference/cli.mdx index 7784c22..722b490 100644 --- a/docs/src/content/docs/reference/cli.mdx +++ b/docs/src/content/docs/reference/cli.mdx @@ -34,6 +34,10 @@ Removes the stored token for the index. Prints the username of the currently authenticated user of the index. Only works if the token is a GitHub token. +### `pesde auth token` + +Prints the token for the index. + ## `pesde config` Configuration-related commands. diff --git a/src/cli/commands/auth/mod.rs b/src/cli/commands/auth/mod.rs index cbb1160..e548150 100644 --- a/src/cli/commands/auth/mod.rs +++ b/src/cli/commands/auth/mod.rs @@ -4,6 +4,7 @@ use pesde::{errors::ManifestReadError, Project, DEFAULT_INDEX_NAME}; mod login; mod logout; +mod token; mod whoami; #[derive(Debug, Args)] @@ -25,6 +26,8 @@ pub enum AuthCommands { /// Prints the username of the currently logged-in user #[clap(name = "whoami")] WhoAmI(whoami::WhoAmICommand), + /// Prints the token for an index + Token(token::TokenCommand), } impl AuthSubcommand { @@ -64,6 +67,7 @@ impl AuthSubcommand { AuthCommands::Login(login) => login.run(index_url, project, reqwest).await, AuthCommands::Logout(logout) => logout.run(index_url).await, AuthCommands::WhoAmI(whoami) => whoami.run(index_url, reqwest).await, + AuthCommands::Token(token) => token.run(index_url).await, } } } diff --git a/src/cli/commands/auth/token.rs b/src/cli/commands/auth/token.rs new file mode 100644 index 0000000..e3f824e --- /dev/null +++ b/src/cli/commands/auth/token.rs @@ -0,0 +1,22 @@ +use crate::cli::auth::get_tokens; +use clap::Args; + +#[derive(Debug, Args)] +pub struct TokenCommand {} + +impl TokenCommand { + pub async fn run(self, index_url: gix::Url) -> anyhow::Result<()> { + let tokens = get_tokens().await?; + let token = match tokens.0.get(&index_url) { + Some(token) => token, + None => { + println!("not logged in into {index_url}"); + return Ok(()); + } + }; + + println!("token for {index_url}: \"{token}\""); + + Ok(()) + } +}