From e88f6dab0217375ca52dea0149d313b1041a75f7 Mon Sep 17 00:00:00 2001 From: Priyesh-Kun Date: Sun, 14 Jul 2024 20:11:02 +0530 Subject: [PATCH] added feature for relative path --- cli/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index e1b7384c49..d653d24263 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -49,6 +49,7 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Stdio}; use std::str::FromStr; use std::string::ToString; +use std::env; use tar::Archive; mod checks; @@ -887,6 +888,16 @@ fn process_command(opts: Opts) -> Result<()> { } } +fn resolve_path(filepath: String) -> Result { + let path = PathBuf::from(filepath); + if path.is_relative() { + let current_dir = env::current_dir()?; + Ok(current_dir.join(path)) + } else { + Ok(path) + } +} + #[allow(clippy::too_many_arguments)] fn init( cfg_override: &ConfigOverride, @@ -2283,10 +2294,11 @@ fn idl_init( idl_filepath: String, priority_fee: Option, ) -> Result<()> { + let absolute_path = resolve_path(idl_filepath)?; with_workspace(cfg_override, |cfg| { let keypair = cfg.provider.wallet.to_string(); - let bytes = fs::read(idl_filepath)?; + let bytes = fs::read(absolute_path)?; let idl: Idl = serde_json::from_reader(&*bytes)?; let idl_address = create_idl_account(cfg, &keypair, &program_id, &idl, priority_fee)?;