mirror of
https://github.com/perk11/runwhenidle.git
synced 2026-01-11 06:37:55 -05:00
Add --version argument
This commit is contained in:
3
Makefile
3
Makefile
@@ -6,7 +6,6 @@ ifeq ($(PREFIX),)
|
||||
endif
|
||||
SOURCES = time_utils.c sleep_utils.c main.c
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
|
||||
all: executable
|
||||
|
||||
release: CCFLAGS += -O3
|
||||
@@ -15,6 +14,8 @@ release: executable
|
||||
debug: CCFLAGS += -DDEBUG -ggdb
|
||||
debug: executable
|
||||
|
||||
executable: CCFLAGS += -DVERSION=\"$(shell git describe --tags 2>/dev/null || (echo -n "0.0-dev-" && git rev-parse HEAD))\"
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CCFLAGS) -c $< -o $@ $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
|
||||
1
TODO.txt
1
TODO.txt
@@ -1,6 +1,5 @@
|
||||
Here are the planned changes:
|
||||
|
||||
* Add support for --version|-V argument.
|
||||
* AUR package.
|
||||
* Look more into Wayland support.
|
||||
* ?Test coverage?
|
||||
|
||||
15
main.c
15
main.c
@@ -13,6 +13,10 @@
|
||||
#include "sleep_utils.h"
|
||||
#include "time_utils.h"
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION 'unkown'
|
||||
#endif
|
||||
|
||||
int verbose;
|
||||
int quiet;
|
||||
|
||||
@@ -50,9 +54,12 @@ void resume_command(pid_t pid) {
|
||||
}
|
||||
|
||||
void print_usage(char *binary_name) {
|
||||
printf("Usage: %s [--timeout|-t timeout_value_in_seconds] [--verbose|-v] [--quiet|-q] shell_command_to_run\n",
|
||||
printf("Usage: %s [--timeout|-t timeout_value_in_seconds] [--verbose|-v] [--quiet|-q] [--version|-V] shell_command_to_run [shell_command_arguments]\n",
|
||||
binary_name);
|
||||
}
|
||||
void print_version() {
|
||||
printf("runwhenidle %s\n", VERSION);
|
||||
}
|
||||
|
||||
pid_t run_shell_command(const char *shell_command_to_run, pid_t pid) {
|
||||
if (verbose) {
|
||||
@@ -138,12 +145,13 @@ int main(int argc, char *argv[]) {
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"quiet", no_argument, NULL, 'q'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
// Parse command line options
|
||||
int option;
|
||||
while ((option = getopt_long(argc, argv, "+hvqt:", long_options, NULL)) != -1) {
|
||||
while ((option = getopt_long(argc, argv, "+hvqt:V", long_options, NULL)) != -1) {
|
||||
switch (option) {
|
||||
case 't':
|
||||
const long TIMEOUT_MAX_SUPPORTED_VALUE = 100000000; //~3 years
|
||||
@@ -156,6 +164,9 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
user_idle_timeout_ms = timeout_arg_value * 1000;
|
||||
break;
|
||||
case 'V':
|
||||
print_version();
|
||||
return 0;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user