From 4fe027c28db21e4355661010be4e78a12268e0f7 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sun, 29 Sep 2024 12:49:43 +0300 Subject: Add check for env variable --- main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index c15b25f..bbc5dfd 100644 --- a/main.c +++ b/main.c @@ -17,9 +17,9 @@ const char *CPTC_token; static struct option long_options[] = { - {"help", no_argument, NULL, 'h'}, - {"host", no_argument, NULL, 'i'}, - {"port", no_argument, NULL, 'p'}, + {"help", 1, NULL, 'h'}, + {"host", 1, NULL, 'i'}, + {"port", 1, NULL, 'p'}, {0} }; @@ -56,7 +56,6 @@ int main(int argc, char **argv) int port = 8080; int ch; - CPTC_token = getenv("CPTC_TOKEN"); while ((ch = getopt_long(argc, argv, "hi:p:", long_options, NULL)) != EOF) { switch (ch) @@ -80,6 +79,12 @@ int main(int argc, char **argv) /* NOTREACHED */ } } + CPTC_token = getenv("CPTC_TOKEN"); + if (!CPTC_token) + { + fprintf(stderr, "%s: CPTC_TOKEN is not set\n", argv[0]); + usage(argv[0], false); + } CPTC(address, port); } -- cgit 1.4.1