Add CLI version and help options
This commit is contained in:
parent
d4f2301175
commit
54d44d370b
2 changed files with 19 additions and 1 deletions
|
|
@ -15,6 +15,9 @@ make
|
|||
./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
|
||||
nickname-change and mode-change notices.
|
||||
`-C` and `--colored` color nicknames in channel and private chats and in
|
||||
|
|
|
|||
17
irc9.c
17
irc9.c
|
|
@ -49,6 +49,8 @@
|
|||
#include <openssl/x509v3.h>
|
||||
#endif
|
||||
|
||||
#define IRC9_VERSION "1.0"
|
||||
|
||||
#define HOSTLEN 128
|
||||
#define NICKLEN 64
|
||||
#define CHANLEN 128
|
||||
|
|
@ -2946,6 +2948,12 @@ static const char *find_config(void)
|
|||
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)
|
||||
{
|
||||
const char *path = NULL;
|
||||
|
|
@ -2954,6 +2962,13 @@ int main(int argc, char **argv)
|
|||
const char *arg = argv[i];
|
||||
if (options && strcmp(arg, "--") == 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)) {
|
||||
silent = 1;
|
||||
} 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)) {
|
||||
path = arg;
|
||||
} else {
|
||||
fprintf(stderr, "usage: %s [-s|--silent] [-C|--colored] [-c|--color RRGGBB] [config]\n", argv[0]);
|
||||
print_usage(stderr, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue