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