cli: Option to specify program to launch/deploy in workspace (#288)
This commit is contained in:
parent
37118e8c50
commit
30a58b99e1
|
@ -94,6 +94,8 @@ pub enum Command {
|
|||
url: Option<String>,
|
||||
#[clap(short, long)]
|
||||
keypair: Option<String>,
|
||||
#[clap(short, long)]
|
||||
program_name: Option<String>,
|
||||
},
|
||||
/// Runs the deploy migration script.
|
||||
Migrate {
|
||||
|
@ -110,6 +112,8 @@ pub enum Command {
|
|||
/// this should almost always be set.
|
||||
#[clap(short, long)]
|
||||
verifiable: bool,
|
||||
#[clap(short, long)]
|
||||
program_name: Option<String>,
|
||||
},
|
||||
/// Upgrades a single program. The configured wallet must be the upgrade
|
||||
/// authority.
|
||||
|
@ -218,7 +222,11 @@ fn main() -> Result<()> {
|
|||
Command::New { name } => new(name),
|
||||
Command::Build { idl, verifiable } => build(idl, verifiable),
|
||||
Command::Verify { program_id } => verify(program_id),
|
||||
Command::Deploy { url, keypair } => deploy(url, keypair),
|
||||
Command::Deploy {
|
||||
url,
|
||||
keypair,
|
||||
program_name,
|
||||
} => deploy(url, keypair, program_name),
|
||||
Command::Upgrade {
|
||||
program_id,
|
||||
program_filepath,
|
||||
|
@ -229,7 +237,8 @@ fn main() -> Result<()> {
|
|||
url,
|
||||
keypair,
|
||||
verifiable,
|
||||
} => launch(url, keypair, verifiable),
|
||||
program_name,
|
||||
} => launch(url, keypair, verifiable, program_name),
|
||||
Command::Test {
|
||||
skip_deploy,
|
||||
skip_local_validator,
|
||||
|
@ -936,7 +945,7 @@ fn test(
|
|||
_ => {
|
||||
if !skip_deploy {
|
||||
build(None, false)?;
|
||||
deploy(None, None)?;
|
||||
deploy(None, None, None)?;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -1151,11 +1160,19 @@ fn start_test_validator(cfg: &Config, flags: Option<Vec<String>>) -> Result<Chil
|
|||
|
||||
// TODO: Testing and deploys should use separate sections of metadata.
|
||||
// Similarly, each network should have separate metadata.
|
||||
fn deploy(url: Option<String>, keypair: Option<String>) -> Result<()> {
|
||||
_deploy(url, keypair).map(|_| ())
|
||||
fn deploy(
|
||||
url: Option<String>,
|
||||
keypair: Option<String>,
|
||||
program_name: Option<String>,
|
||||
) -> Result<()> {
|
||||
_deploy(url, keypair, program_name).map(|_| ())
|
||||
}
|
||||
|
||||
fn _deploy(url: Option<String>, keypair: Option<String>) -> Result<Vec<(Pubkey, Program)>> {
|
||||
fn _deploy(
|
||||
url: Option<String>,
|
||||
keypair: Option<String>,
|
||||
program_str: Option<String>,
|
||||
) -> Result<Vec<(Pubkey, Program)>> {
|
||||
with_workspace(|cfg, _path, _cargo| {
|
||||
// Fallback to config vars if not provided via CLI.
|
||||
let url = url.unwrap_or_else(|| cfg.cluster.url().to_string());
|
||||
|
@ -1168,9 +1185,19 @@ fn _deploy(url: Option<String>, keypair: Option<String>) -> Result<Vec<(Pubkey,
|
|||
let mut programs = Vec::new();
|
||||
|
||||
for mut program in read_all_programs()? {
|
||||
if let Some(single_prog_str) = &program_str {
|
||||
let program_name = program.path.file_name().unwrap().to_str().unwrap();
|
||||
if single_prog_str.as_str() != program_name {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let binary_path = program.binary_path().display().to_string();
|
||||
|
||||
println!("Deploying {}...", binary_path);
|
||||
println!(
|
||||
"Deploying program {:?}...",
|
||||
program.path.file_name().unwrap().to_str().unwrap()
|
||||
);
|
||||
println!("Program path: {}...", binary_path);
|
||||
|
||||
// Write the program's keypair filepath. This forces a new deploy
|
||||
// address.
|
||||
|
@ -1245,10 +1272,15 @@ fn upgrade(program_id: Pubkey, program_filepath: String) -> Result<()> {
|
|||
})
|
||||
}
|
||||
|
||||
fn launch(url: Option<String>, keypair: Option<String>, verifiable: bool) -> Result<()> {
|
||||
fn launch(
|
||||
url: Option<String>,
|
||||
keypair: Option<String>,
|
||||
verifiable: bool,
|
||||
program_name: Option<String>,
|
||||
) -> Result<()> {
|
||||
// Build and deploy.
|
||||
build(None, verifiable)?;
|
||||
let programs = _deploy(url.clone(), keypair.clone())?;
|
||||
let programs = _deploy(url.clone(), keypair.clone(), program_name.clone())?;
|
||||
|
||||
with_workspace(|cfg, _path, _cargo| {
|
||||
let url = url.unwrap_or_else(|| cfg.cluster.url().to_string());
|
||||
|
|
Loading…
Reference in New Issue