Skip to content

Commit

Permalink
cli: Update programs in Anchor.toml when using anchor new (coral-…
Browse files Browse the repository at this point in the history
  • Loading branch information
CanardMandarin authored Jun 5, 2023
1 parent 383e440 commit 1902b8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Fix inability to use identifiers `program_id`, `accounts`, `ix_data`, `remaining_accounts` in instruction arguments ([#2464](https://github.com/coral-xyz/anchor/pull/2464))
- cli: Fix incorrect `metadata.address` generation in IDL after deploying with a custom keypair ([#2485](https://github.com/coral-xyz/anchor/pull/2485))
- cli: IDL commands no longer hang when the payer doesn't have funds to pay for the transaction fee ([#2492](https://github.com/coral-xyz/anchor/pull/2492))
- cli: Fix `anchor new` not updating `Anchor.toml` ([#2516](https://github.com/coral-xyz/anchor/pull/2516)).

### Breaking

Expand Down
28 changes: 24 additions & 4 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,31 @@ fn new(cfg_override: &ConfigOverride, solidity: bool, name: String) -> Result<()
}
Some(parent) => {
std::env::set_current_dir(parent)?;
if solidity {
new_solidity_program(&name)?;
} else {
new_rust_program(&name)?;

let cluster = cfg.provider.cluster.clone();
let programs = cfg.programs.entry(cluster).or_insert(BTreeMap::new());
if programs.contains_key(&name) {
return Err(anyhow!("Program already exists"));
}

programs.insert(
name.clone(),
ProgramDeployment {
address: if solidity {
new_solidity_program(&name)?;
solidity_template::default_program_id()
} else {
new_rust_program(&name)?;
rust_template::get_or_create_program_id(&name)
},
path: None,
idl: None,
},
);

let toml = cfg.to_string();
fs::write("Anchor.toml", toml)?;

println!("Created new program.");
}
};
Expand Down

0 comments on commit 1902b8e

Please sign in to comment.