Skip to content

Commit a2b2c8a

Browse files
authored
Add /shell command to simulate request (#55)
1 parent a52d8a3 commit a2b2c8a

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Minor
66

7+
- Add `/shell` command to simulate a Sec-Gemini request
78
- Add visible confirmation after multi-line query
89
- Don't print the user and org id anymore
910
- Add `/session list --debug` argument

cli/src/cli/interact.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ impl Options {
156156

157157
async fn execute(&mut self, query: &str, session: &mut Session) {
158158
let (enable_shell, query) = self.shell.update_query(query).await;
159+
self.execute_updated(enable_shell, &query, session).await;
160+
}
161+
162+
async fn execute_updated(&mut self, enable_shell: bool, query: &str, session: &mut Session) {
159163
let mut progress = new_progress();
160-
session.send(&query).await;
164+
session.send(query).await;
161165
set_message(&progress, "Waiting response");
162166
let mut result: Option<String> = None;
163167
while let Some(message) = session.recv().await {

cli/src/cli/interact/cmds.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,14 @@ fn exec_session_delete(input: CommandInput<'_>) -> CommandOutput<'_> {
557557
})
558558
}
559559

560+
fn exec_shell(input: CommandInput<'_>) -> CommandOutput<'_> {
561+
Box::pin(async move {
562+
let command = format!("{}{}", super::shell::EXEC_SHELL_CMD, input.args["command"]);
563+
let response = input.this.shell.interpret_result(&command).await.unwrap();
564+
input.this.execute_updated(true, &response, input.session).await;
565+
})
566+
}
567+
560568
fn compl_session_name(completer: &Completer) -> Vec<String> {
561569
Handle::current().block_on(async {
562570
completer.sdk.cached_sessions().await.iter().map(|x| x.name.clone()).collect()
@@ -620,4 +628,6 @@ If the --name argument is an empty string (the default), a name is generated."
620628
{ "delete" "Deletes an existing session.\n
621629
The current session cannot be deleted."
622630
exec_session_delete ( "name" : compl_session_name ) } ]
631+
{ "shell" "Executes a shell command as if Sec-Gemini requested it."
632+
exec_shell ( "command" : * ) }
623633
};

cli/src/cli/interact/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ The format is:
257257
}
258258
}
259259

260-
const EXEC_SHELL_CMD: &str = "Execute shell command: ";
260+
pub const EXEC_SHELL_CMD: &str = "Execute shell command: ";
261261
const KILL_SHELL_CMD: &str = "Kill shell command.";
262262
const CONT_SHELL_CMD: &str = "Resume shell command: ";
263263

0 commit comments

Comments
 (0)