Skip to content

Commit 3522375

Browse files
authored
fix: handle slash commands (#1235)
1 parent 82d91ff commit 3522375

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

crates/q_cli/src/cli/chat/command.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ impl Command {
351351
return Err(suggestion);
352352
}
353353

354+
// Check if the input starts with a literal backslash followed by a slash
355+
// This allows users to escape the slash if they actually want to start with one
356+
if input.starts_with("\\/") {
357+
return Ok(Self::Ask {
358+
prompt: input[1..].to_string(), // Remove the backslash but keep the slash
359+
});
360+
}
361+
354362
if let Some(command) = input.strip_prefix("/") {
355363
let parts: Vec<&str> = command.split_whitespace().collect();
356364

@@ -688,10 +696,13 @@ impl Command {
688696
},
689697
}
690698
},
691-
_ => {
692-
return Ok(Self::Ask {
693-
prompt: input.to_string(),
694-
});
699+
unknown_command => {
700+
// If the command starts with a slash but isn't recognized,
701+
// return an error instead of treating it as a prompt
702+
return Err(format!(
703+
"Unknown command: '/{}'. Type '/help' to see available commands.\nTo use a literal slash at the beginning of your message, escape it with a backslash (e.g., '\\//hey' for '/hey').",
704+
unknown_command
705+
));
695706
},
696707
});
697708
}

0 commit comments

Comments
 (0)