diff options
| author | 2021-09-05 13:14:17 -0700 | |
|---|---|---|
| committer | 2021-09-05 22:29:35 +0200 | |
| commit | 4be3fcdb616647215dc162c9e2f64b7d6e3ad09d (patch) | |
| tree | bc2526beb08dc141170cb4542407c30b48676021 | |
| parent | Use debug.print instead of deprecated debug.warn in examples (diff) | |
| download | zig-clap-4be3fcdb616647215dc162c9e2f64b7d6e3ad09d.tar.gz zig-clap-4be3fcdb616647215dc162c9e2f64b7d6e3ad09d.tar.xz zig-clap-4be3fcdb616647215dc162c9e2f64b7d6e3ad09d.zip | |
Indent help text on every new line to allow for user-controlled wrapping
| -rw-r--r-- | clap.zig | 15 |
1 files changed, 14 insertions, 1 deletions
| @@ -408,7 +408,16 @@ pub fn helpFull( | |||
| 408 | try stream.print("\t", .{}); | 408 | try stream.print("\t", .{}); |
| 409 | try printParam(cs.writer(), Id, param, Error, context, valueText); | 409 | try printParam(cs.writer(), Id, param, Error, context, valueText); |
| 410 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); | 410 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); |
| 411 | try stream.print("\t{s}\n", .{try helpText(context, param)}); | 411 | const help_text = try helpText(context, param); |
| 412 | var help_text_line_it = mem.split(help_text, "\n"); | ||
| 413 | var indent_line = false; | ||
| 414 | while (help_text_line_it.next()) |line| : (indent_line = true) { | ||
| 415 | if (indent_line) { | ||
| 416 | try stream.print("\t", .{}); | ||
| 417 | try stream.writeByteNTimes(' ', max_spacing); | ||
| 418 | } | ||
| 419 | try stream.print("\t{s}\n", .{line}); | ||
| 420 | } | ||
| 412 | } | 421 | } |
| 413 | } | 422 | } |
| 414 | 423 | ||
| @@ -509,6 +518,7 @@ test "clap.help" { | |||
| 509 | parseParam("--aa Long flag.") catch unreachable, | 518 | parseParam("--aa Long flag.") catch unreachable, |
| 510 | parseParam("--bb <V2> Long option.") catch unreachable, | 519 | parseParam("--bb <V2> Long option.") catch unreachable, |
| 511 | parseParam("-c, --cc Both flag.") catch unreachable, | 520 | parseParam("-c, --cc Both flag.") catch unreachable, |
| 521 | parseParam("--complicate Flag with a complicated and\nvery long description that\nspans multiple lines.") catch unreachable, | ||
| 512 | parseParam("-d, --dd <V3> Both option.") catch unreachable, | 522 | parseParam("-d, --dd <V3> Both option.") catch unreachable, |
| 513 | parseParam("-d, --dd <V3>... Both repeated option.") catch unreachable, | 523 | parseParam("-d, --dd <V3>... Both repeated option.") catch unreachable, |
| 514 | parseParam( | 524 | parseParam( |
| @@ -523,6 +533,9 @@ test "clap.help" { | |||
| 523 | "\t --aa \tLong flag.\n" ++ | 533 | "\t --aa \tLong flag.\n" ++ |
| 524 | "\t --bb <V2> \tLong option.\n" ++ | 534 | "\t --bb <V2> \tLong option.\n" ++ |
| 525 | "\t-c, --cc \tBoth flag.\n" ++ | 535 | "\t-c, --cc \tBoth flag.\n" ++ |
| 536 | "\t --complicate\tFlag with a complicated and\n" ++ | ||
| 537 | "\t \tvery long description that\n" ++ | ||
| 538 | "\t \tspans multiple lines.\n" ++ | ||
| 526 | "\t-d, --dd <V3> \tBoth option.\n" ++ | 539 | "\t-d, --dd <V3> \tBoth option.\n" ++ |
| 527 | "\t-d, --dd <V3>...\tBoth repeated option.\n"; | 540 | "\t-d, --dd <V3>...\tBoth repeated option.\n"; |
| 528 | 541 | ||