From 8697659890090a4e7b2788a9db898519f3098ebb Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 14 Feb 2018 18:57:29 +0100 Subject: [PATCH] Expose device serial as an optional argument The device serial was provided as a positional argument: scrcpy 0123456789abcdef Instead, expose it as an optional argument, -s or --serial: scrcpy -s 0123456789abcdef This avoids inconsistency between platforms when the positional argument is passed before the options (which is undefined). --- app/src/main.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index c4276742..18c9f232 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -20,11 +20,7 @@ struct args { static void usage(const char *arg0) { fprintf(stderr, - "Usage: %s [options] [serial]\n" - "\n" - " serial\n" - " The device serial number. Mandatory only if several devices\n" - " are connected to adb.\n" + "Usage: %s [options]\n" "\n" "Options:\n" "\n" @@ -46,6 +42,10 @@ static void usage(const char *arg0) { " Set the TCP port the client listens on.\n" " Default is %d.\n" "\n" + " -s, --serial\n" + " The device serial number. Mandatory only if several devices\n" + " are connected to adb.\n" + "\n" " -v, --version\n" " Print the version of scrcpy.\n" "\n" @@ -177,11 +177,12 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { {"help", no_argument, NULL, 'h'}, {"max-size", required_argument, NULL, 'm'}, {"port", required_argument, NULL, 'p'}, + {"serial", required_argument, NULL, 's'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0 }, }; int c; - while ((c = getopt_long(argc, argv, "b:hm:p:v", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "b:hm:p:s:v", long_options, NULL)) != -1) { switch (c) { case 'b': { if (!parse_bit_rate(optarg, &args->bit_rate)) { @@ -205,6 +206,10 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { } break; } + case 's': { + args->serial = optarg; + break; + } case 'v': { args->version = SDL_TRUE; break; @@ -216,9 +221,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { } int index = optind; - if (index < argc) { - args->serial = argv[index++]; - } if (index < argc) { LOGE("Unexpected additional argument: %s", argv[index]); return SDL_FALSE;