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
5 changes: 2 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
55 changes: 52 additions & 3 deletions src/cortex-cli/src/alias_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async fn run_set(args: AliasSetArgs) -> Result<()> {

println!("Alias '{}' set to: {}", args.name, args.command);
if let Some(desc) = &args.description {
println!(" Description: {}", desc);
print_multiline_description(" Description: ", " ", desc);
}

Ok(())
Expand Down Expand Up @@ -203,7 +203,7 @@ async fn run_list(args: AliasListArgs) -> Result<()> {
for alias in aliases {
println!(" {} = {}", alias.name, alias.command);
if let Some(desc) = &alias.description {
println!(" {}", desc);
print_multiline_description(" ", " ", desc);
}
}

Expand Down Expand Up @@ -265,12 +265,42 @@ async fn run_show(args: AliasShowArgs) -> Result<()> {
println!("{}", "-".repeat(40));
println!(" Command: {}", alias.command);
if let Some(desc) = &alias.description {
println!(" Description: {}", desc);
print_multiline_description(" Description: ", " ", desc);
}

Ok(())
}

fn format_multiline_description(
first_prefix: &str,
continuation_prefix: &str,
desc: &str,
) -> String {
let mut output = String::new();

for (index, line) in desc.lines().enumerate() {
if index > 0 {
output.push('\n');
}

if index == 0 {
output.push_str(first_prefix);
} else {
output.push_str(continuation_prefix);
}
output.push_str(line);
}

output
}

fn print_multiline_description(first_prefix: &str, continuation_prefix: &str, desc: &str) {
println!(
"{}",
format_multiline_description(first_prefix, continuation_prefix, desc)
);
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -299,6 +329,25 @@ mod tests {
);
}

#[test]
fn test_format_multiline_description_indents_every_line() {
let formatted =
format_multiline_description(" ", " ", "First line\nSecond line\nThird line");

assert_eq!(
formatted,
" First line\n Second line\n Third line"
);
}

#[test]
fn test_format_multiline_description_uses_continuation_prefix() {
let formatted =
format_multiline_description(" Description: ", " ", "First\nSecond");

assert_eq!(formatted, " Description: First\n Second");
}

#[test]
fn test_alias_definition_without_description_json_roundtrip() {
let alias = AliasDefinition {
Expand Down