Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cortex-cli/src/agent_cmd/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ pub struct CopyArgs {
/// Force overwrite if destination agent already exists.
#[arg(short, long)]
pub force: bool,

/// Show what would be copied without writing the destination file.
#[arg(long = "dry-run")]
pub dry_run: bool,
}

/// Arguments for export command.
Expand Down
37 changes: 34 additions & 3 deletions src/cortex-cli/src/agent_cmd/handlers/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn run_copy(args: CopyArgs) -> Result<()> {

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

// Get the agents directory
let agents_dir = get_agents_dir()?;
std::fs::create_dir_all(&agents_dir)?;

let dest_file = agents_dir.join(format!("{}.md", args.destination));

if args.dry_run {
println!(
"Would copy agent '{}' to '{}'",
args.source, args.destination
);
println!(
" Source: {}",
source_agent
.path
.as_ref()
.map(|path| path.display().to_string())
.unwrap_or_else(|| "builtin".to_string())
);
println!(" Destination: {}", dest_file.display());
println!(
" Destination exists: {}",
if dest_exists { "yes" } else { "no" }
);
println!(
" Force required: {}",
if dest_exists && !args.force {
"yes"
} else {
"no"
}
);
println!();
println!("No files written (dry run).");
return Ok(());
}

std::fs::create_dir_all(&agents_dir)?;

// Generate the agent content
let content = if source_agent.native {
// For built-in agents, create a new file from scratch
Expand Down
19 changes: 16 additions & 3 deletions src/cortex-cli/src/agent_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#[cfg(test)]
mod tests {
use crate::agent_cmd::cli::{CopyArgs, ExportArgs};
use crate::agent_cmd::loader::{
load_builtin_agents, parse_frontmatter, read_file_with_encoding,
};
use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter};
use crate::agent_cmd::types::AgentMode;
use crate::utils::file::read_file_with_encoding;

#[test]
fn test_read_file_with_utf8() {
Expand Down Expand Up @@ -89,9 +88,23 @@ mod tests {
source: "build".to_string(),
destination: "my-build".to_string(),
force: false,
dry_run: false,
};
assert_eq!(args.source, "build");
assert_eq!(args.destination, "my-build");
assert!(!args.dry_run);
}

#[test]
fn test_copy_args_dry_run() {
let args = CopyArgs {
source: "build".to_string(),
destination: "my-build".to_string(),
force: false,
dry_run: true,
};

assert!(args.dry_run);
}

#[test]
Expand Down