Skip to content

Commit 8179b32

Browse files
authored
feat(chat /context): add --expand flag to print out file content (#1148)
1 parent d9175eb commit 8179b32

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

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

+23-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ Profiles allow you to organize and manage different sets of context files for di
7070

7171
#[derive(Debug, Clone, PartialEq, Eq)]
7272
pub enum ContextSubcommand {
73-
Show,
73+
Show {
74+
expand: bool,
75+
},
7476
Add {
7577
global: bool,
7678
force: bool,
@@ -91,7 +93,8 @@ impl ContextSubcommand {
9193
const AVAILABLE_COMMANDS: &str = color_print::cstr! {"<cyan!>Available commands</cyan!>
9294
<em>help</em> <black!>Show an explanation for the context command</black!>
9395
94-
<em>show</em> <black!>Display the context rule configuration and matched files</black!>
96+
<em>show [--expand]</em> <black!>Display the context rule configuration and matched files</black!>
97+
<black!>--expand: Print out each matched file's content</black!>
9598
9699
<em>add [--global] [--force] <<paths...>></em>
97100
<black!>Add context rules (filenames or glob patterns)</black!>
@@ -105,6 +108,7 @@ impl ContextSubcommand {
105108
<black!>--global: Remove global rules</black!>"};
106109
const CLEAR_USAGE: &str = "/context clear [--global]";
107110
const REMOVE_USAGE: &str = "/context rm [--global] <path1> [path2...]";
111+
const SHOW_USAGE: &str = "/context show [--expand]";
108112

109113
fn usage_msg(header: impl AsRef<str>) -> String {
110114
format!("{}\n\n{}", header.as_ref(), Self::AVAILABLE_COMMANDS)
@@ -340,8 +344,18 @@ impl Command {
340344
}
341345

342346
match parts[1].to_lowercase().as_str() {
343-
"show" => Self::Context {
344-
subcommand: ContextSubcommand::Show,
347+
"show" => {
348+
let mut expand = false;
349+
for part in &parts[2..] {
350+
if *part == "--expand" {
351+
expand = true;
352+
} else {
353+
usage_err!(ContextSubcommand::SHOW_USAGE);
354+
}
355+
}
356+
Self::Context {
357+
subcommand: ContextSubcommand::Show { expand },
358+
}
345359
},
346360
"add" => {
347361
// Parse add command with paths and flags
@@ -532,7 +546,11 @@ mod tests {
532546
"/profile set p",
533547
profile!(ProfileSubcommand::Set { name: "p".to_string() }),
534548
),
535-
("/context show", context!(ContextSubcommand::Show)),
549+
("/context show", context!(ContextSubcommand::Show { expand: false })),
550+
(
551+
"/context show --expand",
552+
context!(ContextSubcommand::Show { expand: true }),
553+
),
536554
(
537555
"/context add p1 p2",
538556
context!(ContextSubcommand::Add {

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const HELP_TEXT: &str = color_print::cstr! {"
149149
<em>rename</em> <black!>Rename a profile</black!>
150150
<em>/context</em> <black!>Manage context files for the chat session</black!>
151151
<em>help</em> <black!>Show context help</black!>
152-
<em>show</em> <black!>Display current context configuration</black!>
152+
<em>show</em> <black!>Display current context rules configuration [--expand]</black!>
153153
<em>add</em> <black!>Add file(s) to context [--global] [--force]</black!>
154154
<em>rm</em> <black!>Remove file(s) from context [--global]</black!>
155155
<em>clear</em> <black!>Clear all files from current context [--global]</black!>
@@ -1008,7 +1008,7 @@ where
10081008
Command::Context { subcommand } => {
10091009
if let Some(context_manager) = &mut self.conversation_state.context_manager {
10101010
match subcommand {
1011-
command::ContextSubcommand::Show => {
1011+
command::ContextSubcommand::Show { expand } => {
10121012
// Display global context
10131013
execute!(
10141014
self.output,
@@ -1125,6 +1125,14 @@ where
11251125
style::SetForegroundColor(Color::Reset),
11261126
style::Print(format!(" {}\n", filename))
11271127
)?;
1128+
if expand {
1129+
execute!(
1130+
self.output,
1131+
style::SetForegroundColor(Color::DarkGrey),
1132+
style::Print(format!("{}\n\n", content)),
1133+
style::SetForegroundColor(Color::Reset)
1134+
)?;
1135+
}
11281136
}
11291137

11301138
for (filename, content) in profile_context_files {
@@ -1136,6 +1144,18 @@ where
11361144
style::SetForegroundColor(Color::Reset),
11371145
style::Print(format!(" {}\n", filename))
11381146
)?;
1147+
if expand {
1148+
execute!(
1149+
self.output,
1150+
style::SetForegroundColor(Color::DarkGrey),
1151+
style::Print(format!("{}\n\n", content)),
1152+
style::SetForegroundColor(Color::Reset)
1153+
)?;
1154+
}
1155+
}
1156+
1157+
if expand {
1158+
execute!(self.output, style::Print(format!("{}\n\n", "▔".repeat(3))),)?;
11391159
}
11401160

11411161
execute!(

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

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const COMMANDS: &[&str] = &[
5757
"/profile set",
5858
"/context help",
5959
"/context show",
60+
"/context show --expand",
6061
"/context add",
6162
"/context add --global",
6263
"/context rm",

0 commit comments

Comments
 (0)