Remove --authoritative leftovers from complete

The complete builtin had once -A / --authoritative and -u /
--unauthoritative switches which indicated whether all possibilities for
completion are specified and would cause an error if the completion was
authoritative and an unknown option was encountered.

This feature was functionally removed during one of the past parser
rewritings, but -A and -u still remained in parts of the code and
command completions, although having no effect.

This commit removes the leftovers and prints an warning whenever user
tries to run the complete command with -A / -u / --authoritative /
--unauthoritative switches.

Fixes #3640.
This commit is contained in:
Radomír Bosák 2016-12-19 18:05:18 +01:00 committed by Kurtis Rader
parent 1ace742b6c
commit dc96c01c93
3 changed files with 15 additions and 36 deletions

View file

@ -58,25 +58,17 @@ static void builtin_complete_add2(const wchar_t *cmd, int cmd_type, const wchar_
/// Silly function. /// Silly function.
static void builtin_complete_add(const wcstring_list_t &cmd, const wcstring_list_t &path, static void builtin_complete_add(const wcstring_list_t &cmd, const wcstring_list_t &path,
const wchar_t *short_opt, wcstring_list_t &gnu_opt, const wchar_t *short_opt, wcstring_list_t &gnu_opt,
wcstring_list_t &old_opt, int result_mode, int authoritative, wcstring_list_t &old_opt, int result_mode,
const wchar_t *condition, const wchar_t *comp, const wchar_t *desc, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc,
int flags) { int flags) {
for (size_t i = 0; i < cmd.size(); i++) { for (size_t i = 0; i < cmd.size(); i++) {
builtin_complete_add2(cmd.at(i).c_str(), COMMAND, short_opt, gnu_opt, old_opt, result_mode, builtin_complete_add2(cmd.at(i).c_str(), COMMAND, short_opt, gnu_opt, old_opt, result_mode,
condition, comp, desc, flags); condition, comp, desc, flags);
if (authoritative != -1) {
complete_set_authoritative(cmd.at(i).c_str(), COMMAND, authoritative);
}
} }
for (size_t i = 0; i < path.size(); i++) { for (size_t i = 0; i < path.size(); i++) {
builtin_complete_add2(path.at(i).c_str(), PATH, short_opt, gnu_opt, old_opt, result_mode, builtin_complete_add2(path.at(i).c_str(), PATH, short_opt, gnu_opt, old_opt, result_mode,
condition, comp, desc, flags); condition, comp, desc, flags);
if (authoritative != -1) {
complete_set_authoritative(path.at(i).c_str(), PATH, authoritative);
}
} }
} }
@ -128,7 +120,6 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
int result_mode = SHARED; int result_mode = SHARED;
int remove = 0; int remove = 0;
int authoritative = -1;
wcstring short_opt; wcstring short_opt;
wcstring_list_t gnu_opt, old_opt; wcstring_list_t gnu_opt, old_opt;
const wchar_t *comp = L"", *desc = L"", *condition = L""; const wchar_t *comp = L"", *desc = L"", *condition = L"";
@ -183,7 +174,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
else else
cmd_to_complete.push_back(tmp); cmd_to_complete.push_back(tmp);
} else { } else {
streams.err.append_format(L"%ls: Invalid token '%ls'\n", cmd, w.woptarg); streams.err.append_format(_(L"%ls: Invalid token '%ls'\n"), cmd, w.woptarg);
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
break; break;
@ -193,17 +184,19 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
break; break;
} }
case 'u': { case 'u': {
authoritative = 0; streams.err.append_format(
_(L"%ls: -u / --unauthoritative flags have been removed\n"), cmd);
break; break;
} }
case 'A': { case 'A': {
authoritative = 1; streams.err.append_format(_(L"%ls: -A / --authoritative flags have been removed\n"),
cmd);
break; break;
} }
case 's': { case 's': {
short_opt.append(w.woptarg); short_opt.append(w.woptarg);
if (w.woptarg[0] == '\0') { if (w.woptarg[0] == '\0') {
streams.err.append_format(L"%ls: -s requires a non-empty string\n", cmd); streams.err.append_format(_(L"%ls: -s requires a non-empty string\n"), cmd);
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
break; break;
@ -211,7 +204,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
case 'l': { case 'l': {
gnu_opt.push_back(w.woptarg); gnu_opt.push_back(w.woptarg);
if (w.woptarg[0] == '\0') { if (w.woptarg[0] == '\0') {
streams.err.append_format(L"%ls: -l requires a non-empty string\n", cmd); streams.err.append_format(_(L"%ls: -l requires a non-empty string\n"), cmd);
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
break; break;
@ -219,7 +212,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
case 'o': { case 'o': {
old_opt.push_back(w.woptarg); old_opt.push_back(w.woptarg);
if (w.woptarg[0] == '\0') { if (w.woptarg[0] == '\0') {
streams.err.append_format(L"%ls: -o requires a non-empty string\n", cmd); streams.err.append_format(_(L"%ls: -o requires a non-empty string\n"), cmd);
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
break; break;
@ -369,7 +362,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
builtin_complete_remove(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt); builtin_complete_remove(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt);
} else { } else {
builtin_complete_add(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt, builtin_complete_add(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt,
result_mode, authoritative, condition, comp, desc, flags); result_mode, condition, comp, desc, flags);
} }
// Handle wrap targets (probably empty). We only wrap commands, not paths. // Handle wrap targets (probably empty). We only wrap commands, not paths.

View file

@ -138,8 +138,6 @@ class completion_entry_t {
const wcstring cmd; const wcstring cmd;
/// True if command is a path. /// True if command is a path.
const bool cmd_is_path; const bool cmd_is_path;
/// True if no other options than the ones supplied are possible.
bool authoritative;
/// Order for when this completion was created. This aids in outputting completions sorted by /// Order for when this completion was created. This aids in outputting completions sorted by
/// time. /// time.
const unsigned int order; const unsigned int order;
@ -151,8 +149,8 @@ class completion_entry_t {
void add_option(const complete_entry_opt_t &opt); void add_option(const complete_entry_opt_t &opt);
bool remove_option(const wcstring &option, complete_option_type_t type); bool remove_option(const wcstring &option, complete_option_type_t type);
completion_entry_t(const wcstring &c, bool type, bool author) completion_entry_t(const wcstring &c, bool type)
: cmd(c), cmd_is_path(type), authoritative(author), order(++kCompleteOrder) {} : cmd(c), cmd_is_path(type), order(++kCompleteOrder) {}
}; };
/// Set of all completion entries. /// Set of all completion entries.
@ -418,7 +416,7 @@ static completion_entry_t &complete_get_exact_entry(const wcstring &cmd, bool cm
ASSERT_IS_LOCKED(completion_lock); ASSERT_IS_LOCKED(completion_lock);
std::pair<completion_entry_set_t::iterator, bool> ins = std::pair<completion_entry_set_t::iterator, bool> ins =
completion_set.insert(completion_entry_t(cmd, cmd_is_path, false)); completion_set.insert(completion_entry_t(cmd, cmd_is_path));
// NOTE SET_ELEMENTS_ARE_IMMUTABLE: Exposing mutable access here is only okay as long as callers // NOTE SET_ELEMENTS_ARE_IMMUTABLE: Exposing mutable access here is only okay as long as callers
// do not change any field that matters to ordering - affecting order without telling std::set // do not change any field that matters to ordering - affecting order without telling std::set
@ -426,14 +424,6 @@ static completion_entry_t &complete_get_exact_entry(const wcstring &cmd, bool cm
return const_cast<completion_entry_t &>(*ins.first); return const_cast<completion_entry_t &>(*ins.first);
} }
void complete_set_authoritative(const wchar_t *cmd, bool cmd_is_path, bool authoritative) {
CHECK(cmd, );
scoped_lock lock(completion_lock);
completion_entry_t &c = complete_get_exact_entry(cmd, cmd_is_path);
c.authoritative = authoritative;
}
void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option, void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option,
complete_option_type_t option_type, int result_mode, const wchar_t *condition, complete_option_type_t option_type, int result_mode, const wchar_t *condition,
const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) { const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) {
@ -481,7 +471,7 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti
complete_option_type_t type) { complete_option_type_t type) {
scoped_lock lock(completion_lock); scoped_lock lock(completion_lock);
completion_entry_t tmp_entry(cmd, cmd_is_path, false); completion_entry_t tmp_entry(cmd, cmd_is_path);
completion_entry_set_t::iterator iter = completion_set.find(tmp_entry); completion_entry_set_t::iterator iter = completion_set.find(tmp_entry);
if (iter != completion_set.end()) { if (iter != completion_set.end()) {
// const_cast: See SET_ELEMENTS_ARE_IMMUTABLE. // const_cast: See SET_ELEMENTS_ARE_IMMUTABLE.
@ -498,7 +488,7 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti
void complete_remove_all(const wcstring &cmd, bool cmd_is_path) { void complete_remove_all(const wcstring &cmd, bool cmd_is_path) {
scoped_lock lock(completion_lock); scoped_lock lock(completion_lock);
completion_entry_t tmp_entry(cmd, cmd_is_path, false); completion_entry_t tmp_entry(cmd, cmd_is_path);
completion_set.erase(tmp_entry); completion_set.erase(tmp_entry);
} }

View file

@ -143,10 +143,6 @@ void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option,
complete_option_type_t option_type, int result_mode, const wchar_t *condition, complete_option_type_t option_type, int result_mode, const wchar_t *condition,
const wchar_t *comp, const wchar_t *desc, int flags); const wchar_t *comp, const wchar_t *desc, int flags);
/// Sets whether the completion list for this command is complete. If true, any options not matching
/// one of the provided options will be flagged as an error by syntax highlighting.
void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authoritative);
/// Remove a previously defined completion. /// Remove a previously defined completion.
void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option, void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option,
complete_option_type_t type); complete_option_type_t type);