| 1 |
#![cfg_attr(not(feature = "help"), allow(unused_variables))] |
| 2 |
|
| 3 |
// Internal |
| 4 |
use crate::builder::Command; |
| 5 |
use crate::builder::StyledStr; |
| 6 |
use crate::output::Usage; |
| 7 |
|
| 8 |
/// Writes the parser help to the wrapped stream. |
| 9 |
pub(crate) fn write_help(writer: &mut StyledStr, cmd: &Command, usage: &Usage<'_>, use_long: bool) { |
| 10 |
debug!("write_help"); |
| 11 |
|
| 12 |
if let Some(h) = cmd.get_override_help() { |
| 13 |
writer.push_styled(h); |
| 14 |
} else { |
| 15 |
#[cfg(feature = "help")] |
| 16 |
{ |
| 17 |
use super::AutoHelp; |
| 18 |
use super::HelpTemplate; |
| 19 |
if let Some(tmpl) = cmd.get_help_template() { |
| 20 |
HelpTemplate::new(writer, cmd, usage, use_long) |
| 21 |
.write_templated_help(tmpl.as_styled_str()); |
| 22 |
} else { |
| 23 |
AutoHelp::new(writer, cmd, usage, use_long).write_help(); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
#[cfg(not(feature = "help"))] |
| 28 |
{ |
| 29 |
debug!("write_help: no help, `Command::override_help` and `help` is missing"); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// Remove any lines from unused sections |
| 34 |
writer.trim_start_lines(); |
| 35 |
// Remove any whitespace caused by book keeping |
| 36 |
writer.trim_end(); |
| 37 |
// Ensure there is still a trailing newline |
| 38 |
writer.push_str("\n"); |
| 39 |
} |