Skip to content

Commit

Permalink
cli: add option to specify program keypair when using 'anchor deploy' (
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-schaaf authored Apr 20, 2022
1 parent 509ef94 commit 700ed26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The minor version will be incremented upon a breaking change and the patch versi

## [Unreleased]

### Features

* cli: Add `--program-keypair` to `anchor deploy` ([#1786](https://github.com/project-serum/anchor/pull/1786)).

### Fixes

* cli: Move `overflow-checks` into workspace `Cargo.toml` so that it will not be ignored by compiler ([#1806](https://github.com/project-serum/anchor/pull/1806)).
Expand Down
24 changes: 19 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ pub enum Command {
Clean,
/// Deploys each program in the workspace.
Deploy {
/// Only deploy this program
#[clap(short, long)]
program_name: Option<String>,
/// Keypair of the program (filepath) (requires program-name)
#[clap(long, requires = "program-name")]
program_keypair: Option<String>,
},
/// Runs the deploy migration script.
Migrate,
Expand Down Expand Up @@ -415,7 +419,10 @@ pub fn entry(opts: Opts) -> Result<()> {
cargo_args,
),
Command::Clean => clean(&opts.cfg_override),
Command::Deploy { program_name } => deploy(&opts.cfg_override, program_name),
Command::Deploy {
program_name,
program_keypair,
} => deploy(&opts.cfg_override, program_name, program_keypair),
Command::Expand {
program_name,
cargo_args,
Expand Down Expand Up @@ -1839,7 +1846,7 @@ fn test(
// In either case, skip the deploy if the user specifies.
let is_localnet = cfg.provider.cluster == Cluster::Localnet;
if (!is_localnet || skip_local_validator) && !skip_deploy {
deploy(cfg_override, None)?;
deploy(cfg_override, None, None)?;
}
let mut is_first_suite = true;
if cfg.scripts.get("test").is_some() {
Expand Down Expand Up @@ -2338,7 +2345,11 @@ fn clean(cfg_override: &ConfigOverride) -> Result<()> {
Ok(())
}

fn deploy(cfg_override: &ConfigOverride, program_str: Option<String>) -> Result<()> {
fn deploy(
cfg_override: &ConfigOverride,
program_str: Option<String>,
program_keypair: Option<String>,
) -> Result<()> {
with_workspace(cfg_override, |cfg| {
let url = cluster_url(cfg, &cfg.test_validator);
let keypair = cfg.provider.wallet.to_string();
Expand All @@ -2362,7 +2373,10 @@ fn deploy(cfg_override: &ConfigOverride, program_str: Option<String>) -> Result<
);
println!("Program path: {}...", binary_path);

let file = program.keypair_file()?;
let program_keypair_filepath = match &program_keypair {
Some(program_keypair) => program_keypair.clone(),
None => program.keypair_file()?.path().display().to_string(),
};

// Send deploy transactions.
let exit = std::process::Command::new("solana")
Expand All @@ -2373,7 +2387,7 @@ fn deploy(cfg_override: &ConfigOverride, program_str: Option<String>) -> Result<
.arg("--keypair")
.arg(&keypair)
.arg("--program-id")
.arg(file.path().display().to_string())
.arg(program_keypair_filepath)
.arg(&binary_path)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand Down

0 comments on commit 700ed26

Please sign in to comment.