Factor out common usage-help code

This commit is contained in:
Rangi42
2025-07-27 19:20:04 -04:00
parent 16e16cdf51
commit b2747dfbd8
9 changed files with 138 additions and 179 deletions

22
src/usage.cpp Normal file
View File

@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
#include "usage.hpp"
#include <stdio.h>
#include <stdlib.h>
void Usage::printAndExit(int code) const {
fputs(usage, stderr);
exit(code);
}
void Usage::printAndExit(char const *fmt, ...) const {
va_list args;
fputs("FATAL: ", stderr);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
putc('\n', stderr);
printAndExit(1);
}