diff --git a/CHANGELOG.md b/CHANGELOG.md index 7543ce7e61..bf27615ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ The minor version will be incremented upon a breaking change and the patch versi - cli: Ignore non semver solana/agave releases to avoid panic ([#3432](https://github.com/coral-xyz/anchor/pull/3432)). - ts: Fix loading programs with numbers in their names using `workspace` ([#3450](https://github.com/coral-xyz/anchor/pull/3450)). - lang: Remove a potential panic while getting the IDL in `declare_program!` ([#3458](https://github.com/coral-xyz/anchor/pull/3458)). +- cli: Fix altering user-provided lib names ([#3467](https://github.com/coral-xyz/anchor/pull/3467)). ### Breaking diff --git a/cli/src/config.rs b/cli/src/config.rs index f38100aba5..94afa6d075 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -79,24 +79,15 @@ impl Manifest { } pub fn lib_name(&self) -> Result { - if self.lib.is_some() && self.lib.as_ref().unwrap().name.is_some() { - Ok(self - .lib - .as_ref() - .unwrap() - .name - .as_ref() - .unwrap() - .to_string() - .to_snake_case()) - } else { - Ok(self + match &self.lib { + Some(cargo_toml::Product { + name: Some(name), .. + }) => Ok(name.to_owned()), + _ => self .package .as_ref() - .ok_or_else(|| anyhow!("package section not provided"))? - .name - .to_string() - .to_snake_case()) + .ok_or_else(|| anyhow!("package section not provided")) + .map(|pkg| pkg.name.to_snake_case()), } }