Skip to content

Commit

Permalink
fix: Prevent panic when passing relative paths to --program-dir (#2324
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TomAFrench authored Aug 15, 2023
1 parent bc645fc commit 9eb45da
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct NargoCli {
#[derive(Args, Clone, Debug)]
pub(crate) struct NargoConfig {
// REMINDER: Also change this flag in the LSP test lens if renamed
#[arg(long, hide=true, global=true, default_value_os_t = std::env::current_dir().unwrap())]
#[arg(long, hide = true, global = true, default_value = "./")]
program_dir: PathBuf,
}

Expand All @@ -64,6 +64,11 @@ enum NargoCommand {
pub(crate) fn start_cli() -> eyre::Result<()> {
let NargoCli { command, mut config } = NargoCli::parse();

// If the provided `program_dir` is relative, make it absolute by joining it to the current directory.
if !config.program_dir.is_absolute() {
config.program_dir = std::env::current_dir().unwrap().join(config.program_dir);
}

// Search through parent directories to find package root if necessary.
if !matches!(command, NargoCommand::New(_) | NargoCommand::Init(_) | NargoCommand::Lsp(_)) {
config.program_dir = find_package_root(&config.program_dir)?;
Expand Down

0 comments on commit 9eb45da

Please sign in to comment.