Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a0db9fe authored by Felipe Leme's avatar Felipe Leme
Browse files

Improved usage on invalid args.

BUG: 26379932
Test: manual
Change-Id: I89689fa98ebe8ed112038575a614ea81d821d16e
parent a034de98
Loading
Loading
Loading
Loading
+38 −33
Original line number Diff line number Diff line
@@ -1141,7 +1141,7 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver
    printf("========================================================\n");
}

static void usage() {
static void ShowUsageAndExit(int exitCode = 1) {
    fprintf(stderr,
            "usage: dumpstate [-h] [-b soundfile] [-e soundfile] [-o file [-d] [-p] "
            "[-z]] [-s] [-S] [-q] [-B] [-P] [-R] [-V version]\n"
@@ -1162,6 +1162,12 @@ static void usage() {
            "shouldn't be used with -P)\n"
            "  -V: sets the bugreport format version (valid values: %s)\n",
            VERSION_DEFAULT.c_str());
    exit(exitCode);
}

static void ExitOnInvalidArgs() {
    fprintf(stderr, "invalid combination of args\n");
    ShowUsageAndExit();
}

static void wake_lock_releaser() {
@@ -1353,8 +1359,12 @@ int main(int argc, char *argv[]) {
            case 'R': is_remote_mode = 1;       break;
            case 'B': do_broadcast = 1;         break;
            case 'V': version = optarg;         break;
            case '?': printf("\n");
            case 'h': usage(); exit(1);
            case 'h':
                ShowUsageAndExit(0);
                break;
            default:
                fprintf(stderr, "Invalid option: %c\n", c);
                ShowUsageAndExit();
                // clang-format on
        }
    }
@@ -1382,28 +1392,23 @@ int main(int argc, char *argv[]) {
    }

    if ((do_zip_file || do_add_date || ds.updateProgress_ || do_broadcast) && !use_outfile) {
        usage();
        exit(1);
        ExitOnInvalidArgs();
    }

    if (use_control_socket && !do_zip_file) {
        usage();
        exit(1);
        ExitOnInvalidArgs();
    }

    if (ds.updateProgress_ && !do_broadcast) {
        usage();
        exit(1);
        ExitOnInvalidArgs();
    }

    if (is_remote_mode && (ds.updateProgress_ || !do_broadcast || !do_zip_file || !do_add_date)) {
        usage();
        exit(1);
        ExitOnInvalidArgs();
    }

    if (version != VERSION_DEFAULT) {
      usage();
      exit(1);
        ShowUsageAndExit();
    }

    MYLOGI("bugreport format version: %s\n", version.c_str());