summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-03-21 20:13:21 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-03-21 20:13:21 -0400
commitcd76a94a328719df61c15b02f25f984b43cce19e (patch)
treeb368ebaa562728c8d032db324123041dd171adc4
parent1f54a19b76946dafcd98a85b53410dfa9204ebe1 (diff)
downloadbfs-cd76a94a328719df61c15b02f25f984b43cce19e.tar.xz
parse: Use the right color when suggesting typo fixes
-rw-r--r--parse.c239
1 files changed, 126 insertions, 113 deletions
diff --git a/parse.c b/parse.c
index 36dc67b..7f4da32 100644
--- a/parse.c
+++ b/parse.c
@@ -2898,6 +2898,7 @@ typedef struct expr *parse_fn(struct parser_state *state, int arg1, int arg2);
*/
struct table_entry {
char *arg;
+ enum token_type type;
parse_fn *parse;
int arg1;
int arg2;
@@ -2908,118 +2909,118 @@ struct table_entry {
* The parse table for literals.
*/
static const struct table_entry parse_table[] = {
- {"--"},
- {"--help", parse_help},
- {"--version", parse_version},
- {"-Bmin", parse_time, BFS_STAT_BTIME, MINUTES},
- {"-Bnewer", parse_newer, BFS_STAT_BTIME},
- {"-Bsince", parse_since, BFS_STAT_BTIME},
- {"-Btime", parse_time, BFS_STAT_BTIME, DAYS},
- {"-D", parse_debug},
- {"-E", parse_regex_extended},
- {"-H", parse_follow, BFTW_COMFOLLOW, false},
- {"-L", parse_follow, BFTW_LOGICAL, false},
- {"-O", parse_optlevel, 0, 0, true},
- {"-P", parse_follow, 0, false},
- {"-S", parse_search_strategy},
- {"-X", parse_xargs_safe},
- {"-a"},
- {"-acl", parse_acl},
- {"-amin", parse_time, BFS_STAT_ATIME, MINUTES},
- {"-and"},
- {"-anewer", parse_newer, BFS_STAT_ATIME},
- {"-asince", parse_since, BFS_STAT_ATIME},
- {"-atime", parse_time, BFS_STAT_ATIME, DAYS},
- {"-capable", parse_capable},
- {"-cmin", parse_time, BFS_STAT_CTIME, MINUTES},
- {"-cnewer", parse_newer, BFS_STAT_CTIME},
- {"-color", parse_color, true},
- {"-csince", parse_since, BFS_STAT_CTIME},
- {"-ctime", parse_time, BFS_STAT_CTIME, DAYS},
- {"-d", parse_depth},
- {"-daystart", parse_daystart},
- {"-delete", parse_delete},
- {"-depth", parse_depth_n},
- {"-empty", parse_empty},
- {"-exec", parse_exec, 0},
- {"-execdir", parse_exec, BFS_EXEC_CHDIR},
- {"-executable", parse_access, X_OK},
- {"-exit", parse_exit},
- {"-f", parse_f},
- {"-false", parse_const, false},
- {"-fls", parse_fls},
- {"-follow", parse_follow, BFTW_LOGICAL, true},
- {"-fprint", parse_fprint},
- {"-fprint0", parse_fprint0},
- {"-fprintf", parse_fprintf},
- {"-fstype", parse_fstype},
- {"-gid", parse_group},
- {"-group", parse_group},
- {"-help", parse_help},
- {"-hidden", parse_hidden},
- {"-ignore_readdir_race", parse_ignore_races, true},
- {"-ilname", parse_lname, true},
- {"-iname", parse_name, true},
- {"-inum", parse_inum},
- {"-ipath", parse_path, true},
- {"-iregex", parse_regex, REG_ICASE},
- {"-iwholename", parse_path, true},
- {"-links", parse_links},
- {"-lname", parse_lname, false},
- {"-ls", parse_ls},
- {"-maxdepth", parse_depth_limit, false},
- {"-mindepth", parse_depth_limit, true},
- {"-mmin", parse_time, BFS_STAT_MTIME, MINUTES},
- {"-mnewer", parse_newer, BFS_STAT_MTIME},
- {"-mount", parse_mount},
- {"-msince", parse_since, BFS_STAT_MTIME},
- {"-mtime", parse_time, BFS_STAT_MTIME, DAYS},
- {"-name", parse_name, false},
- {"-newer", parse_newer, BFS_STAT_MTIME},
- {"-newer", parse_newerxy, 0, 0, true},
- {"-nocolor", parse_color, false},
- {"-nogroup", parse_nogroup},
- {"-nohidden", parse_nohidden},
- {"-noignore_readdir_race", parse_ignore_races, false},
- {"-noleaf", parse_noleaf},
- {"-not"},
- {"-nouser", parse_nouser},
- {"-nowarn", parse_warn, false},
- {"-o"},
- {"-ok", parse_exec, BFS_EXEC_CONFIRM},
- {"-okdir", parse_exec, BFS_EXEC_CONFIRM | BFS_EXEC_CHDIR},
- {"-or"},
- {"-path", parse_path, false},
- {"-perm", parse_perm},
- {"-print", parse_print},
- {"-print0", parse_print0},
- {"-printf", parse_printf},
- {"-printx", parse_printx},
- {"-prune", parse_prune},
- {"-quit", parse_quit},
- {"-readable", parse_access, R_OK},
- {"-regex", parse_regex, 0},
- {"-regextype", parse_regextype},
- {"-rm", parse_delete},
- {"-s", parse_s},
- {"-samefile", parse_samefile},
- {"-since", parse_since, BFS_STAT_MTIME},
- {"-size", parse_size},
- {"-sparse", parse_sparse},
- {"-true", parse_const, true},
- {"-type", parse_type, false},
- {"-uid", parse_user},
- {"-unique", parse_unique},
- {"-used", parse_used},
- {"-user", parse_user},
- {"-version", parse_version},
- {"-warn", parse_warn, true},
- {"-wholename", parse_path, false},
- {"-writable", parse_access, W_OK},
- {"-x", parse_xdev},
- {"-xattr", parse_xattr},
- {"-xdev", parse_xdev},
- {"-xtype", parse_type, true},
+ {"--", T_FLAG},
+ {"--help", T_ACTION, parse_help},
+ {"--version", T_ACTION, parse_version},
+ {"-Bmin", T_TEST, parse_time, BFS_STAT_BTIME, MINUTES},
+ {"-Bnewer", T_TEST, parse_newer, BFS_STAT_BTIME},
+ {"-Bsince", T_TEST, parse_since, BFS_STAT_BTIME},
+ {"-Btime", T_TEST, parse_time, BFS_STAT_BTIME, DAYS},
+ {"-D", T_FLAG, parse_debug},
+ {"-E", T_FLAG, parse_regex_extended},
+ {"-H", T_FLAG, parse_follow, BFTW_COMFOLLOW, false},
+ {"-L", T_FLAG, parse_follow, BFTW_LOGICAL, false},
+ {"-O", T_FLAG, parse_optlevel, 0, 0, true},
+ {"-P", T_FLAG, parse_follow, 0, false},
+ {"-S", T_FLAG, parse_search_strategy},
+ {"-X", T_FLAG, parse_xargs_safe},
+ {"-a", T_OPERATOR},
+ {"-acl", T_TEST, parse_acl},
+ {"-amin", T_TEST, parse_time, BFS_STAT_ATIME, MINUTES},
+ {"-and", T_OPERATOR},
+ {"-anewer", T_TEST, parse_newer, BFS_STAT_ATIME},
+ {"-asince", T_TEST, parse_since, BFS_STAT_ATIME},
+ {"-atime", T_TEST, parse_time, BFS_STAT_ATIME, DAYS},
+ {"-capable", T_TEST, parse_capable},
+ {"-cmin", T_TEST, parse_time, BFS_STAT_CTIME, MINUTES},
+ {"-cnewer", T_TEST, parse_newer, BFS_STAT_CTIME},
+ {"-color", T_OPTION, parse_color, true},
+ {"-csince", T_TEST, parse_since, BFS_STAT_CTIME},
+ {"-ctime", T_TEST, parse_time, BFS_STAT_CTIME, DAYS},
+ {"-d", T_FLAG, parse_depth},
+ {"-daystart", T_OPTION, parse_daystart},
+ {"-delete", T_ACTION, parse_delete},
+ {"-depth", T_OPTION, parse_depth_n},
+ {"-empty", T_TEST, parse_empty},
+ {"-exec", T_ACTION, parse_exec, 0},
+ {"-execdir", T_ACTION, parse_exec, BFS_EXEC_CHDIR},
+ {"-executable", T_TEST, parse_access, X_OK},
+ {"-exit", T_ACTION, parse_exit},
+ {"-f", T_FLAG, parse_f},
+ {"-false", T_TEST, parse_const, false},
+ {"-fls", T_ACTION, parse_fls},
+ {"-follow", T_OPTION, parse_follow, BFTW_LOGICAL, true},
+ {"-fprint", T_ACTION, parse_fprint},
+ {"-fprint0", T_ACTION, parse_fprint0},
+ {"-fprintf", T_ACTION, parse_fprintf},
+ {"-fstype", T_TEST, parse_fstype},
+ {"-gid", T_TEST, parse_group},
+ {"-group", T_TEST, parse_group},
+ {"-help", T_ACTION, parse_help},
+ {"-hidden", T_TEST, parse_hidden},
+ {"-ignore_readdir_race", T_OPTION, parse_ignore_races, true},
+ {"-ilname", T_TEST, parse_lname, true},
+ {"-iname", T_TEST, parse_name, true},
+ {"-inum", T_TEST, parse_inum},
+ {"-ipath", T_TEST, parse_path, true},
+ {"-iregex", T_TEST, parse_regex, REG_ICASE},
+ {"-iwholename", T_TEST, parse_path, true},
+ {"-links", T_TEST, parse_links},
+ {"-lname", T_TEST, parse_lname, false},
+ {"-ls", T_ACTION, parse_ls},
+ {"-maxdepth", T_OPTION, parse_depth_limit, false},
+ {"-mindepth", T_OPTION, parse_depth_limit, true},
+ {"-mmin", T_TEST, parse_time, BFS_STAT_MTIME, MINUTES},
+ {"-mnewer", T_TEST, parse_newer, BFS_STAT_MTIME},
+ {"-mount", T_OPTION, parse_mount},
+ {"-msince", T_TEST, parse_since, BFS_STAT_MTIME},
+ {"-mtime", T_TEST, parse_time, BFS_STAT_MTIME, DAYS},
+ {"-name", T_TEST, parse_name, false},
+ {"-newer", T_TEST, parse_newer, BFS_STAT_MTIME},
+ {"-newer", T_TEST, parse_newerxy, 0, 0, true},
+ {"-nocolor", T_OPTION, parse_color, false},
+ {"-nogroup", T_TEST, parse_nogroup},
+ {"-nohidden", T_TEST, parse_nohidden},
+ {"-noignore_readdir_race", T_OPTION, parse_ignore_races, false},
+ {"-noleaf", T_OPTION, parse_noleaf},
+ {"-not", T_OPERATOR},
+ {"-nouser", T_TEST, parse_nouser},
+ {"-nowarn", T_TEST, parse_warn, false},
+ {"-o", T_OPERATOR},
+ {"-ok", T_ACTION, parse_exec, BFS_EXEC_CONFIRM},
+ {"-okdir", T_ACTION, parse_exec, BFS_EXEC_CONFIRM | BFS_EXEC_CHDIR},
+ {"-or", T_OPERATOR},
+ {"-path", T_TEST, parse_path, false},
+ {"-perm", T_TEST, parse_perm},
+ {"-print", T_ACTION, parse_print},
+ {"-print0", T_ACTION, parse_print0},
+ {"-printf", T_ACTION, parse_printf},
+ {"-printx", T_ACTION, parse_printx},
+ {"-prune", T_ACTION, parse_prune},
+ {"-quit", T_ACTION, parse_quit},
+ {"-readable", T_TEST, parse_access, R_OK},
+ {"-regex", T_TEST, parse_regex, 0},
+ {"-regextype", T_OPTION, parse_regextype},
+ {"-rm", T_ACTION, parse_delete},
+ {"-s", T_FLAG, parse_s},
+ {"-samefile", T_TEST, parse_samefile},
+ {"-since", T_TEST, parse_since, BFS_STAT_MTIME},
+ {"-size", T_TEST, parse_size},
+ {"-sparse", T_TEST, parse_sparse},
+ {"-true", T_TEST, parse_const, true},
+ {"-type", T_TEST, parse_type, false},
+ {"-uid", T_TEST, parse_user},
+ {"-unique", T_ACTION, parse_unique},
+ {"-used", T_TEST, parse_used},
+ {"-user", T_TEST, parse_user},
+ {"-version", T_ACTION, parse_version},
+ {"-warn", T_OPTION, parse_warn, true},
+ {"-wholename", T_TEST, parse_path, false},
+ {"-writable", T_TEST, parse_access, W_OK},
+ {"-x", T_FLAG, parse_xdev},
+ {"-xattr", T_TEST, parse_xattr},
+ {"-xdev", T_OPTION, parse_xdev},
+ {"-xtype", T_TEST, parse_type, true},
{0},
};
@@ -3080,7 +3081,19 @@ static struct expr *parse_literal(struct parser_state *state) {
match = table_lookup_fuzzy(arg);
- parse_error(state, "Unknown argument ${er}%s${rs}; did you mean ${blu}%s${rs}?", arg, match->arg);
+ CFILE *cerr = state->cmdline->cerr;
+ parse_error(state, "Unknown argument ${er}%s${rs}; did you mean ", arg);
+ switch (match->type) {
+ case T_FLAG:
+ cfprintf(cerr, "${cyn}%s${rs}?", match->arg);
+ break;
+ case T_OPERATOR:
+ cfprintf(cerr, "${red}%s${rs}?", match->arg);
+ break;
+ default:
+ cfprintf(cerr, "${blu}%s${rs}?", match->arg);
+ break;
+ }
if (!state->interactive || !match->parse) {
fprintf(stderr, "\n");