Skip to content

Commit

Permalink
cli: Build IDL if there is only one program when using the `idl build…
Browse files Browse the repository at this point in the history
…` command (#3275)
  • Loading branch information
acheroncrypto authored Sep 25, 2024
1 parent 0c306c2 commit ef542f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- cli: Add completions command to generate shell completions via the clap_complete crate ([#3251](https://github.com/coral-xyz/anchor/pull/3251)).
- cli: Always convert IDLs ([#3265](https://github.com/coral-xyz/anchor/pull/3265)).
- cli: Check whether the `idl-build` feature exists when using the `idl build` command ([#3273](https://github.com/coral-xyz/anchor/pull/3273)).
- cli: Build IDL if there is only one program when using the `idl build` command ([#3275](https://github.com/coral-xyz/anchor/pull/3275)).

### Fixes

Expand Down
15 changes: 10 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2728,11 +2728,16 @@ fn idl_build(
Some(name) => cfg.get_program(&name)?.path,
None => {
let current_dir = std::env::current_dir()?;
cfg.read_all_programs()?
.into_iter()
.find(|program| program.path == current_dir)
.ok_or_else(|| anyhow!("Not in a program directory"))?
.path
let programs = cfg.read_all_programs()?;
if programs.len() == 1 {
programs.into_iter().next().unwrap().path
} else {
programs
.into_iter()
.find(|program| program.path == current_dir)
.ok_or_else(|| anyhow!("Not in a program directory"))?
.path
}
}
};
std::env::set_current_dir(program_path)?;
Expand Down

0 comments on commit ef542f5

Please sign in to comment.