diff --git a/CHANGELOG.md b/CHANGELOG.md index 9572d29f4..8ee4f5b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - A variable `fish_kill_signal` will be set to the signal that terminated the last foreground job, or `0` if the job exited normally. - On BSD systems, with the `-s` option, `fish_md5` does not use the given string, but `-s`. From now on the string is used. - Control-C no longer kills background jobs for which job control is disabled, matching POSIX semantics (#6828). +- Improve Gradle completion ### Syntax changes and new commands diff --git a/share/completions/gradle.fish b/share/completions/gradle.fish index 4480d8ff7..9f92e1dee 100644 --- a/share/completions/gradle.fish +++ b/share/completions/gradle.fish @@ -1,60 +1,276 @@ -# gradle is a build system. +# Gradle is a build system. # See: https://gradle.org -complete -c gradle -l help -s h -d 'Show help' -complete -c gradle -l no-rebuild -s a -d 'Don\'t rebuild dependencies' -complete -c gradle -l build-file -s b -r -d 'Specify build file' -complete -c gradle -l settings-file -s c -r -d 'Specify settings file' -complete -c gradle -l configure-on-demand -d 'Only relevant project are configured' -complete -c gradle -l console -x -d 'Specify console output type' -a 'plan auto rich' -complete -c gradle -l continue -d 'Continue task execution after failure' -complete -c gradle -l system-prop -s D -r -d 'Set system property of the JVM' -complete -c gradle -l debug -s d -d 'Log in debug mode' -complete -c gradle -l daemon -d 'Uses Gradle Daemon to run build' -complete -c gradle -l foreground -d 'Uses Gradle Daemon in foreground' -complete -c gradle -l gradle-user-home -s g -r -d 'Specify gradle user home directory' -complete -c gradle -l initscript -s I -r -d 'Specify an initialization script' -complete -c gradle -l info -s i -d 'Set log level to info' -complete -c gradle -l include-build -r -d 'Include specified build in composite' -complete -c gradle -l dry-run -s m -d 'Runs build with all task actions disabled' -complete -c gradle -l max-workers -x -d 'Configure number of concurrent workers' -a '1\t 2\t 3\t 4\t 5\t 6\t 7\t 8\t 9\t 10\t' -complete -c gradle -l no-daemon -d 'Don\'t use deamon' -complete -c gradle -l offline -d 'Don\'t use network resources' -complete -c gradle -l project-prop -s P -x -d 'Set project property for build script' -complete -c gradle -l project-dir -s p -r -d 'Specify start directory' -complete -c gradle -l parallel -d 'Build project in parallel' -complete -c gradle -l profile -d 'Profile build execution time' -complete -c gradle -l project-cache-dir -r -d 'Specify project cache directory' -complete -c gradle -l quiet -s q -d 'Only log erros' -complete -c gradle -l recompile-scripts -d 'Force build script recompiling' -complete -c gradle -l refresh-dependencies -d 'Refresh state of dependencies' -complete -c gradle -l rerun-tasks -d 'Ignore previously cached dependencies' -complete -c gradle -l full-stacktrace -s S -d 'Print out full stacktrace for all exceptions' -complete -c gradle -l status -d 'Shows status of running andrecently stopped daemon' -complete -c gradle -l stop -d 'Stop daemon if running' -complete -c gradle -l continuous -s t -d 'Enable continuous build' -complete -c gradle -l no-search-upward -s u -d 'Don\'t search in parent folders for settings file' -complete -c gradle -l version -s v -d 'Print version' -complete -c gradle -l exclude-task -s x -x -d 'Specify task to be excluded from execution' +function __fish_gradle_contains_build_file + test -f build.gradle -o -f build.gradle.kts +end -# https://github.com/hanny24/gradle-fish/blob/master/gradle.load -function __cache_or_get_gradle_completion +function __fish_gradle_create_completion_cache_file # Set up cache directory if test -z $XDG_CACHE_HOME - set XDG_CACHE_HOME $HOME/.cache/ + set XDG_CACHE_HOME $HOME/.cache end mkdir -m 700 -p $XDG_CACHE_HOME/gradle-completions - set -l hashed_pwd (__fish_md5 -s $PWD) - set -l gradle_cache_file $XDG_CACHE_HOME/gradle-completions/$hashed_pwd - if not test -f $gradle_cache_file; or command test build.gradle -nt $gradle_cache_file - command gradle -q tasks 2>/dev/null | string match -r '^[[:alnum:]]+ - .*' | string replace ' - ' \t >$gradle_cache_file + string trim -- $XDG_CACHE_HOME/gradle-completions/(__fish_md5 -s $argv[1] | string split ' = ')[2] +end + +############################## +# Configure Tasks Completion # +############################## + +# Outside of a Project +function __fish_gradle_get_default_task_completion + if __fish_gradle_contains_build_file + return end - cat $gradle_cache_file + + printf '%s\t%s\n' \ + "buildEnvironment" "Display buildscript dependencies" \ + "components" "Display components" \ + "dependencies" "Display dependencies" \ + "dependencyInsight" "Display insight of a given dependency" \ + "dependentComponents" "Display the dependent components" \ + "help" "Display help message" \ + "init" "Initialize new Gradle project" \ + "model" "Display configuration model" \ + "projects" "Display sub-projects" \ + "properties" "Display properties" \ + "tasks" "Display tasks" \ + "wrapper" "Generate Gradle wrapper files" end -function __contains_gradle_build - test -f build.gradle +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --exclusive \ + --arguments "(__fish_gradle_get_default_task_completion)" + +# Inside of a Project +function __fish_gradle_get_task_completion + if not __fish_gradle_contains_build_file + return + end + + set -l gradle_cache_file (__fish_gradle_create_completion_cache_file "{$PWD}-tasks") + if not command test -f $gradle_cache_file -a -s $gradle_cache_file + command gradle -q tasks --all 2>/dev/null | string match --regex '^[a-z][A-z:]+.*' | string replace ' - ' \t >$gradle_cache_file + end + + # return possible tasks + string trim -- <$gradle_cache_file end -complete -x -c gradle -n __contains_gradle_build -a "(__cache_or_get_gradle_completion)" +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --condition "__fish_gradle_contains_build_file" \ + --exclusive \ + --arguments "(__fish_gradle_get_task_completion)" + + +############################### +# Configure Option Completion # +############################### + +function __fish_gradle_get_console_completion + printf '%s\t%s\n' \ + "auto" "Use 'rich' in console otherwise 'plain'" \ + "plain" "Disable color and rich output" \ + "rich" "Enable color and rich output" \ + "verbose" "Enable color, rich output, output task names and outcomes at the lifecycle log level" +end + +function __fish_gradle_get_property_completion + printf '%s\t%s\n' \ + "org.gradle.cache.reserved.mb" "Reserve Gradle Daemon memory for operations" \ + "org.gradle.caching" "Enable Gradle build cache" \ + "org.gradle.console" "Set type of console output to generate (plain, auto, rich, verbose)" \ + "org.gradle.daemon.debug" "Enable debug Gradle Daemon" \ + "org.gradle.daemon.idletimeout" "Kill Gradle Daemon after" \ + "org.gradle.debug" "Enable debug Gradle Client" \ + "org.gradle.jvmargs" "Set JVM arguments" \ + "org.gradle.java.home" "Set JDK home dir" \ + "org.gradle.logging.level" "Set default Gradle log level (quiet, warn, lifecycle, info, debug)" \ + "org.gradle.parallel" "Enable parallel project builds (incubating)" \ + "org.gradle.priority" "Set priority for Gradle worker processes (low, normal)" \ + "org.gradle.warning.mode" "Set types of warnings to log (all, summary, fail, none)" \ + "org.gradle.workers.max" "Set the number of workers Gradle is allowed to use" +end + +function __fish_gradle_get_priority_completion + printf '%s\t%s\n' \ + "normal" "Default process priority" \ + "low" "Low process priority" +end + +function __fish_gradle_get_warning_mode_completion + printf '%s\t%s\n' \ + "all" "Log all warnings" \ + "summary" "Suppress all warnings, log a summary at the end" \ + "fail" "Log all warnings and fail the build if there are any" \ + "none" "Suppress all warnings, including the summary at the end" +end + +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'help' \ + --short-option 'h' --short-option '?' \ + --description 'Show this help message' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'no-rebuild' \ + --short-option 'a' \ + --description 'Do not rebuild project dependencies' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'build-file' \ + --short-option 'b' \ + --require-parameter \ + --description 'Specify build file' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'build-cache' \ + --description 'Enable Gradle build cache' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'settings-file' \ + --short-option 'c' \ + --require-parameter \ + --description 'Specify settings file' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'configure-on-demand' \ + --description 'Configure necessary projects only [incubating]' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'console' \ + --exclusive \ + --description 'Specify type of console output' \ + --arguments "(__fish_gradle_get_console_completion)" +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'continue' \ + --description 'Continue task execution after task failures' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'system-prop' \ + --short-option 'D' \ + --exclusive \ + --description 'Set system property of the JVM (e.g. -Dmyprop=myvalue)' \ + --arguments "(__fish_gradle_get_property_completion)" +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'debug' \ + --short-option 'd' \ + --description 'Log in debug mode (incl. normal stacktrace)' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'daemon' \ + --description 'Uses Gradle Daemon' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'foreground' \ + --description 'Start Gradle Daemon in foreground' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'gradle-user-home' \ + --short-option 'g' \ + --require-parameter \ + --description 'Specify gradle user home directory' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'init-script' \ + --short-option 'I' \ + --require-parameter \ + --description 'Specify initialization script' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'info' \ + --short-option 'i' \ + --description 'Info log level' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'include-build' \ + --require-parameter \ + --description 'Include specified build in composite' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'dry-run' \ + --short-option 'm' \ + --description 'Run builds with all task actions disabled' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'max-workers' \ + --exclusive \ + --description 'Configure number of concurrent workers' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'no-build-cache' \ + --description 'Disable Gradle build cache' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'no-configure-on-demand' \ + --description 'Disable use of configuration on demand [incubating]' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'no-daemon' \ + --description 'Disable Gradle daemon' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'no-parallel' \ + --description 'Disable parallel execution' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'no-scan' \ + --description 'Disable creation of build scan' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'offline' \ + --description 'Execute build without accessing network resources' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'project-prop' \ + --short-option 'P' \ + --exclusive \ + --description 'Set project property for build script (e.g. -Pmyprop=myvalue)' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'project-dir' \ + --short-option 'p' \ + --require-parameter \ + --description 'Specify start directory for Gradle' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'parallel' \ + --description 'Build projects in parallel' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'priority' \ + --exclusive \ + --description 'Specify scheduling priority for the Gradle daemon and all processes launched by it' \ + --arguments "(__fish_gradle_get_priority_completion)" +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'profile' \ + --description 'Profile build execution time and generate report' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'project-cache-dir' \ + --require-parameter \ + --description 'Specify cache directory' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'quiet' \ + --short-option 'q' \ + --description 'Error log level' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'refresh-dependencies' \ + --description 'Refresh dependencies state' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'rerun-tasks' \ + --description 'Ignore previously cached task results' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'full-stacktrace' \ + --short-option 'S' \ + --description 'Print out full stacktrace' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'stacktrace' \ + --short-option 's' \ + --description 'Print out stacktrace' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'scan' \ + --description 'Creates build scan' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'status' \ + --description 'Show status of Gradle Daemon(s)' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'stop' \ + --description 'Stop Gradle Daemon(s)' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'continuous' \ + --short-option 't' \ + --description 'Enable continuous build' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'update-locks' \ + --description 'Perform a partial update of the dependency lock [incubating]' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'version' \ + --short-option 'v' \ + --description 'Print version info.' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'warn' \ + --short-option 'w' \ + --description 'Warn log level' +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'warning-mode' \ + --description 'Specify warn mode' \ + --arguments "(__fish_gradle_get_warning_mode_completion)" +complete --command 'gw' --command 'gradle' --command 'gradlew' \ + --long-option 'write-locks' \ + --description 'Persists dependency resolution for locked configurations [incubating]'