summary refs log tree commit diff
diff options
context:
space:
mode:
authorwrmr2025-03-08 18:21:53 -0500
committerwrmr2025-03-08 18:21:53 -0500
commit8fb95c786b3c1bd2e4457fb80b0b436ec547483d (patch)
tree00bcc72064ecf13c5fd9404a0f45ae224cd81c91
parent4dda367d09e769fff4a8b20cde07d634ef062e0c (diff)
add -? / --help
-rw-r--r--main.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/main.c b/main.c
index 634127f..56edb04 100644
--- a/main.c
+++ b/main.c
@@ -273,6 +273,18 @@ int hvar_calc(Str param, Str *name, Str *val, Str filename) {
 	return 1;
 }
 
+void usage(const char *cmd) {
+	fprintf(stderr, "usage: %s -?\n"
+			"       %s [-s] [-c FILE] [-h NAME:ARG1[,ARG2,ARG3...]] [FILES...]\n"
+			"\n"
+			" -? --help         show this help text\n"
+			" -s --standalone   prefix with html metadata\n"
+			" -h --hvar         define a css variable (--name) with a random value,\n"
+			"                   selected by a hash of the document's title\n"
+			" -c --css          embed the given file within a <style> element\n",
+			cmd, cmd);
+}
+
 #define countof(x) (sizeof(x) / sizeof(*x))
 int main(int argc, const char **argv) {
 	(void)argc;
@@ -294,10 +306,17 @@ int main(int argc, const char **argv) {
 	Str param = { 0 };
 	opts.from_stdin = 1;
 
-	while ((r = arg_get(&a, "sc:h:", &param, ":css", 'c', ":hvar", 'h')) >= ARG_OK) {
+	while ((r = arg_get(&a, "?sc:h:", &param,
+					"help", '?',
+					"standalone", 's',
+					":css", 'c',
+					":hvar", 'h')) >= ARG_OK) {
 		Arena reset = scratch;
 		FILE *f;
 		switch (r) {
+		case '?':
+			usage(argv[0]);
+			return 0;
 		case 's':
 			opts.standalone = 1;
 			break;
@@ -338,12 +357,12 @@ int main(int argc, const char **argv) {
 	case ARG_BAD:
 		fprintf(stderr, "unknown option '");
 		fwrite(param.s, 1, param.n, stderr);
-		fprintf(stderr, "'\n");
+		fprintf(stderr, "' (see %s --help)\n", argv[0]);
 		return 1;
 	case ARG_EMPTY:
 		fprintf(stderr, "'");
 		fwrite(param.s, 1, param.n, stderr);
-		fprintf(stderr, "' option expected an argument\n");
+		fprintf(stderr, "' option expected an argument (see %s --help)\n", argv[0]);
 		return 1;
 	}