Add -h and -v and augment the usage text with option descriptions

This commit is contained in:
Marc Di Luzio
2018-03-06 16:20:16 +00:00
parent 24a192d594
commit 142246366f
3 changed files with 34 additions and 7 deletions

View File

@@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define _GNU_SOURCE
#include "config.h"
#include "daemonize.h"
#include "dbus_messaging.h"
#include "gamemode.h"
@@ -58,6 +59,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <unistd.h>
#define USAGE_TEXT \
"Usage: %s [-d] [-l] [-h] [-v]\n\n" \
" -d daemonize self after launch\n" \
" -l log to syslog\n" \
" -h print this help\n" \
" -v print version\n" \
"\n" \
"See man page for more information.\n"
#define VERSION_TEXT "gamemode version: v" GAMEMODE_VERSION "\n"
static void sigint_handler(__attribute__((unused)) int signo)
{
LOG_MSG("Quitting by request...\n");
@@ -79,7 +91,7 @@ int main(int argc, char *argv[])
bool daemon = false;
bool use_syslog = false;
int opt = 0;
while ((opt = getopt(argc, argv, "dl")) != -1) {
while ((opt = getopt(argc, argv, "dlvh")) != -1) {
switch (opt) {
case 'd':
daemon = true;
@@ -87,8 +99,16 @@ int main(int argc, char *argv[])
case 'l':
use_syslog = true;
break;
case 'v':
fprintf(stdout, VERSION_TEXT);
exit(EXIT_SUCCESS);
break;
case 'h':
fprintf(stdout, USAGE_TEXT, argv[0]);
exit(EXIT_SUCCESS);
break;
default:
fprintf(stderr, "Usage: %s [-d] [-l]\n", argv[0]);
fprintf(stderr, USAGE_TEXT, argv[0]);
exit(EXIT_FAILURE);
break;
}