mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 02:13:38 +08:00
Promote job_control_t to an enum class
This commit is contained in:
parent
99d77c6049
commit
96b8ac7013
|
@ -76,24 +76,25 @@ const enum_map<status_cmd_t> status_enum_map[] = {
|
||||||
/// Values that may be returned from the test-feature option to status.
|
/// Values that may be returned from the test-feature option to status.
|
||||||
enum { TEST_FEATURE_ON, TEST_FEATURE_OFF, TEST_FEATURE_NOT_RECOGNIZED };
|
enum { TEST_FEATURE_ON, TEST_FEATURE_OFF, TEST_FEATURE_NOT_RECOGNIZED };
|
||||||
|
|
||||||
int job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd, io_streams_t &streams) {
|
static maybe_t<job_control_t> job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd,
|
||||||
|
io_streams_t &streams) {
|
||||||
if (std::wcscmp(mode, L"full") == 0) {
|
if (std::wcscmp(mode, L"full") == 0) {
|
||||||
return JOB_CONTROL_ALL;
|
return job_control_t::all;
|
||||||
} else if (std::wcscmp(mode, L"interactive") == 0) {
|
} else if (std::wcscmp(mode, L"interactive") == 0) {
|
||||||
return JOB_CONTROL_INTERACTIVE;
|
return job_control_t::interactive;
|
||||||
} else if (std::wcscmp(mode, L"none") == 0) {
|
} else if (std::wcscmp(mode, L"none") == 0) {
|
||||||
return JOB_CONTROL_NONE;
|
return job_control_t::none;
|
||||||
}
|
}
|
||||||
streams.err.append_format(L"%ls: Invalid job control mode '%ls'\n", cmd, mode);
|
streams.err.append_format(L"%ls: Invalid job control mode '%ls'\n", cmd, mode);
|
||||||
return -1;
|
return none();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct status_cmd_opts_t {
|
struct status_cmd_opts_t {
|
||||||
bool print_help = false;
|
bool print_help{false};
|
||||||
int level = 1;
|
int level{1};
|
||||||
int new_job_control_mode = -1;
|
maybe_t<job_control_t> new_job_control_mode{};
|
||||||
const wchar_t *feature_name;
|
const wchar_t *feature_name{};
|
||||||
status_cmd_t status_cmd = STATUS_UNDEF;
|
status_cmd_t status_cmd{STATUS_UNDEF};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Note: Do not add new flags that represent subcommands. We're encouraging people to switch to
|
/// Note: Do not add new flags that represent subcommands. We're encouraging people to switch to
|
||||||
|
@ -230,10 +231,11 @@ static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high
|
||||||
if (!set_status_cmd(cmd, opts, STATUS_SET_JOB_CONTROL, streams)) {
|
if (!set_status_cmd(cmd, opts, STATUS_SET_JOB_CONTROL, streams)) {
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
opts.new_job_control_mode = job_control_str_to_mode(w.woptarg, cmd, streams);
|
auto job_mode = job_control_str_to_mode(w.woptarg, cmd, streams);
|
||||||
if (opts.new_job_control_mode == -1) {
|
if (!job_mode) {
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
opts.new_job_control_mode = job_mode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 't': {
|
case 't': {
|
||||||
|
@ -309,14 +311,14 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
|
||||||
streams.out.append_format(
|
streams.out.append_format(
|
||||||
_(L"Job control: %ls\n"),
|
_(L"Job control: %ls\n"),
|
||||||
job_control_mode == JOB_CONTROL_INTERACTIVE
|
job_control_mode == job_control_t::interactive
|
||||||
? _(L"Only on interactive jobs")
|
? _(L"Only on interactive jobs")
|
||||||
: (job_control_mode == JOB_CONTROL_NONE ? _(L"Never") : _(L"Always")));
|
: (job_control_mode == job_control_t::none ? _(L"Never") : _(L"Always")));
|
||||||
streams.out.append(parser.stack_trace());
|
streams.out.append(parser.stack_trace());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STATUS_SET_JOB_CONTROL: {
|
case STATUS_SET_JOB_CONTROL: {
|
||||||
if (opts.new_job_control_mode != -1) {
|
if (opts.new_job_control_mode) {
|
||||||
// Flag form was used.
|
// Flag form was used.
|
||||||
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
||||||
} else {
|
} else {
|
||||||
|
@ -326,12 +328,14 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
args.size());
|
args.size());
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
opts.new_job_control_mode = job_control_str_to_mode(args[0].c_str(), cmd, streams);
|
auto new_mode = job_control_str_to_mode(args[0].c_str(), cmd, streams);
|
||||||
if (opts.new_job_control_mode == -1) {
|
if (!new_mode) {
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
opts.new_job_control_mode = new_mode;
|
||||||
}
|
}
|
||||||
job_control_mode = opts.new_job_control_mode;
|
assert(opts.new_job_control_mode && "Should have a new mode");
|
||||||
|
job_control_mode = *opts.new_job_control_mode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STATUS_FEATURES: {
|
case STATUS_FEATURES: {
|
||||||
|
@ -403,17 +407,17 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
}
|
}
|
||||||
case STATUS_IS_FULL_JOB_CTRL: {
|
case STATUS_IS_FULL_JOB_CTRL: {
|
||||||
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
||||||
retval = job_control_mode != JOB_CONTROL_ALL;
|
retval = job_control_mode != job_control_t::all;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STATUS_IS_INTERACTIVE_JOB_CTRL: {
|
case STATUS_IS_INTERACTIVE_JOB_CTRL: {
|
||||||
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
||||||
retval = job_control_mode != JOB_CONTROL_INTERACTIVE;
|
retval = job_control_mode != job_control_t::interactive;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STATUS_IS_NO_JOB_CTRL: {
|
case STATUS_IS_NO_JOB_CTRL: {
|
||||||
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
CHECK_FOR_UNEXPECTED_STATUS_ARGS(opts.status_cmd)
|
||||||
retval = job_control_mode != JOB_CONTROL_NONE;
|
retval = job_control_mode != job_control_t::none;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STATUS_STACK_TRACE: {
|
case STATUS_STACK_TRACE: {
|
||||||
|
|
|
@ -1207,8 +1207,8 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
||||||
shared_ptr<job_t> job = std::make_shared<job_t>(acquire_job_id(), block_io, parent_job);
|
shared_ptr<job_t> job = std::make_shared<job_t>(acquire_job_id(), block_io, parent_job);
|
||||||
job->tmodes = tmodes;
|
job->tmodes = tmodes;
|
||||||
job->set_flag(job_flag_t::JOB_CONTROL,
|
job->set_flag(job_flag_t::JOB_CONTROL,
|
||||||
(job_control_mode == JOB_CONTROL_ALL) ||
|
(job_control_mode == job_control_t::all) ||
|
||||||
((job_control_mode == JOB_CONTROL_INTERACTIVE) && shell_is_interactive()));
|
((job_control_mode == job_control_t::interactive) && shell_is_interactive()));
|
||||||
|
|
||||||
job->set_flag(job_flag_t::FOREGROUND, !job_node_is_background(job_node));
|
job->set_flag(job_flag_t::FOREGROUND, !job_node_is_background(job_node));
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ bool is_block = false;
|
||||||
bool is_breakpoint = false;
|
bool is_breakpoint = false;
|
||||||
bool is_login = false;
|
bool is_login = false;
|
||||||
int is_event = 0;
|
int is_event = 0;
|
||||||
int job_control_mode = JOB_CONTROL_INTERACTIVE;
|
job_control_t job_control_mode = job_control_t::interactive;
|
||||||
int no_exec = 0;
|
int no_exec = 0;
|
||||||
|
|
||||||
static int is_interactive = -1;
|
static int is_interactive = -1;
|
||||||
|
|
12
src/proc.h
12
src/proc.h
|
@ -38,10 +38,10 @@ enum process_type_t {
|
||||||
INTERNAL_EXEC
|
INTERNAL_EXEC
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum class job_control_t {
|
||||||
JOB_CONTROL_ALL,
|
all,
|
||||||
JOB_CONTROL_INTERACTIVE,
|
interactive,
|
||||||
JOB_CONTROL_NONE,
|
none,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A proc_status_t is a value type that encapsulates logic around exited vs stopped vs signaled,
|
/// A proc_status_t is a value type that encapsulates logic around exited vs stopped vs signaled,
|
||||||
|
@ -489,8 +489,8 @@ void set_proc_had_barrier(bool flag);
|
||||||
|
|
||||||
/// The current job control mode.
|
/// The current job control mode.
|
||||||
///
|
///
|
||||||
/// Must be one of JOB_CONTROL_ALL, JOB_CONTROL_INTERACTIVE and JOB_CONTROL_NONE.
|
/// Must be one of job_control_t::all, job_control_t::interactive and job_control_t::none.
|
||||||
extern int job_control_mode;
|
extern job_control_t job_control_mode;
|
||||||
|
|
||||||
/// If this flag is set, fish will never fork or run execve. It is used to put fish into a syntax
|
/// If this flag is set, fish will never fork or run execve. It is used to put fish into a syntax
|
||||||
/// verifier mode where fish tries to validate the syntax of a file but doesn't actually do
|
/// verifier mode where fish tries to validate the syntax of a file but doesn't actually do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user