/* * 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 /* 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 /* Sane cap on repeated --ext-dir flags (todo 20). */ #define CLI_MAX_EXT_DIRS 32 /* 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 */ /* --ext-dir values, in the order given; the pointers are borrowed * from argv. STUPIDTOOLS_EXT is NOT merged here -- discovery reads * the environment itself and appends those dirs after these. */ const char *ext_dirs[CLI_MAX_EXT_DIRS]; size_t ext_dir_count; }; 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 */