change string match --filter to --entire

Per discussion in PR#3998 to review adding a `--filter` flag to `string
replace` rename the same flag in the `string match` subcommand to avoid
confusion about the meaning of the flag.
This commit is contained in:
Kurtis Rader 2017-05-01 22:19:58 -07:00
parent 16816a1202
commit fb54d34788
5 changed files with 25 additions and 25 deletions

View File

@ -15,7 +15,7 @@
- When the current token has an open single-quote (`'`), fish will now escape any `'` and `\` in pasted text so that it can be used as a single token. Note that this requires either bracketed paste or use of the special `fish_clipboard_paste` function (bound to \cv by default).
- Fish is now more forgiving of missing or invalid $TERM values (#3850).
- The `string` command now supports a `repeat` subcommand with the obvious behavior (#3864).
- The `string match` command now supports a `--filter` flag to emit the entire string partially matched by a pattern (#3957).
- The `string match` command now supports a `--entire` flag to emit the entire string partially matched by a pattern (#3957).
- The `string replace` command now supports a `--filter` flag to limit output to strings which underwent a replacement (#3348).
- The `functions --details --verbose` output now includes the function description (#597).
- Completions for `helm` added (#3829).

View File

@ -11,7 +11,7 @@ string join [(-q | --quiet)] SEP [STRING...]
string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)]
[(-q | --quiet)] [STRING...]
string escape [(-n | --no-quoted)] [STRING...]
string match [(-a | --all)] [((-f | --filter)] [(-i | --ignore-case)] [(-r | --regex)]
string match [(-a | --all)] [((-e | --entire)] [(-i | --ignore-case)] [(-r | --regex)]
[(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...]
string replace [(-a | --all)] [(-f | --filter)] [(-i | --ignore-case)] [(-r | --regex)]
[(-q | --quiet)] PATTERN REPLACEMENT [STRING...]
@ -62,7 +62,7 @@ The following subcommands are available.
`string match` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless `-a` or `--all` is given, in which case all matches are reported.The default behavior is equivalent to `grep -o`.
If you specify the `-f` or `--filter` then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to `grep` without the `-o` flag). You can, obviously, achieve the same result by prepending and appending `*` or `.*` depending on whether or not you have specified the `--regex` flag. The `--filter` flag is simply a way to avoid having to complicate the pattern in that fashion and make the intent of the `string match` clearer.
If you specify the `-e` or `--entire` then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to `grep` without the `-o` flag). You can, obviously, achieve the same result by prepending and appending `*` or `.*` depending on whether or not you have specified the `--regex` flag. The `--entire` flag is simply a way to avoid having to complicate the pattern in that fashion and make the intent of the `string match` clearer.
Matching can be made case-insensitive with `--ignore-case` or `-i`.

View File

@ -264,7 +264,7 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha
struct match_options_t {
bool all;
bool filter;
bool entire;
bool ignore_case;
bool index;
bool invert_match;
@ -272,7 +272,7 @@ struct match_options_t {
match_options_t()
: all(false),
filter(false),
entire(false),
ignore_case(false),
index(false),
invert_match(false),
@ -307,7 +307,7 @@ class wildcard_matcher_t : public string_matcher_t {
wcpattern[i] = towlower(wcpattern[i]);
}
}
if (opts.filter && !wcpattern.empty()) {
if (opts.entire && !wcpattern.empty()) {
if (wcpattern.front() != ANY_STRING) wcpattern.insert(0, 1, ANY_STRING);
if (wcpattern.back() != ANY_STRING) wcpattern.push_back(ANY_STRING);
}
@ -421,13 +421,13 @@ class pcre2_matcher_t : public string_matcher_t {
return 0;
}
if (opts.filter) {
if (opts.entire) {
streams.out.append(arg);
streams.out.push_back(L'\n');
}
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(regex.match);
for (int j = (opts.filter ? 1 : 0); j < pcre2_rc; j++) {
for (int j = (opts.entire ? 1 : 0); j < pcre2_rc; j++) {
PCRE2_SIZE begin = ovector[2 * j];
PCRE2_SIZE end = ovector[2 * j + 1];
@ -515,9 +515,9 @@ class pcre2_matcher_t : public string_matcher_t {
static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv) {
wchar_t *cmd = argv[0];
const wchar_t *short_options = L"afinqrv";
const wchar_t *short_options = L"aeinqrv";
const struct woption long_options[] = {
{L"all", no_argument, NULL, 'a'}, {L"filter", no_argument, NULL, 'f'},
{L"all", no_argument, NULL, 'a'}, {L"entire", no_argument, NULL, 'e'},
{L"ignore-case", no_argument, NULL, 'i'}, {L"index", no_argument, NULL, 'n'},
{L"invert", no_argument, NULL, 'v'}, {L"quiet", no_argument, NULL, 'q'},
{L"regex", no_argument, NULL, 'r'}, {NULL, 0, NULL, 0}};
@ -532,8 +532,8 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
opts.all = true;
break;
}
case 'f': {
opts.filter = true;
case 'e': {
opts.entire = true;
break;
}
case 'i': {
@ -567,9 +567,9 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar
}
}
if (opts.filter && opts.index) {
if (opts.entire && opts.index) {
streams.err.append_format(BUILTIN_ERR_COMBO2, cmd,
_(L"--filter and --index are mutually exclusive"));
_(L"--enter and --index are mutually exclusive"));
return BUILTIN_STRING_ERROR;
}

View File

@ -293,10 +293,10 @@ echo '# string repeat -n3 ""'
string repeat -n3 ""
or echo string repeat empty string failed
# Test equivalent matches with/without the --filter, --regex, and --invert flags.
# Test equivalent matches with/without the --entire, --regex, and --invert flags.
echo
echo '# string match -f x abc dxf xyz jkx x z'
string match -f x abc dxf xyz jkx x z
echo '# string match -e x abc dxf xyz jkx x z'
string match -e x abc dxf xyz jkx x z
or echo exit 1
echo
@ -304,8 +304,8 @@ echo '# string match x abc dxf xyz jkx x z'
string match x abc dxf xyz jkx x z
echo
echo '# string match --filter -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match --filter -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
echo '# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1
echo
@ -313,10 +313,10 @@ echo '# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyx
string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1
# Make sure that groups are handled correct with/without --filter.
# Make sure that groups are handled correct with/without --entire.
echo
echo '# string match --filter -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match --filter -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
echo '# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz'
string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
or echo exit 1
echo

View File

@ -204,7 +204,7 @@ string repeat empty string failed
# string repeat -n3 ""
string repeat empty string failed
# string match -f x abc dxf xyz jkx x z
# string match -e x abc dxf xyz jkx x z
dxf
xyz
jkx
@ -213,7 +213,7 @@ x
# string match x abc dxf xyz jkx x z
x
# string match --filter -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abxc
bye
aaabyz
@ -229,7 +229,7 @@ aabx
bxy
aabxyx
# string match --filter -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abxc
x
bye