mirror of
https://github.com/gay-pizza/jaarg.git
synced 2025-12-19 15:30:16 +00:00
Add program description to full help
This commit is contained in:
@@ -110,6 +110,11 @@ impl<ID> core::fmt::Display for StandardFullHelpWriter<'_, ID> {
|
||||
}
|
||||
writeln!(f)?;
|
||||
|
||||
if let Some(description) = self.0.options.description {
|
||||
writeln!(f)?;
|
||||
writeln!(f, "{description}")?;
|
||||
}
|
||||
|
||||
fn calculate_left_pad<ID: 'static>(option: &Opt<ID>) -> usize {
|
||||
(match option.names {
|
||||
OptIdentifier::Single(name) => name.chars().count(),
|
||||
|
||||
@@ -5,16 +5,22 @@
|
||||
|
||||
/// Static structure that contains instructions for parsing command-line arguments
|
||||
pub struct Opts<ID: 'static> {
|
||||
/// String containing single characters that match option prefixes
|
||||
flag_chars: &'static str,
|
||||
/// List of options
|
||||
options: &'static[Opt<ID>],
|
||||
/// String containing single characters that match option prefixes
|
||||
flag_chars: &'static str,
|
||||
/// A description of what the program does
|
||||
description: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl<ID: 'static> Opts<ID> {
|
||||
/// Build argument parser options with the default flag character of '-'
|
||||
pub const fn new(options: &'static[Opt<ID>]) -> Self {
|
||||
Self { flag_chars: "-", options }
|
||||
Self {
|
||||
options,
|
||||
flag_chars: "-",
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the recognised flag/option characters.
|
||||
@@ -22,4 +28,10 @@ impl<ID: 'static> Opts<ID> {
|
||||
self.flag_chars = flag_chars;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the description of the program, available to help writers.
|
||||
pub const fn with_description(mut self, description: &'static str) -> Self {
|
||||
self.description = Some(description);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user