Skip to content

Commit 78b28d5

Browse files
committed
fix(cli): add dry run for agent copy
1 parent 7954d02 commit 78b28d5

3 files changed

Lines changed: 54 additions & 6 deletions

File tree

src/cortex-cli/src/agent_cmd/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ pub struct CopyArgs {
184184
/// Force overwrite if destination agent already exists.
185185
#[arg(short, long)]
186186
pub force: bool,
187+
188+
/// Show what would be copied without writing the destination file.
189+
#[arg(long = "dry-run")]
190+
pub dry_run: bool,
187191
}
188192

189193
/// Arguments for export command.

src/cortex-cli/src/agent_cmd/handlers/copy.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn run_copy(args: CopyArgs) -> Result<()> {
3131

3232
// Check if destination already exists
3333
let dest_exists = agents.iter().any(|a| a.name == args.destination);
34-
if dest_exists && !args.force {
34+
if dest_exists && !args.force && !args.dry_run {
3535
bail!(
3636
"Agent '{}' already exists. Use --force to overwrite.",
3737
args.destination
@@ -40,10 +40,41 @@ pub async fn run_copy(args: CopyArgs) -> Result<()> {
4040

4141
// Get the agents directory
4242
let agents_dir = get_agents_dir()?;
43-
std::fs::create_dir_all(&agents_dir)?;
44-
4543
let dest_file = agents_dir.join(format!("{}.md", args.destination));
4644

45+
if args.dry_run {
46+
println!(
47+
"Would copy agent '{}' to '{}'",
48+
args.source, args.destination
49+
);
50+
println!(
51+
" Source: {}",
52+
source_agent
53+
.path
54+
.as_ref()
55+
.map(|path| path.display().to_string())
56+
.unwrap_or_else(|| "builtin".to_string())
57+
);
58+
println!(" Destination: {}", dest_file.display());
59+
println!(
60+
" Destination exists: {}",
61+
if dest_exists { "yes" } else { "no" }
62+
);
63+
println!(
64+
" Force required: {}",
65+
if dest_exists && !args.force {
66+
"yes"
67+
} else {
68+
"no"
69+
}
70+
);
71+
println!();
72+
println!("No files written (dry run).");
73+
return Ok(());
74+
}
75+
76+
std::fs::create_dir_all(&agents_dir)?;
77+
4778
// Generate the agent content
4879
let content = if source_agent.native {
4980
// For built-in agents, create a new file from scratch

src/cortex-cli/src/agent_cmd/tests.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#[cfg(test)]
44
mod tests {
55
use crate::agent_cmd::cli::{CopyArgs, ExportArgs};
6-
use crate::agent_cmd::loader::{
7-
load_builtin_agents, parse_frontmatter, read_file_with_encoding,
8-
};
6+
use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter};
97
use crate::agent_cmd::types::AgentMode;
8+
use crate::utils::file::read_file_with_encoding;
109

1110
#[test]
1211
fn test_read_file_with_utf8() {
@@ -89,9 +88,23 @@ mod tests {
8988
source: "build".to_string(),
9089
destination: "my-build".to_string(),
9190
force: false,
91+
dry_run: false,
9292
};
9393
assert_eq!(args.source, "build");
9494
assert_eq!(args.destination, "my-build");
95+
assert!(!args.dry_run);
96+
}
97+
98+
#[test]
99+
fn test_copy_args_dry_run() {
100+
let args = CopyArgs {
101+
source: "build".to_string(),
102+
destination: "my-build".to_string(),
103+
force: false,
104+
dry_run: true,
105+
};
106+
107+
assert!(args.dry_run);
95108
}
96109

97110
#[test]

0 commit comments

Comments
 (0)