From 3aa4e243faa8198550cb2851cb6f0b9cbb293812 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 5 Jun 2020 18:42:20 +0200 Subject: tools: Add --version command line switch --- tools/idevicename.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'tools/idevicename.c') diff --git a/tools/idevicename.c b/tools/idevicename.c index af80dcc..5a34ea0 100644 --- a/tools/idevicename.c +++ b/tools/idevicename.c @@ -23,6 +23,8 @@ #include #endif +#define TOOL_NAME "idevicename" + #include #include #include @@ -45,6 +47,7 @@ static void print_usage(void) printf(" -d, --debug\t\tenable communication debugging\n"); printf(" -u, --udid UDID\ttarget specific device by UDID\n"); printf(" -h, --help\t\tprint usage information\n"); + printf(" -v, --version\t\tprint version information\n"); printf("\n"); printf("Homepage: <" PACKAGE_URL ">\n"); printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n"); @@ -52,22 +55,22 @@ static void print_usage(void) int main(int argc, char** argv) { - int res = -1; - char* udid = NULL; - int c = 0; - int optidx = 0; const struct option longopts[] = { - { "udid", required_argument, NULL, 'u' }, - { "help", no_argument, NULL, 'h' }, + { "udid", required_argument, NULL, 'u' }, + { "debug", no_argument, NULL, 'd' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0} }; + int res = -1; + char* udid = NULL; #ifndef WIN32 signal(SIGPIPE, SIG_IGN); #endif - while ((c = getopt_long(argc, argv, "du:h", longopts, &optidx)) != -1) { + while ((c = getopt_long(argc, argv, "du:hv", longopts, NULL)) != -1) { switch (c) { case 'u': if (!*optarg) { @@ -84,9 +87,12 @@ int main(int argc, char** argv) case 'd': idevice_set_debug_level(1); break; + case 'v': + printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); + return 0; default: print_usage(); - return -1; + return 2; } } @@ -105,7 +111,7 @@ int main(int argc, char** argv) } lockdownd_client_t lockdown = NULL; - lockdownd_error_t lerr = lockdownd_client_new_with_handshake(device, &lockdown, "idevicename"); + lockdownd_error_t lerr = lockdownd_client_new_with_handshake(device, &lockdown, TOOL_NAME); if (lerr != LOCKDOWN_E_SUCCESS) { idevice_free(device); fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", lerr); -- cgit v1.1-32-gdbae