Skip to content

Commit

Permalink
Merge pull request #63 from joncinque/outfile
Browse files Browse the repository at this point in the history
cli: Add argument for output filename
  • Loading branch information
blockiosaurus authored Feb 28, 2024
2 parents 48399dc + 74ad7aa commit 3df10f5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions shank-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub enum Command {
#[clap(short, long, default_value = "idl")]
out_dir: String,

/// Output filename for the IDL JSON [default: <program crate name>.json,
/// e.g. "my_program.json"]
#[clap(long)]
out_filename: Option<String>,

/// Directory of program crate for which to generate the IDL.
#[clap(short = 'r', long)]
crate_root: Option<String>,
Expand All @@ -39,9 +44,10 @@ pub fn entry(opts: Opts) -> Result<()> {
match opts.command {
Command::Idl {
out_dir,
out_filename,
crate_root,
program_id,
} => idl(out_dir, crate_root, program_id),
} => idl(out_dir, out_filename, crate_root, program_id),
}
}

Expand All @@ -66,6 +72,7 @@ pub fn try_resolve_path(p: Option<String>, label: &str) -> Result<PathBuf> {

pub fn idl(
out_dir: String,
out_filename: Option<String>,
crate_root: Option<String>,
program_id: Option<String>,
) -> Result<()> {
Expand Down Expand Up @@ -107,8 +114,12 @@ pub fn idl(
let idl_json = idl.try_into_json()?;

// Write to JSON file
let name = manifest.lib_name()?;
let idl_json_path = out_dir.join(format!("{}.json", name));
let out_filename = if let Some(out_filename) = out_filename {
out_filename
} else {
format!("{}.json", manifest.lib_name()?)
};
let idl_json_path = out_dir.join(out_filename);
let mut idl_json_file = File::create(&idl_json_path)?;
info!("Writing IDL to {}", &idl_json_path.display());

Expand Down

0 comments on commit 3df10f5

Please sign in to comment.