Make --allow-extra default (#281)

This commit is contained in:
Denis Isidoro 2020-03-17 12:39:38 -03:00 committed by GitHub
parent 6e582e4015
commit b49ee6a491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View file

@ -177,6 +177,8 @@ Variable names should only include alphanumeric characters and `_`.
If there's a corresponding line starting with `$` for a variable, suggestions will be displayed. Otherwise, the user will be able to type any value for it. If there's a corresponding line starting with `$` for a variable, suggestions will be displayed. Otherwise, the user will be able to type any value for it.
If you hit `<tab>` the query typed will be prefered. If you hit `<enter>` the selection will be prefered.
### Advanced variable options ### Advanced variable options
For lines starting with `$` you can add use `---` to customize the behavior of `fzf` or how the value is going to be used: For lines starting with `$` you can add use `---` to customize the behavior of `fzf` or how the value is going to be used:
@ -189,10 +191,10 @@ $ image_id: docker images --- --column 3 --header-lines 1 --delimiter '\s\s+'
``` ```
The supported parameters are: The supported parameters are:
- `--allow-extra` *(experimental)*: handles `fzf` option `--print-query`. `enter` will prefer a selection and `tab` will prefer the query typed. - `--prevent-extra` *(experimental)*: limits the user to select one of the suggestions;
- `--multi` : forwarded option to `fzf`. - `--multi` : forwarded option to `fzf`;
- `--header-lines` : forwarded option to `fzf` - `--header-lines` : forwarded option to `fzf`;
- `--column` : forwarded option to `fzf`. - `--column` : forwarded option to `fzf`;
- `--delimiter` : forwarded option to `fzf`. - `--delimiter` : forwarded option to `fzf`.
### Variable dependency ### Variable dependency

View file

@ -39,7 +39,7 @@ fn parse_opts(text: &str) -> SuggestionOpts {
let mut header_lines: u8 = 0; let mut header_lines: u8 = 0;
let mut column: Option<u8> = None; let mut column: Option<u8> = None;
let mut multi = false; let mut multi = false;
let mut allow_extra = false; let mut prevent_extra = false;
let mut delimiter: Option<String> = None; let mut delimiter: Option<String> = None;
let mut parts = text.split(' '); let mut parts = text.split(' ');
@ -47,7 +47,7 @@ fn parse_opts(text: &str) -> SuggestionOpts {
while let Some(p) = parts.next() { while let Some(p) = parts.next() {
match p { match p {
"--multi" => multi = true, "--multi" => multi = true,
"--allow-extra" => allow_extra = true, "--prevent-extra" => prevent_extra = true,
"--header" | "--headers" | "--header-lines" => { "--header" | "--headers" | "--header-lines" => {
header_lines = remove_quotes(parts.next().unwrap()).parse::<u8>().unwrap() header_lines = remove_quotes(parts.next().unwrap()).parse::<u8>().unwrap()
} }
@ -63,10 +63,10 @@ fn parse_opts(text: &str) -> SuggestionOpts {
header_lines, header_lines,
column, column,
delimiter, delimiter,
suggestion_type: match (multi, allow_extra) { suggestion_type: match (multi, prevent_extra) {
(true, _) => SuggestionType::MultipleSelections, // multi wins over allow-extra (true, _) => SuggestionType::MultipleSelections, // multi wins over allow-extra
(false, true) => SuggestionType::SingleRecommendation, (false, false) => SuggestionType::SingleRecommendation,
(false, false) => SuggestionType::SingleSelection, (false, true) => SuggestionType::SingleSelection,
}, },
} }
} }