aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLion Kortlepel <[email protected]>2026-02-01 12:58:37 +0000
committerLion Kortlepel <[email protected]>2026-02-01 12:58:37 +0000
commit3c7b67aceb1ccf75e71358e84d9cc58d01b9abd5 (patch)
treeebaaac40bf7a291002abfa3a91f4f7535382c92a /examples
parenta29480c901a92a1b1891b4edc3239f8d997a3f9d (diff)
downloadargs-3c7b67aceb1ccf75e71358e84d9cc58d01b9abd5.tar.zst
args-3c7b67aceb1ccf75e71358e84d9cc58d01b9abd5.zip
feat: add help option printing, add descriptionv2.2
Diffstat (limited to 'examples')
-rw-r--r--examples/basic_example.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/examples/basic_example.c b/examples/basic_example.c
index 2f77b6c..43413f4 100644
--- a/examples/basic_example.c
+++ b/examples/basic_example.c
@@ -9,24 +9,24 @@ int main(int argc, char** argv) {
const char* testfile;
ls_args_init(&args);
+ args.help_description = "An example program to show how arguments work. "
+ "Provide an input file and optionally an output "
+ "file and test file and see what happens!";
ls_args_bool(&args, &help, "h", "help", "Prints help", 0);
ls_args_string(&args, &outfile, "o", "out",
"Specify the outfile, default 'out.txt'", 0);
- ls_args_pos_string(&args, &infile, "Input file", LS_ARGS_REQUIRED);
- ls_args_pos_string(&args, &testfile, "Test file", 0);
+ ls_args_pos_string(&args, &infile, "input file", LS_ARGS_REQUIRED);
+ ls_args_pos_string(&args, &testfile, "test file", 0);
if (!ls_args_parse(&args, argc, argv)) {
- printf("Error: %s\n", args.last_error);
- puts(ls_args_help(&args));
+ if (help) {
+ puts(ls_args_help(&args));
+ } else {
+ printf("Error: %s\n", args.last_error);
+ }
ls_args_free(&args);
return 1;
}
- if (help) {
- puts(ls_args_help(&args));
- ls_args_free(&args);
- return 0;
- }
-
printf("Got input file: %s\n", infile);
printf("Got output file: %s\n", outfile);
printf("Got test file: %s\n", testfile);