feat(cli): add entrypoint with --help/--version and exit codes

This commit is contained in:
2026-08-28 19:48:33 -04:00
parent 238db8b484
commit b5718b7487
5 changed files with 262 additions and 10 deletions
+36
View File
@@ -0,0 +1,36 @@
/*
* cli.h - argument parsing for the stupidtools entrypoint.
*
* Copyright (c) 2026 huntedbytheirs
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef STUPIDTOOLS_CLI_H
#define STUPIDTOOLS_CLI_H
#include <stdio.h>
/* Must match AC_INIT version in configure.ac (todo 1: 1.0.0). */
#define STUPIDTOOLS_VERSION "1.0.0"
#define CLI_EXIT_OK 0
#define CLI_EXIT_RUNTIME 1
#define CLI_EXIT_USAGE 2
/* What the caller should do after parsing argv. */
enum cli_action {
CLI_ACTION_RUN, /* proceed with the parsed buildfile (todo 16+) */
CLI_ACTION_HELP, /* usage already printed to stdout, exit 0 */
CLI_ACTION_VERSION, /* caller prints the version line, exit 0 */
CLI_ACTION_ERROR /* error + usage already printed to stderr, exit 2 */
};
struct cli_opts {
const char *program; /* argv[0] as given (or a default) */
const char *buildfile; /* single positional buildfile, NULL if none */
};
enum cli_action cli_parse(int argc, char **argv, struct cli_opts *opts);
void cli_print_usage(FILE *stream, const char *program);
#endif /* STUPIDTOOLS_CLI_H */