Skip to content

Commit

Permalink
[aptos-cli] Support profiles in NamedAddresses
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Apr 27, 2022
1 parent e12be41 commit 980c7e6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 26 additions & 1 deletion crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,17 @@ pub struct MovePackageDir {
///
/// Note: This will fail if there are duplicates in the Move.toml file remove those first.
#[clap(long, parse(try_from_str = parse_map), default_value = "")]
pub named_addresses: BTreeMap<String, AccountAddress>,
named_addresses: BTreeMap<String, AccountAddressWrapper>,
}

impl MovePackageDir {
pub fn named_addresses(&self) -> BTreeMap<String, AccountAddress> {
self.named_addresses
.clone()
.into_iter()
.map(|(key, value)| (key, value.account_address))
.collect()
}
}

const PARSE_MAP_SYNTAX_MSG: &str = "Invalid syntax for map. Example: Name=Value,Name2=Value";
Expand Down Expand Up @@ -494,6 +504,21 @@ where
Ok(map)
}

#[derive(Clone, Copy, Debug)]
pub struct AccountAddressWrapper {
pub account_address: AccountAddress,
}

impl FromStr for AccountAddressWrapper {
type Err = CliError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(AccountAddressWrapper {
account_address: load_account_arg(s)?,
})
}
}

/// Loads an account arg and allows for naming based on profiles
pub fn load_account_arg(str: &str) -> Result<AccountAddress, CliError> {
if str.starts_with("0x") {
Expand Down
6 changes: 3 additions & 3 deletions crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct CompilePackage {
impl CompilePackage {
pub async fn execute(self) -> CliTypedResult<Vec<String>> {
let build_config = BuildConfig {
additional_named_addresses: self.move_options.named_addresses.clone(),
additional_named_addresses: self.move_options.named_addresses(),
generate_docs: true,
install_dir: self.move_options.output_dir.clone(),
..Default::default()
Expand All @@ -95,7 +95,7 @@ pub struct TestPackage {
impl TestPackage {
pub async fn execute(self) -> CliTypedResult<&'static str> {
let config = BuildConfig {
additional_named_addresses: self.move_options.named_addresses.clone(),
additional_named_addresses: self.move_options.named_addresses(),
test_mode: true,
install_dir: self.move_options.output_dir.clone(),
..Default::default()
Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct PublishPackage {
impl PublishPackage {
pub async fn execute(self) -> CliTypedResult<aptos_rest_client::Transaction> {
let build_config = BuildConfig {
additional_named_addresses: self.move_options.named_addresses.clone(),
additional_named_addresses: self.move_options.named_addresses(),
generate_abis: false,
generate_docs: true,
install_dir: self.move_options.output_dir.clone(),
Expand Down

0 comments on commit 980c7e6

Please sign in to comment.