MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / launch_editor

Function launch_editor

crates/chat-cli/src/util/editor.rs:17–41  ·  view source on GitHub ↗

Launch the user's preferred editor with the given file path. This function properly parses the EDITOR environment variable to handle editors that require arguments (e.g., "emacsclient -nw"). # Arguments `file_path` - Path to the file to open in the editor # Returns `Ok(())` if the editor was launched successfully and exited with success `Err` if the editor failed to launch or exited with an err

(file_path: &Path)

Source from the content-addressed store, hash-verified

15/// * `Ok(())` if the editor was launched successfully and exited with success
16/// * `Err` if the editor failed to launch or exited with an error
17pub fn launch_editor(file_path: &Path) -> eyre::Result<()> {
18 let editor_cmd = get_editor();
19
20 // Parse the editor command to handle arguments
21 let mut parts = shlex::split(&editor_cmd).ok_or_else(|| eyre::eyre!("Failed to parse EDITOR command"))?;
22
23 if parts.is_empty() {
24 eyre::bail!("EDITOR environment variable is empty");
25 }
26
27 let editor_bin = parts.remove(0);
28
29 let mut cmd = Command::new(editor_bin);
30 for arg in parts {
31 cmd.arg(arg);
32 }
33
34 let status = cmd.arg(file_path).status()?;
35
36 if !status.success() {
37 eyre::bail!("Editor process did not exit with success");
38 }
39
40 Ok(())
41}

Callers

nothing calls this directly

Calls 5

get_editorFunction · 0.85
removeMethod · 0.80
is_emptyMethod · 0.45
statusMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected