Skip to content

Commit 157e93b

Browse files
committed
whoami
1 parent 8c01a23 commit 157e93b

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ pub mod update;
2626
pub mod upload;
2727
pub mod variables;
2828
pub mod version;
29+
pub mod whoami;

src/commands/project/id.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use super::*;
2+
use crate::utils::config::Config;
3+
4+
#[derive(Parser)]
5+
pub struct Args {}
6+
7+
pub async fn command(_args: Args) -> Result<()> {
8+
let config = Config::get()?;
9+
let project = config.get_project();
10+
match project {
11+
Ok(p) => println!("Project ID:\n\t{}", p.project_id),
12+
Err(_) => println!("No project set"),
13+
}
14+
Ok(())
15+
}

src/commands/project/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub(super) use colored::Colorize;
77
pub mod add_user;
88
pub mod list_users;
99
pub mod remove_user;
10+
pub mod id;
1011

1112
use crate::commands_enum;
1213
use clap::Subcommand;
@@ -21,7 +22,7 @@ pub struct Args {
2122
json: bool,
2223
}
2324

24-
commands_enum!(add_user, remove_user, list_users);
25+
commands_enum!(add_user, remove_user, list_users, id);
2526

2627
pub async fn command(args: Args) -> Result<()> {
2728
Commands::exec(args).await?;

src/commands/whoami.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::*;
2+
use crate::utils::config::Config;
3+
4+
/// Print the primary key fingerprint and uuid
5+
#[derive(Parser)]
6+
pub struct Args {}
7+
8+
pub async fn command(_args: Args) -> Result<()> {
9+
let config = Config::get().context("Failed to get config")?;
10+
let primary_key = config.get_key(&config.primary_key)?;
11+
println!(
12+
"{} - {}",
13+
&primary_key.fingerprint[..8],
14+
primary_key.uuid.unwrap_or("Not on remote".into())
15+
);
16+
Ok(())
17+
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ commands_enum!(
3333
auth, export, gen, import, link, list_keys, run, set, shell, unlink, unset,
3434
update, upload, variables, version,
3535
// commands with subcommands
36-
config, delete, get, keyring, new, project
36+
config, delete, get, keyring, new, project, whoami
3737
);
3838

3939
fn spawn_update_task(

0 commit comments

Comments
 (0)