... Both repeated option.
- \\ Positional. This should not appear in the help message.
+ try testHelp(.{ .markdown_lite = false },
+ \\ -a
+ \\ Short flag.
+ \\
+ \\ -b
+ \\ Short option.
+ \\
+ \\ --aa
+ \\ Long flag.
+ \\
+ \\ --bb
+ \\ Long option.
+ \\
+ \\ -c, --cc
+ \\ Both flag.
+ \\
+ \\ --complicate
+ \\ Flag with a complicated and
+ \\ very long description that
+ \\ spans multiple lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\
+ \\ Example:
+ \\ something something something
+ \\
+ \\ -d, --dd
+ \\ Both option.
+ \\
+ \\ -d, --dd ...
+ \\ Both repeated option.
\\
);
- try help(slice_stream.writer(), Help, ¶ms);
- const expected = "" ++
- "\t-a \tShort flag.\n" ++
- "\t-b \tShort option.\n" ++
- "\t --aa \tLong flag.\n" ++
- "\t --bb \tLong option.\n" ++
- "\t-c, --cc \tBoth flag.\n" ++
- "\t --complicate\tFlag with a complicated and\n" ++
- "\t \tvery long description that\n" ++
- "\t \tspans multiple lines.\n" ++
- "\t-d, --dd \tBoth option.\n" ++
- "\t-d, --dd ...\tBoth repeated option.\n";
+ try testHelp(.{ .indent = 0 },
+ \\-a
+ \\ Short flag.
+ \\
+ \\-b
+ \\ Short option.
+ \\
+ \\ --aa
+ \\ Long flag.
+ \\
+ \\ --bb
+ \\ Long option.
+ \\
+ \\-c, --cc
+ \\ Both flag.
+ \\
+ \\ --complicate
+ \\ Flag with a complicated and very long description that spans multiple lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something something something
+ \\
+ \\-d, --dd
+ \\ Both option.
+ \\
+ \\-d, --dd ...
+ \\ Both repeated option.
+ \\
+ );
- try testing.expectEqualStrings(expected, slice_stream.getWritten());
+ try testHelp(.{ .indent = 0 },
+ \\-a
+ \\ Short flag.
+ \\
+ \\-b
+ \\ Short option.
+ \\
+ \\ --aa
+ \\ Long flag.
+ \\
+ \\ --bb
+ \\ Long option.
+ \\
+ \\-c, --cc
+ \\ Both flag.
+ \\
+ \\ --complicate
+ \\ Flag with a complicated and very long description that spans multiple lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something something something
+ \\
+ \\-d, --dd
+ \\ Both option.
+ \\
+ \\-d, --dd ...
+ \\ Both repeated option.
+ \\
+ );
+
+ try testHelp(.{ .indent = 0, .max_width = 26 },
+ \\-a
+ \\ Short flag.
+ \\
+ \\-b
+ \\ Short option.
+ \\
+ \\ --aa
+ \\ Long flag.
+ \\
+ \\ --bb
+ \\ Long option.
+ \\
+ \\-c, --cc
+ \\ Both flag.
+ \\
+ \\ --complicate
+ \\ Flag with a
+ \\ complicated and
+ \\ very long
+ \\ description that
+ \\ spans multiple
+ \\ lines.
+ \\
+ \\ Paragraph number
+ \\ 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something
+ \\ something
+ \\ something
+ \\
+ \\-d, --dd
+ \\ Both option.
+ \\
+ \\-d, --dd ...
+ \\ Both repeated
+ \\ option.
+ \\
+ );
+
+ try testHelp(.{
+ .indent = 0,
+ .max_width = 26,
+ .description_indent = 6,
+ },
+ \\-a
+ \\ Short flag.
+ \\
+ \\-b
+ \\ Short option.
+ \\
+ \\ --aa
+ \\ Long flag.
+ \\
+ \\ --bb
+ \\ Long option.
+ \\
+ \\-c, --cc
+ \\ Both flag.
+ \\
+ \\ --complicate
+ \\ Flag with a
+ \\ complicated and
+ \\ very long
+ \\ description that
+ \\ spans multiple
+ \\ lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something
+ \\ something
+ \\ something
+ \\
+ \\-d, --dd
+ \\ Both option.
+ \\
+ \\-d, --dd ...
+ \\ Both repeated
+ \\ option.
+ \\
+ );
+
+ try testHelp(.{
+ .indent = 0,
+ .max_width = 46,
+ .description_on_new_line = false,
+ },
+ \\-a Short flag.
+ \\
+ \\-b Short option.
+ \\
+ \\ --aa Long flag.
+ \\
+ \\ --bb Long option.
+ \\
+ \\-c, --cc Both flag.
+ \\
+ \\ --complicate Flag with a
+ \\ complicated and very
+ \\ long description that
+ \\ spans multiple lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something
+ \\ something
+ \\ something
+ \\
+ \\-d, --dd Both option.
+ \\
+ \\-d, --dd ... Both repeated option.
+ \\
+ );
+
+ try testHelp(.{
+ .indent = 0,
+ .max_width = 46,
+ .description_on_new_line = false,
+ .description_indent = 4,
+ },
+ \\-a Short flag.
+ \\
+ \\-b Short option.
+ \\
+ \\ --aa Long flag.
+ \\
+ \\ --bb Long option.
+ \\
+ \\-c, --cc Both flag.
+ \\
+ \\ --complicate Flag with a complicated
+ \\ and very long description
+ \\ that spans multiple
+ \\ lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something something
+ \\ something
+ \\
+ \\-d, --dd Both option.
+ \\
+ \\-d, --dd ... Both repeated option.
+ \\
+ );
+
+ try testHelp(.{
+ .indent = 0,
+ .max_width = 46,
+ .description_on_new_line = false,
+ .description_indent = 4,
+ .spacing_between_parameters = 0,
+ },
+ \\-a Short flag.
+ \\-b Short option.
+ \\ --aa Long flag.
+ \\ --bb Long option.
+ \\-c, --cc Both flag.
+ \\ --complicate Flag with a complicated
+ \\ and very long description
+ \\ that spans multiple
+ \\ lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something something
+ \\ something
+ \\-d, --dd Both option.
+ \\-d, --dd ... Both repeated option.
+ \\
+ );
+
+ try testHelp(.{
+ .indent = 0,
+ .max_width = 46,
+ .description_on_new_line = false,
+ .description_indent = 4,
+ .spacing_between_parameters = 2,
+ },
+ \\-a Short flag.
+ \\
+ \\
+ \\-b Short option.
+ \\
+ \\
+ \\ --aa Long flag.
+ \\
+ \\
+ \\ --bb Long option.
+ \\
+ \\
+ \\-c, --cc Both flag.
+ \\
+ \\
+ \\ --complicate Flag with a complicated
+ \\ and very long description
+ \\ that spans multiple
+ \\ lines.
+ \\
+ \\ Paragraph number 2:
+ \\ * Bullet point
+ \\ * Bullet point
+ \\
+ \\ Example:
+ \\ something something
+ \\ something
+ \\
+ \\
+ \\-d, --dd Both option.
+ \\
+ \\
+ \\-d, --dd ... Both repeated option.
+ \\
+ );
}
/// Will print a usage message in the following format:
@@ -1104,7 +1699,6 @@ pub fn usage(stream: anytype, comptime Id: type, params: []const Param(Id)) !voi
continue;
const prefix = if (param.names.short) |_| "-" else "--";
-
const name = if (param.names.short) |*s|
// Seems the zig compiler is being a little wierd. I doesn't allow me to write
// @as(*const [1]u8, s)
diff --git a/example/README.md.template b/example/README.md.template
index b76ae45..8b12cd6 100644
--- a/example/README.md.template
+++ b/example/README.md.template
@@ -58,7 +58,8 @@ is generated at runtime.
The `help` prints a simple list of all parameters the program can take. It expects the
`Id` to have a `description` method and an `value` method so that it can provide that
-in the output.
+in the output. `HelpOptions` is passed to `help` to control how the help message is
+printed.
```zig
{s}
@@ -66,8 +67,11 @@ in the output.
```
$ zig-out/bin/help --help
- -h, --help Display this help and exit.
- -v, --version Output version information and exit.
+ -h, --help
+ Display this help and exit.
+
+ -v, --version
+ Output version information and exit.
```
### `usage`
diff --git a/example/help.zig b/example/help.zig
index 64d1709..18d61b9 100644
--- a/example/help.zig
+++ b/example/help.zig
@@ -15,5 +15,5 @@ pub fn main() !void {
// slice of Param(Help). There is also a helpEx, which can print a
// help message for any Param, but it is more verbose to call.
if (res.args.help)
- return clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms);
+ return clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{});
}
--
cgit v1.2.3