Add --version option
This commit is contained in:
parent
78ca637d96
commit
9d17aeaddf
4 changed files with 32 additions and 4 deletions
|
@ -33,5 +33,6 @@ void print_help(){
|
|||
std::cout << "-b --bus\n\tUSB bus id, requires -d.\n";
|
||||
std::cout << "-d --device\n\tUSB device number, requires -b.\n";
|
||||
std::cout << "-k --kernel-driver\n\tDo not attempt to detach kernel driver.\n";
|
||||
std::cout << "-v --version\n\tPrint version.\n";
|
||||
//std::cout << "-r --repeat\n\tSets number of times the macro will be repeated (1-255).\n";
|
||||
}
|
||||
|
|
6
makefile
6
makefile
|
@ -9,6 +9,9 @@ CC = g++
|
|||
CC_OPTIONS := -Wall -Wextra -O2 `pkg-config --cflags libusb-1.0`
|
||||
LIBS != pkg-config --libs libusb-1.0
|
||||
|
||||
# version string
|
||||
VERSION_STRING = "1.7"
|
||||
|
||||
# compile
|
||||
build: constructor.o data.o getters.o helpers.o load_config.o setters.o writers.o mouse_m908.o
|
||||
$(CC) *.o -o mouse_m908 $(LIBS) $(CC_OPTIONS)
|
||||
|
@ -22,6 +25,7 @@ install:
|
|||
cp ./example.macro $(DOC_DIR)/mouse_m908/ && \
|
||||
cp ./README.md $(DOC_DIR)/mouse_m908/ && \
|
||||
cp ./keymap.md $(DOC_DIR)/mouse_m908/ && \
|
||||
cp ./LICENSE $(DOC_DIR)/mouse_m908/ && \
|
||||
cp ./mouse_m908.1 $(MAN_DIR)/
|
||||
|
||||
# remove binary
|
||||
|
@ -40,7 +44,7 @@ upgrade: install
|
|||
|
||||
# individual files
|
||||
mouse_m908.o:
|
||||
$(CC) -c mouse_m908.cpp $(CC_OPTIONS)
|
||||
$(CC) -c mouse_m908.cpp $(CC_OPTIONS) -D VERSION_STRING=$(VERSION_STRING)
|
||||
|
||||
constructor.o:
|
||||
$(CC) -c include/constructor.cpp $(CC_OPTIONS)
|
||||
|
|
|
@ -40,6 +40,9 @@ USB device address, with this option the mouse gets opened by its bus id and dev
|
|||
.TP
|
||||
\fB\-k\fR, \fB\-\-kernel\-driver\fR
|
||||
Do not attempt to detach the kernel drivers. Useful for compatibility on some systems.
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-version\fR
|
||||
Print version.
|
||||
.SH EXAMPLES
|
||||
To send the configuration from example.ini
|
||||
.PP
|
||||
|
|
|
@ -30,6 +30,11 @@
|
|||
#include "include/load_config.h"
|
||||
#include "include/print_help.cpp"
|
||||
|
||||
// this is the default version string
|
||||
// the version string gets overwritten by the makefile
|
||||
#ifndef VERSION_STRING
|
||||
#define VERSION_STRING "no version defined during compilation"
|
||||
#endif
|
||||
|
||||
// this function checks its arguments and opens the mouse accordingly
|
||||
// (with vid and pid or with bus and device)
|
||||
|
@ -75,6 +80,12 @@ int main( int argc, char **argv ){
|
|||
|
||||
mouse_m908 m;
|
||||
|
||||
// if no arguments: print help
|
||||
if( argc == 1 ){
|
||||
print_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//command line options
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
|
@ -86,6 +97,7 @@ int main( int argc, char **argv ){
|
|||
{"bus", required_argument, 0, 'b'},
|
||||
{"device", required_argument, 0, 'd'},
|
||||
{"kernel-driver", no_argument, 0, 'k'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -93,6 +105,7 @@ int main( int argc, char **argv ){
|
|||
bool flag_macro = false, flag_number = false;
|
||||
bool flag_bus = false, flag_device = false;
|
||||
bool flag_kernel_driver = false;
|
||||
bool flag_version = false;
|
||||
//bool flag_repeat;
|
||||
std::string string_config, string_profile;
|
||||
std::string string_macro, string_number;
|
||||
|
@ -101,8 +114,8 @@ int main( int argc, char **argv ){
|
|||
|
||||
//parse command line options
|
||||
int c, option_index = 0;
|
||||
//while( (c = getopt_long( argc, argv, "hc:p:m:n:r:",
|
||||
while( (c = getopt_long( argc, argv, "hc:p:m:n:b:d:k",
|
||||
//while( (c = getopt_long( argc, argv, "hc:p:m:n:b:d:kvr:",
|
||||
while( (c = getopt_long( argc, argv, "hc:p:m:n:b:d:kv",
|
||||
long_options, &option_index ) ) != -1 ){
|
||||
|
||||
switch( c ){
|
||||
|
@ -141,6 +154,9 @@ int main( int argc, char **argv ){
|
|||
case 'k':
|
||||
flag_kernel_driver = true;
|
||||
break;
|
||||
case 'v':
|
||||
flag_version = true;
|
||||
break;
|
||||
case '?':
|
||||
break;
|
||||
default:
|
||||
|
@ -151,6 +167,10 @@ int main( int argc, char **argv ){
|
|||
// set wether to detach kernel driver
|
||||
m.set_detach_kernel_driver( !flag_kernel_driver );
|
||||
|
||||
// print version if requested
|
||||
if( flag_version )
|
||||
std::cout << "Version: " << VERSION_STRING << "\n";
|
||||
|
||||
// load and write config
|
||||
if( flag_config ){
|
||||
try{
|
||||
|
|
Loading…
Reference in a new issue