Skip to content

Commit c4070f0

Browse files
committed
fix(cortex-cli): expand tilde in import command file paths
Fixes bounty issue #1571 The import command was treating the tilde (~) character literally instead of expanding it to the user's home directory. This prevented users from using paths like ~/file.json with the cortex import command. The fix uses the existing expand_home_path() function from cortex-common to properly expand the tilde before reading the file.
1 parent a6338de commit c4070f0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cortex-cli/src/import_cmd.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
55
use anyhow::{Context, Result, bail};
66
use clap::Parser;
7-
use std::path::PathBuf;
7+
use std::path::{Path, PathBuf};
8+
9+
use cortex_common::path_utils::expand_home_path;
810

911
use cortex_engine::rollout::recorder::{RolloutRecorder, SessionMeta};
1012
use cortex_engine::rollout::{SESSIONS_SUBDIR, get_rollout_path};
@@ -44,8 +46,9 @@ impl ImportCommand {
4446
// Fetch from URL
4547
fetch_url(&self.source).await?
4648
} else {
47-
// Read from local file
48-
let path = PathBuf::from(&self.source);
49+
// Read from local file (expand tilde to home directory)
50+
let path = expand_home_path(Path::new(&self.source))
51+
.map_err(|e| anyhow::anyhow!("Failed to expand path: {}", e))?;
4952
std::fs::read_to_string(&path)
5053
.with_context(|| format!("Failed to read file: {}", path.display()))?
5154
};

0 commit comments

Comments
 (0)