mirror of
https://github.com/gay-pizza/jaarg.git
synced 2025-12-19 07:20:18 +00:00
Add program description to full help
This commit is contained in:
@@ -208,7 +208,8 @@ pub fn main() -> ExitCode {
|
|||||||
Opt::value(Arg::Bin, &["--bin", "-b"], "data.bin").help_text("Add a binary file"),
|
Opt::value(Arg::Bin, &["--bin", "-b"], "data.bin").help_text("Add a binary file"),
|
||||||
Opt::value(Arg::Txt, &["--txt", "-t"], "text.txt").help_text("Add a text file"),
|
Opt::value(Arg::Txt, &["--txt", "-t"], "text.txt").help_text("Add a text file"),
|
||||||
Opt::value(Arg::Whitespace, &["--whitespace"], "\" \"").help_text("Emitted indentation (Default: \"\\t\")"),
|
Opt::value(Arg::Whitespace, &["--whitespace"], "\" \"").help_text("Emitted indentation (Default: \"\\t\")"),
|
||||||
]);
|
]).with_description("Convert one or more binary and text file(s) to a C header file,\n\
|
||||||
|
as arrays and C strings respectively.");
|
||||||
match OPTIONS.parse_easy(|program_name, id, _opt, _name, arg| {
|
match OPTIONS.parse_easy(|program_name, id, _opt, _name, arg| {
|
||||||
match id {
|
match id {
|
||||||
Arg::Out => { arguments.out = arg.into(); }
|
Arg::Out => { arguments.out = arg.into(); }
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ impl<ID> core::fmt::Display for StandardFullHelpWriter<'_, ID> {
|
|||||||
}
|
}
|
||||||
writeln!(f)?;
|
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 {
|
fn calculate_left_pad<ID: 'static>(option: &Opt<ID>) -> usize {
|
||||||
(match option.names {
|
(match option.names {
|
||||||
OptIdentifier::Single(name) => name.chars().count(),
|
OptIdentifier::Single(name) => name.chars().count(),
|
||||||
|
|||||||
@@ -5,16 +5,22 @@
|
|||||||
|
|
||||||
/// Static structure that contains instructions for parsing command-line arguments
|
/// Static structure that contains instructions for parsing command-line arguments
|
||||||
pub struct Opts<ID: 'static> {
|
pub struct Opts<ID: 'static> {
|
||||||
/// String containing single characters that match option prefixes
|
|
||||||
flag_chars: &'static str,
|
|
||||||
/// List of options
|
/// List of options
|
||||||
options: &'static[Opt<ID>],
|
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> {
|
impl<ID: 'static> Opts<ID> {
|
||||||
/// Build argument parser options with the default flag character of '-'
|
/// Build argument parser options with the default flag character of '-'
|
||||||
pub const fn new(options: &'static[Opt<ID>]) -> Self {
|
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.
|
/// Set the recognised flag/option characters.
|
||||||
@@ -22,4 +28,10 @@ impl<ID: 'static> Opts<ID> {
|
|||||||
self.flag_chars = flag_chars;
|
self.flag_chars = flag_chars;
|
||||||
self
|
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