From cc056cf4232721b62b76428d1ada447eecd98421 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Thu, 5 Mar 2020 23:24:36 +0100 Subject: Add clap.usage --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 0555a0f..47c028d 100644 --- a/README.md +++ b/README.md @@ -232,3 +232,46 @@ The `helpEx` is the generic version of `help`. It can print a help message for a The `helpFull` is even more generic, allowing the functions that get the help and value strings to return errors and take a context as a parameter. + +### `usage` + +The `usage`, `usageEx` and `usageFull` are functions for printing a simple list of all parameters the +program can take. + +```zig +const std = @import("std"); +const clap = @import("clap"); + +pub fn main() !void { + const stderr_file = try std.io.getStdErr(); + var stderr_out_stream = stderr_file.outStream(); + const stderr = &stderr_out_stream.stream; + + // clap.usage is a function that can print a simple usage message, given a + // slice of Param(Help). There is also a usageEx, which can print a + // usage message for any Param, but it is more verbose to call. + try clap.usage( + stderr, + comptime [_]clap.Param(clap.Help){ + clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, + clap.parseParam("-v, --version Output version information and exit.") catch unreachable, + clap.parseParam(" --value Output version information and exit.") catch unreachable, + }, + ); +} + +``` + +``` +[-hv] [--value ] +``` + +The `usage` functions are the simplest to call. It only takes an `OutStream` and a slice of +`Param(Help)`. + +The `usageEx` is the generic version of `usage`. It can print a usage message for any +`Param` give that the caller provides functions for getting the usage and value strings. + +The `usageFull` is even more generic, allowing the functions that get the usage and value strings +to return errors and take a context as a parameter. + -- cgit v1.2.3 From ca4b720d1b99f217559fe52d2be2146514d406a3 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Thu, 5 Mar 2020 23:28:11 +0100 Subject: Better readme for usage --- README.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 47c028d..12d691d 100644 --- a/README.md +++ b/README.md @@ -235,8 +235,8 @@ to return errors and take a context as a parameter. ### `usage` -The `usage`, `usageEx` and `usageFull` are functions for printing a simple list of all parameters the -program can take. +The `usage`, `usageEx` and `usageFull` are functions for printing a small abbreviated version +of the help message. ```zig const std = @import("std"); @@ -266,12 +266,3 @@ pub fn main() !void { [-hv] [--value ] ``` -The `usage` functions are the simplest to call. It only takes an `OutStream` and a slice of -`Param(Help)`. - -The `usageEx` is the generic version of `usage`. It can print a usage message for any -`Param` give that the caller provides functions for getting the usage and value strings. - -The `usageFull` is even more generic, allowing the functions that get the usage and value strings -to return errors and take a context as a parameter. - -- cgit v1.2.3