diff options
| author | Lion Kortlepel <[email protected]> | 2026-02-01 12:58:37 +0000 |
|---|---|---|
| committer | Lion Kortlepel <[email protected]> | 2026-02-01 12:58:37 +0000 |
| commit | 3c7b67aceb1ccf75e71358e84d9cc58d01b9abd5 (patch) | |
| tree | ebaaac40bf7a291002abfa3a91f4f7535382c92a /ls_args.h | |
| parent | a29480c901a92a1b1891b4edc3239f8d997a3f9d (diff) | |
| download | args-3c7b67aceb1ccf75e71358e84d9cc58d01b9abd5.tar.zst args-3c7b67aceb1ccf75e71358e84d9cc58d01b9abd5.zip | |
feat: add help option printing, add descriptionv2.2
Diffstat (limited to 'ls_args.h')
| -rw-r--r-- | ls_args.h | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -1,7 +1,7 @@ /* Lion's Standard (LS) ANSI C commandline argument parser with included help * renderer. * - * Version: 2.1 + * Version: 2.2 * Website: https://libls.org * Repo: https://github.com/libls/args * SPDX-License-Identifier: MIT @@ -136,6 +136,9 @@ typedef struct ls_args { * if you want to, for whatever reason. */ const char* program_name; + /* description rendered under the "usage" line in ls_args_help */ + const char* help_description; + /* some bookkeeping -- these are used to free dynamically allocated memory * for help or errors cleanly on `ls_args_free`. */ void* _allocated_error; @@ -700,6 +703,32 @@ char* ls_args_help(ls_args* a) { goto alloc_fail; } } + if (a->help_description) { + if (!_lsa_buffer_append_cstr(&help, "\n\n")) + goto alloc_fail; + if (!_lsa_buffer_append_cstr(&help, a->help_description)) + goto alloc_fail; + } + if (!_lsa_buffer_append_cstr(&help, "\n\nOptions:")) + goto alloc_fail; + for (i = 0; i < a->args_len; ++i) { + if (!a->args[i].is_pos) { + if (!_lsa_buffer_append_cstr(&help, "\n -")) + goto alloc_fail; + if (!_lsa_buffer_append_cstr( + &help, a->args[i].match.name.short_opt)) + goto alloc_fail; + if (!_lsa_buffer_append_cstr(&help, " \t--")) + goto alloc_fail; + if (!_lsa_buffer_append_cstr( + &help, a->args[i].match.name.long_opt)) + goto alloc_fail; + if (!_lsa_buffer_append_cstr(&help, " \t\t")) + goto alloc_fail; + if (!_lsa_buffer_append_cstr(&help, a->args[i].help)) + goto alloc_fail; + } + } } a->_allocated_help = help.data; |
