diff --git a/CHANGELOG.md b/CHANGELOG.md index 50cf0c3e..c577adea 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index a25aca0d..6b8fcd46 100644 --- a/README.md +++ b/README.md @@ -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 Set environment variables from provided file -l, --loglevel The log level [default: info] [possible values: verbose, info, error] --makefile The optional toml file containing the tasks definitions [default: Makefile.toml] - --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 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 The list steps output file name -p, --profile The profile name (will be converted to lower case) [default: development] --skip-tasks Skip all tasks that match the provided regex (example: pre.*|post.*) @@ -3231,6 +3232,17 @@ ARGS: ... Task arguments which can be accessed in the task itself. ``` + +### 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. + + +#### 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. + ### 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. diff --git a/docs/_includes/content.md b/docs/_includes/content.md index 5a140783..09031915 100755 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -3107,7 +3107,7 @@ OPTIONS: --env-file Set environment variables from provided file -l, --loglevel The log level [default: info] [possible values: verbose, info, error] --makefile The optional toml file containing the tasks definitions [default: Makefile.toml] - --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 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 The list steps output file name -p, --profile The profile name (will be converted to lower case) [default: development] --skip-tasks Skip all tasks that match the provided regex (example: pre.*|post.*) @@ -3118,6 +3118,17 @@ ARGS: ... Task arguments which can be accessed in the task itself. ``` + +### 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. + + +#### 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. + ### 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. diff --git a/docs/_includes/nav.md b/docs/_includes/nav.md index 80db754a..5c5bdcde 100755 --- a/docs/_includes/nav.md +++ b/docs/_includes/nav.md @@ -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) diff --git a/extra/shell/makers-completion.bash b/extra/shell/makers-completion.bash new file mode 100755 index 00000000..66429fa7 --- /dev/null +++ b/extra/shell/makers-completion.bash @@ -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 + diff --git a/src/lib/cli.rs b/src/lib/cli.rs index 90727d6d..95c81878 100644 --- a/src/lib/cli.rs +++ b/src/lib/cli.rs @@ -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( diff --git a/src/lib/cli_commands/list_steps.rs b/src/lib/cli_commands/list_steps.rs index 2eecc03b..c649b95f 100644 --- a/src/lib/cli_commands/list_steps.rs +++ b/src/lib/cli_commands/list_steps.rs @@ -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)