bash auto completion script for makers #565

This commit is contained in:
sagie gur ari
2021-06-26 10:22:36 +00:00
parent 4e824ad95a
commit f0ebe40585
7 changed files with 69 additions and 11 deletions
+4
View File
@@ -1,5 +1,9 @@
## CHANGELOG
### v0.34.1
* New bash auto completion script for makers #565
### v0.34.0 (2021-06-13)
* Fix UNC prefix stripping inconsistency #562 (thanks @WilliamVenner)
+13 -1
View File
@@ -96,6 +96,7 @@
* [Minimal Version](#usage-min-version)
* [Diff Changes](#usage-diff-changes)
* [Cli Options](#usage-cli)
* [Auto Completion](#usage-auto-completion)
* [Global Configuration](#cargo-make-global-config)
* [Makefile Definition](#descriptor-definition)
* [Task Naming Conventions](#task-name-conventions)
@@ -3220,7 +3221,7 @@ OPTIONS:
--env-file <FILE> Set environment variables from provided file
-l, --loglevel <LOG LEVEL> The log level [default: info] [possible values: verbose, info, error]
--makefile <FILE> The optional toml file containing the tasks definitions [default: Makefile.toml]
--output-format <OUTPUT FORMAT> The print/list steps format (some operations do not support all formats) [default: default] [possible values: default, short-description, markdown, markdown-single-page, markdown-sub-section]
--output-format <OUTPUT FORMAT> The print/list steps format (some operations do not support all formats) [default: default] [possible values: default, short-description, markdown, markdown-single-page, markdown-sub-section, autocomplete]
--output-file <OUTPUT_FILE> The list steps output file name
-p, --profile <PROFILE> The profile name (will be converted to lower case) [default: development]
--skip-tasks <SKIP_TASK_PATTERNS> Skip all tasks that match the provided regex (example: pre.*|post.*)
@@ -3231,6 +3232,17 @@ ARGS:
<TASK_ARGS>... Task arguments which can be accessed in the task itself.
```
<a name="usage-auto-completion"></a>
### Auto Completion
cargo-make comes with shell auto completion support, however in order to provide the exact task names that are
available in the current directory, it will run the --list-all-steps command which might take a bit to finish.
<a name="usage-auto-completion-bash"></a>
#### Bash
Source the makers-completion.bash file found in extra/shell folder at the start of your shell session.
It will enable auto completion for the **makers** executable.
<a name="cargo-make-global-config"></a>
### Global Configuration
Some of the default CLI values and cargo-make behaviour can be configured via optional global configuration file config.toml located in the cargo-make directory.
+12 -1
View File
@@ -3107,7 +3107,7 @@ OPTIONS:
--env-file <FILE> Set environment variables from provided file
-l, --loglevel <LOG LEVEL> The log level [default: info] [possible values: verbose, info, error]
--makefile <FILE> The optional toml file containing the tasks definitions [default: Makefile.toml]
--output-format <OUTPUT FORMAT> The print/list steps format (some operations do not support all formats) [default: default] [possible values: default, short-description, markdown, markdown-single-page, markdown-sub-section]
--output-format <OUTPUT FORMAT> The print/list steps format (some operations do not support all formats) [default: default] [possible values: default, short-description, markdown, markdown-single-page, markdown-sub-section, autocomplete]
--output-file <OUTPUT_FILE> The list steps output file name
-p, --profile <PROFILE> The profile name (will be converted to lower case) [default: development]
--skip-tasks <SKIP_TASK_PATTERNS> Skip all tasks that match the provided regex (example: pre.*|post.*)
@@ -3118,6 +3118,17 @@ ARGS:
<TASK_ARGS>... Task arguments which can be accessed in the task itself.
```
<a name="usage-auto-completion"></a>
### Auto Completion
cargo-make comes with shell auto completion support, however in order to provide the exact task names that are
available in the current directory, it will run the --list-all-steps command which might take a bit to finish.
<a name="usage-auto-completion-bash"></a>
#### Bash
Source the makers-completion.bash file found in extra/shell folder at the start of your shell session.
It will enable auto completion for the **makers** executable.
<a name="cargo-make-global-config"></a>
### Global Configuration
Some of the default CLI values and cargo-make behaviour can be configured via optional global configuration file config.toml located in the cargo-make directory.
+1
View File
@@ -85,6 +85,7 @@
* [Minimal Version](#usage-min-version)
* [Diff Changes](#usage-diff-changes)
* [Cli Options](#usage-cli)
* [Auto Completion](#usage-auto-completion)
* [Global Configuration](#cargo-make-global-config)
* [Makefile Definition](#descriptor-definition)
* [Task Naming Conventions](#task-name-conventions)
+19
View File
@@ -0,0 +1,19 @@
#/usr/bin/env bash
_cargo_make_completions()
{
if [ "${#COMP_WORDS[@]}" != "2" ]; then
return
fi
# add cli options
ALL_WORDS="--allow-private --diff-steps --disable-check-for-updates --experimental -h --help --list-all-steps --no-color --no-on-error --no-workspace --print-steps -skip-init-end-tasks --time-summary -v --version -V --version --cwd -e --env --env-file -l --loglevel verbose info error --makefile --output-format default short-description markdown markdown-single-page markdown-sub-section autocomplete --output-file -p --profile --skip-tasks -t --task "
# add task names
ALL_WORDS=("${ALL_WORDS}$(makers --loglevel error --list-all-steps --output-format autocomplete)")
COMPREPLY=($(compgen -W "$ALL_WORDS" -- "${COMP_WORDS[1]}"))
}
complete -F _cargo_make_completions makers
+1 -1
View File
@@ -400,7 +400,7 @@ fn create_cli<'a, 'b>(
)
.arg(
Arg::from_usage("--output-format=[OUTPUT FORMAT] 'The print/list steps format (some operations do not support all formats)'")
.possible_values(&["default", "short-description", "markdown", "markdown-single-page", "markdown-sub-section"])
.possible_values(&["default", "short-description", "markdown", "markdown-single-page", "markdown-sub-section", "autocomplete"])
.default_value(DEFAULT_OUTPUT_FORMAT),
)
.arg(
+19 -8
View File
@@ -34,6 +34,7 @@ pub(crate) fn create_list(config: &Config, output_format: &str) -> (String, u32)
let markdown = single_page_markdown
|| output_format == "markdown"
|| output_format == "markdown-sub-section";
let just_task_name = output_format == "autocomplete";
let mut categories = BTreeMap::new();
@@ -98,21 +99,31 @@ pub(crate) fn create_list(config: &Config, output_format: &str) -> (String, u32)
let post_key = if markdown { "**" } else { "" };
for (category, tasks) in &categories {
if single_page_markdown {
buffer.push_str(&format!("## {}\n\n", category));
} else if markdown {
buffer.push_str(&format!("#### {}\n\n", category));
} else {
buffer.push_str(&format!("{}\n----------\n", category));
if !just_task_name {
if single_page_markdown {
buffer.push_str(&format!("## {}\n\n", category));
} else if markdown {
buffer.push_str(&format!("#### {}\n\n", category));
} else {
buffer.push_str(&format!("{}\n----------\n", category));
}
}
for (key, description) in tasks {
if markdown {
buffer.push_str(&format!("* **"));
}
buffer.push_str(&format!("{}{} - {}\n", &key, &post_key, &description));
if just_task_name {
buffer.push_str(&format!("{} ", &key));
} else {
buffer.push_str(&format!("{}{} - {}\n", &key, &post_key, &description));
}
}
if !just_task_name {
buffer.push_str(&format!("\n"));
}
buffer.push_str(&format!("\n"));
}
(buffer, count)