diff options
| author | Lion Kortlepel <[email protected]> | 2026-02-01 12:34:45 +0000 |
|---|---|---|
| committer | Lion Kortlepel <[email protected]> | 2026-02-01 12:34:45 +0000 |
| commit | 1f51309907acb1bed6e588961ccb4a6a792b85c0 (patch) | |
| tree | db8b5a6168bc73dbbe034d2b5d449c27c8c7c86d /examples | |
| parent | acf522e7bab50b24ec702b405b4e450b65f835cd (diff) | |
| download | args-1f51309907acb1bed6e588961ccb4a6a792b85c0.tar.zst args-1f51309907acb1bed6e588961ccb4a6a792b85c0.zip | |
feat!: break api by removing `n` from positionals, implement help string
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/basic_example.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/examples/basic_example.c b/examples/basic_example.c index 293d5c5..2f77b6c 100644 --- a/examples/basic_example.c +++ b/examples/basic_example.c @@ -5,13 +5,32 @@ int main(int argc, char** argv) { ls_args args; int help = 0; const char* outfile = "out.txt"; + const char* infile; + const char* testfile; ls_args_init(&args); 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_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); if (!ls_args_parse(&args, argc, argv)) { - printf("Error: %s\n%s\n", args.last_error, ls_args_help(&args)); + printf("Error: %s\n", args.last_error); + puts(ls_args_help(&args)); + 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); + ls_args_free(&args); return 0; } |
