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).
This commit is contained in:
Romain Vimont 2018-02-14 18:57:29 +01:00
parent 23d92a95b6
commit 8697659890

View File

@ -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;