diff options
| author | Nakidai <nakidai@disroot.org> | 2024-09-29 12:49:43 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-09-29 12:49:43 +0300 |
| commit | 4fe027c28db21e4355661010be4e78a12268e0f7 (patch) | |
| tree | 4f3f7c1052ccee877a25f94abae8b1669fdb2359 | |
| parent | 87e288476014ee7c3810d60361bbb58baf3c3cf6 (diff) | |
| download | cptc-4fe027c28db21e4355661010be4e78a12268e0f7.tar.gz cptc-4fe027c28db21e4355661010be4e78a12268e0f7.zip | |
Add check for env variable
| -rw-r--r-- | main.c | 13 |
1 files 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); } |