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

View File

@ -1,10 +1,10 @@
.\" Manpage for gamemoded. .\" Manpage for gamemoded.
.\" Contact linux-contact@feralinteractive.com to correct errors or typos. .\" Contact linux-contact@feralinteractive.com to correct errors or typos.
.TH gamemoded 1 "23 Feb 2018" "0.3" "gamemoded man page" .TH gamemoded 1 "6 March 2018" "0.3" "gamemoded man page"
.SH NAME .SH NAME
gamemoded \- optimises system performance on demand gamemoded \- optimises system performance on demand
.SH SYNOPSIS .SH SYNOPSIS
\fBgamemoded\fR [\fB\-d\fR] [\fB\-l\fR] \fBgamemoded\fR [\fB\-d\fR] [\fB\-l\fR] [\fB\-h\fR] [\fB\-v\fR]
.SH DESCRIPTION .SH DESCRIPTION
\fBGameMode\fR is a daemon/lib combo for Linux that allows games to request a set of optimisations be temporarily applied to the host OS. \fBGameMode\fR is a daemon/lib combo for Linux that allows games to request a set of optimisations be temporarily applied to the host OS.
@ -15,10 +15,16 @@ The design has a clear cut abstraction between the host daemon and library (\fBg
.TP 8 .TP 8
.B \-d .B \-d
Run the daemon as a separate process (daemonize it) Run the daemon as a separate process (daemonize it)
.TP .TP 8
.B \-l .B \-l
Log to syslog Log to syslog
.LP .TP 8
.B \-h
Print help text
.TP 8
.B \-v
Print the version
.SH USAGE .SH USAGE
\fBlibgamemodeauto.so\fR can be pre-loaded into any program to request \fBgamemoded\fR begin or end the mode, like so: \fBlibgamemodeauto.so\fR can be pre-loaded into any program to request \fBgamemoded\fR begin or end the mode, like so:

View File

@ -66,9 +66,10 @@ path_polkit_action_dir = join_paths(path_datadir, 'polkit-1', 'actions')
with_daemon = get_option('with-daemon') with_daemon = get_option('with-daemon')
with_examples = get_option('with-examples') with_examples = get_option('with-examples')
# Provide config.h so the daemon knows where the helper is # Provide a config.h
cdata = configuration_data() cdata = configuration_data()
cdata.set_quoted('LIBEXECDIR', path_libexecdir) cdata.set_quoted('LIBEXECDIR', path_libexecdir)
cdata.set_quoted('GAMEMODE_VERSION', meson.project_version())
config_h = configure_file( config_h = configure_file(
configuration: cdata, configuration: cdata,
output: 'config.h', output: 'config.h',