Skip to content

Commit

Permalink
Document exit status in --help
Browse files Browse the repository at this point in the history
Refs #3085 <#3085>
  • Loading branch information
rom1v committed Mar 10, 2022
1 parent b3f5dfe commit b1dbc30
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ struct sc_envvar {
const char *text;
};

struct sc_exit_status {
unsigned value;
const char *text;
};

struct sc_getopt_adapter {
char *optstring;
struct option *longopts;
Expand Down Expand Up @@ -662,7 +667,22 @@ static const struct sc_envvar envvars[] = {
{
.name = "SCRCPY_SERVER_PATH",
.text = "Path to the server binary",
}
},
};

static const struct sc_exit_status exit_statuses[] = {
{
.value = 0,
.text = "Normal program termination",
},
{
.value = 1,
.text = "Start failure",
},
{
.value = 2,
.text = "Device disconnected while running",
},
};

static char *
Expand Down Expand Up @@ -901,6 +921,25 @@ print_envvar(const struct sc_envvar *envvar, unsigned cols) {
free(text);
}

static void
print_exit_status(const struct sc_exit_status *status, unsigned cols) {
assert(cols > 8); // sc_str_wrap_lines() requires indent < columns
assert(status->text);

// The text starts at 9: 4 ident spaces, 3 chars for numeric value, 2 spaces
char *text = sc_str_wrap_lines(status->text, cols, 9);
if (!text) {
printf("<ERROR>\n");
return;
}

assert(strlen(text) >= 9); // Contains at least the initial identation

// text + 9 to remove the initial indentation
printf(" %3d %s\n", status->value, text + 9);
free(text);
}

void
scrcpy_print_usage(const char *arg0) {
#define SC_TERM_COLS_DEFAULT 80
Expand Down Expand Up @@ -939,6 +978,11 @@ scrcpy_print_usage(const char *arg0) {
for (size_t i = 0; i < ARRAY_LEN(envvars); ++i) {
print_envvar(&envvars[i], cols);
}

printf("\nExit status:\n\n");
for (size_t i = 0; i < ARRAY_LEN(exit_statuses); ++i) {
print_exit_status(&exit_statuses[i], cols);
}
}

static bool
Expand Down

0 comments on commit b1dbc30

Please sign in to comment.