Skip to content

Commit

Permalink
Fixed help docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyllingene committed May 29, 2024
1 parent 5d069e4 commit 393f967
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sarge"
version = "7.2.3"
version = "7.2.4"
edition = "2021"

authors = ["Kyllingene"]
Expand Down
2 changes: 1 addition & 1 deletion src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn empty(width: Option<NonZeroUsize>) -> String {

/// Returns the padding necessary for continuing doc lines.
fn doc_newline(params: DocParams) -> String {
let mut width = if params.has_short { 6 } else { 0 };
let mut width = if params.has_short { 8 } else { 0 };

if let Some(long_width) = params.long_width {
width += usize::from(long_width) + 1;
Expand Down
48 changes: 36 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,50 @@ macro_rules! __arg_typ {
#[macro_export]
#[doc(hidden)]
macro_rules! __var_tag {
( $long:ident $( $doc:literal )* ) => {
( $long:ident $( $doc:literal )* ) => {{
let mut s = ::std::string::String::new();
$(
s.push_str($doc);
s.push('\n');
)*
s.pop();
$crate::tag::long($crate::__replace!(::std::stringify!($long), '_', '-'))
.doc(::std::string::String::new() $( + "\n" + $doc )*)
};
( $short:literal $long:ident $( $doc:literal )* ) => {
.doc(s)
}};
( $short:literal $long:ident $( $doc:literal )* ) => {{
let mut s = ::std::string::String::new();
$(
s.push_str($doc);
s.push('\n');
)*
s.pop();
$crate::tag::both($short, $crate::__replace!(::std::stringify!($long), '_', '-'))
.doc(::std::string::String::new() $( + "\n" + $doc )*)
};
( $long:ident $env:ident $( $doc:literal )* ) => {
.doc(s)
}};
( $long:ident $env:ident $( $doc:literal )* ) => {{
let mut s = ::std::string::String::new();
$(
s.push_str($doc);
s.push('\n');
)*
s.pop();
$crate::tag::long(
$crate::__replace!(::std::stringify!($long), '_', '-')
)
.env(::std::stringify!($env))
.doc(::std::string::String::new() $( + "\n" + $doc )*)
};
( $short:literal $long:ident $env:ident $( $doc:literal )* ) => {
.doc(s)
}};
( $short:literal $long:ident $env:ident $( $doc:literal )* ) => {{
let mut s = ::std::string::String::new();
$(
s.push_str($doc);
s.push('\n');
)*
s.pop();
$crate::tag::both($short, $crate::__replace!(::std::stringify!($long), '_', '-'))
.env(::std::stringify!($env))
.doc(::std::string::String::new() $( + "\n" + $doc )*)
};
.doc(s)
}};
}

/// A macro to quickly define your CLI interface with struct-like syntax.
Expand Down

0 comments on commit 393f967

Please sign in to comment.