Template
Extension discovery (plan todo 20): scans --ext-dir dirs, STUPIDTOOLS_EXT, the XDG user dir and a builtin-ext dir for *.lua modules, runs each in the sandboxed Lua runtime, and enumerates its registrations; the builtin C/C++ modules load first via st_ext_init_builtins. Fail-fast with an error naming file and line on any malformed/sandbox-violating module. The CLI gains a repeatable --ext-dir flag; with flag or env present main.c runs discovery and prints 'loaded extension: ...' lines from actual registrations (interim wiring until todo 23). Note: src/Makefile.am gained the ext + vendored Lua sources because the binary otherwise cannot link discovery -- required for the root-verifiable CLI acceptance.
45 lines
1.4 KiB
C
45 lines
1.4 KiB
C
/*
|
|
* 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
|
|
|
|
/* 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 */
|