Add CLI version and help options

This commit is contained in:
Johannes Findeisen 2026-11-29 22:58:02 +01:00
commit 54d44d370b
2 changed files with 19 additions and 1 deletions

View file

@ -15,6 +15,9 @@ make
./irc9 -s myconfig.conf # hide channel activity notices ./irc9 -s myconfig.conf # hide channel activity notices
``` ```
`-v` and `--version` print the program version. `-h` and `--help` print the
version and command-line usage.
`-s` and `--silent` hide channel join, quit, leave, and sync notices, as well as `-s` and `--silent` hide channel join, quit, leave, and sync notices, as well as
nickname-change and mode-change notices. nickname-change and mode-change notices.
`-C` and `--colored` color nicknames in channel and private chats and in `-C` and `--colored` color nicknames in channel and private chats and in

17
irc9.c
View file

@ -49,6 +49,8 @@
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#endif #endif
#define IRC9_VERSION "1.0"
#define HOSTLEN 128 #define HOSTLEN 128
#define NICKLEN 64 #define NICKLEN 64
#define CHANLEN 128 #define CHANLEN 128
@ -2946,6 +2948,12 @@ static const char *find_config(void)
return home_path; return home_path;
} }
static void print_usage(FILE *out, const char *program)
{
fprintf(out, "usage: %s [-h|--help] [-v|--version] [-s|--silent] "
"[-C|--colored] [-c|--color RRGGBB] [config]\n", program);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
const char *path = NULL; const char *path = NULL;
@ -2954,6 +2962,13 @@ int main(int argc, char **argv)
const char *arg = argv[i]; const char *arg = argv[i];
if (options && strcmp(arg, "--") == 0) { if (options && strcmp(arg, "--") == 0) {
options = 0; options = 0;
} else if (options && (strcmp(arg, "-v") == 0 || strcmp(arg, "--version") == 0)) {
puts("irc9 " IRC9_VERSION);
return 0;
} else if (options && (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)) {
puts("irc9 " IRC9_VERSION);
print_usage(stdout, argv[0]);
return 0;
} else if (options && (strcmp(arg, "-s") == 0 || strcmp(arg, "--silent") == 0)) { } else if (options && (strcmp(arg, "-s") == 0 || strcmp(arg, "--silent") == 0)) {
silent = 1; silent = 1;
} else if (options && (strcmp(arg, "-C") == 0 || strcmp(arg, "--colored") == 0)) { } else if (options && (strcmp(arg, "-C") == 0 || strcmp(arg, "--colored") == 0)) {
@ -2968,7 +2983,7 @@ int main(int argc, char **argv)
} else if (!path && (!options || arg[0] != '-' || arg[1] == 0)) { } else if (!path && (!options || arg[0] != '-' || arg[1] == 0)) {
path = arg; path = arg;
} else { } else {
fprintf(stderr, "usage: %s [-s|--silent] [-C|--colored] [-c|--color RRGGBB] [config]\n", argv[0]); print_usage(stderr, argv[0]);
return 1; return 1;
} }
} }