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

Function launch_editor

crates/chat-cli/src/cli/chat/cli/editor.rs:88–119  ·  view source on GitHub ↗

Launch the user's preferred editor with the given file path

(file_path: &std::path::Path)

Source from the content-addressed store, hash-verified

86
87/// Launch the user's preferred editor with the given file path
88fn launch_editor(file_path: &std::path::Path) -> Result<(), ChatError> {
89 // Get the editor from environment variable or use a default
90 let editor_cmd = get_editor();
91
92 // Parse the editor command to handle arguments
93 let mut parts =
94 shlex::split(&editor_cmd).ok_or_else(|| ChatError::Custom("Failed to parse EDITOR command".into()))?;
95
96 if parts.is_empty() {
97 return Err(ChatError::Custom("EDITOR environment variable is empty".into()));
98 }
99
100 let editor_bin = parts.remove(0);
101
102 // Open the editor with the parsed command and arguments
103 let mut cmd = std::process::Command::new(editor_bin);
104 // Add any arguments that were part of the EDITOR variable
105 for arg in parts {
106 cmd.arg(arg);
107 }
108 // Add the file path as the last argument
109 let status = cmd
110 .arg(file_path)
111 .status()
112 .map_err(|e| ChatError::Custom(format!("Failed to open editor: {}", e).into()))?;
113
114 if !status.success() {
115 return Err(ChatError::Custom("Editor exited with non-zero status".into()));
116 }
117
118 Ok(())
119}
120
121/// Opens the user's preferred editor to edit an existing file
122pub fn open_editor_file(file_path: &std::path::Path) -> Result<(), ChatError> {

Callers 4

executeMethod · 0.70
open_editor_fileFunction · 0.70
open_editorFunction · 0.70
executeMethod · 0.50

Calls 6

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

Tested by

no test coverage detected