mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
feat: add uth token command
This commit is contained in:
parent
3aadebf3ea
commit
cb17c419d0
4 changed files with 31 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/cli/commands/auth/token.rs
Normal file
22
src/cli/commands/auth/token.rs
Normal file
|
@ -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(())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue