Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow users to get the principal id of the current identity #1046

Merged
merged 12 commits into from
Sep 22, 2020
2 changes: 2 additions & 0 deletions src/dfx/src/commands/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use clap::{App, ArgMatches, SubCommand};

mod list;
mod new;
mod principal;
mod remove;
mod rename;
mod r#use;
Expand All @@ -19,6 +20,7 @@ fn builtins() -> Vec<CliCommand> {
CliCommand::new(rename::construct(), rename::exec),
CliCommand::new(r#use::construct(), r#use::exec),
CliCommand::new(whoami::construct(), whoami::exec),
CliCommand::new(principal::construct(), principal::exec),
]
}

Expand Down
16 changes: 16 additions & 0 deletions src/dfx/src/commands/identity/principal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use crate::lib::identity::identity_manager::IdentityManager;
use crate::lib::message::UserMessage;
use clap::{App, ArgMatches, SubCommand};

pub fn construct() -> App<'static, 'static> {
SubCommand::with_name("get-principal-id").about(UserMessage::GetPrincipalId.to_str())
}

pub fn exec(env: &dyn Environment, _args: &ArgMatches<'_>) -> DfxResult {
let identity = IdentityManager::new(env)?.instantiate_selected_identity()?;
let principal_id = identity.sender()?;
println!("{}", principal_id.to_text());
Ok(())
}
3 changes: 3 additions & 0 deletions src/dfx/src/lib/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ user_message!(
// dfx identity whoami
ShowIdentity => "Shows the name of the current identity.",

// dfx identity get-principal-id
GetPrincipalId => "Shows the textual representation of the Principal ID associated with the current identity.",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsgunnlsgunn may I request you review the command name and help text?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

// dfx new
CreateProject => "Creates a new project.",
ProjectName => "Specifies the name of the project to create.",
Expand Down