Get the commit message, potentially from editor.
(&self)
| 113 | |
| 114 | /// Get the commit message, potentially from editor. |
| 115 | pub(super) fn get_message(&self) -> CliResult<String> { |
| 116 | // If message was provided, use it |
| 117 | if let Some(ref msg) = self.message { |
| 118 | return Ok(msg.clone()); |
| 119 | } |
| 120 | |
| 121 | // If edit flag is set or we're in a terminal without a message |
| 122 | if self.edit { |
| 123 | return self.get_message_from_editor(); |
| 124 | } |
| 125 | |
| 126 | // Check if stdin is a terminal |
| 127 | if is_terminal() { |
| 128 | // Interactive mode - prompt for message |
| 129 | print!("Enter commit message (empty line to cancel): "); |
| 130 | std::io::stdout().flush().map_err(|e| { |
| 131 | CliError::Internal(anyhow::anyhow!("Failed to flush stdout: {}", e)) |
| 132 | })?; |
| 133 | |
| 134 | let mut message = String::new(); |
| 135 | std::io::stdin().read_line(&mut message).map_err(|e| { |
| 136 | CliError::Internal(anyhow::anyhow!("Failed to read message: {}", e)) |
| 137 | })?; |
| 138 | |
| 139 | let message = message.trim(); |
| 140 | if message.is_empty() { |
| 141 | return Err(CliError::Cancelled); |
| 142 | } |
| 143 | |
| 144 | Ok(message.to_string()) |
| 145 | } else { |
| 146 | // Non-interactive mode - use default message |
| 147 | Ok("No message provided".to_string()) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /// Open an editor to get the commit message. |
| 152 | pub(super) fn get_message_from_editor(&self) -> CliResult<String> { |
no test coverage detected