From: "Jesper Nygårds" <jesper.nygards@gmail.com>
To: zsh-workers@zsh.org
Subject: [PATCH] Add _gradle for gradle and gradlew completion.
Date: Sat, 24 Mar 2012 11:28:21 +0100 [thread overview]
Message-ID: <CABZhJg_V5objd2LHhvpGbukBsgNoau_2tTYcn+UOgWh3pAEmjg@mail.gmail.com> (raw)
Please consider applying this patch for adding completion to gradle
and gradlew. Gradle is a build tool for java, scala and groovy.
diff -u -N --recursive a/Completion/Unix/Command/.distfiles
b/Completion/Unix/Command/.distfiles
--- a/Completion/Unix/Command/.distfiles 2012-03-24 10:43:55.425469198 +0100
+++ b/Completion/Unix/Command/.distfiles 2012-03-24 11:17:49.881397396 +0100
@@ -83,6 +83,7 @@
_gpg
_gphoto2
_gprof
+_gradle
_graphicsmagick
_grep
_groff
diff -u -N --recursive a/Completion/Unix/Command/_gradle
b/Completion/Unix/Command/_gradle
--- a/Completion/Unix/Command/_gradle 1970-01-01 01:00:00.000000000 +0100
+++ b/Completion/Unix/Command/_gradle 2012-03-24 11:17:18.489398504 +0100
@@ -0,0 +1,120 @@
+#compdef gradle gradlew
+
+_gradle() {
+ local curcontext="$curcontext" ret=1 state state_descr line
+ local gradle_inspect=yes cache_policy tag_order
+ local -A opt_args
+ local -a gradle_group_tasks gradle_all_tasks
+
+ zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy || \
+ zstyle ":completion:*:*:$service:*" cache-policy _gradle_caching_policy
+
+ # By default, we only complete main tasks (belonging to a group).
Secondary tasks are
+ # completed if no main tasks are found.
+ zstyle -a ":completion:*:*:$service:*" tag-order tag_order || \
+ zstyle ":completion:*:*:$service:*" tag-order 'gradle_group'
'gradle_all'
+
+ # The completion inspects the current build file to find tasks to
complete. Setting
+ # this style to 'no' or 'false' turns off inspection. In that
case only the built-in tasks
+ # are completed.
+ zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
+
+ _arguments -C \
+ '(-)'{-?,-h,--help}'[Shows this help message.]' \
+ {-a,--no-rebuild}'[Do not rebuild project dependencies.]' \
+ {-b,--build-file}'[Specifies the build file.]:build
file:_files -g "*.gradle(-.)"' \
+ {-C,--cache}'[Specifies how compiled build scripts should be
cached.]:cache policy:(on rebuild)' \
+ {-c,--settings-file}'[Specifies the settings file.]:settings
file:_files -g "*.properties(-.)"' \
+ '--continue[Continues task execution after a task failure.]' \
+ '*--system-prop[Set system property of the JVM (e.g.
-Dmyprop=myvalue).]:system property (prop=val):' \
+ '*-D+[Set system property of the JVM (e.g.
-Dmyprop=myvalue).]:system property (prop=val):' \
+ '(-i --info -q --quiet)'{-d,--debug}'[Log in debug mode
(includes normal stacktrace).]' \
+ '(--nodaemon)--daemon[Uses the Gradle daemon to run the
build. Starts the daemon if not running.]' \
+ '--foreground[Starts the Gradle daemon in the foreground.]' \
+ {-g,--gradle-user-home}'[Specifies the gradle user home
directory.]:home directory:_directories' \
+ '(-)--gui[Launches the Gradle GUI.]' \
+ {-I,--init-script}'[Specifies an initialization script.]:init
script:_files -g "*.gradle(-.)"' \
+ '(-d --debug -q --quiet)'{-i,--info}'[Set log level to info.]' \
+ {-m,--dry-run}'[Runs the builds with all task actions disabled.]' \
+ '--no-color[Do not use color in the console output.]' \
+ '(--daemon)--no-daemon[Do not use the Gradle daemon to run
the build.]' \
+ '--no-opt[Ignore any task optimization.]' \
+ '--offline[The build should operate without accessing network
resources.]' \
+ '*--project-prop[Set project property for the build script
(e.g. -Pmyprop=myvalue).]:project property (prop=val):' \
+ '*-P+[Set project property for the build script (e.g.
-Pmyprop=myvalue).]:project property (prop=val):' \
+ {-p,--project-dir}'[Specifies the start directory for
Gradle.]:start directory:_directories' \
+ '--profile[Profiles build execution time and generates a
report in the <build_dir>/reports/profile directory.]' \
+ '--project-cache-dir[Specifies the project-specific cache
directory.]:cache directory:_directories' \
+ '(-d --debug -i --info)'{-q,--quiet}'[Log errors only.]' \
+ "--refresh[Refresh the state of resources of the type(s)
specified.]:refresh policy:(dependencies)" \
+ '(-s --stacktrace)'{-S,--full-stacktrace}'[Print out the full
(very verbose) stacktrace for all exceptions.]' \
+ '(-S --full-stacktrace)'{-s,--stacktrace}'[Print out the
stacktrace for all exceptions.]' \
+ '(-)--stop[Stops the Gradle daemon if it is running.]' \
+ {-u,--no-search-upward}"[Don't search in parent folders for a
settings.gradle file.]" \
+ '(-)'{-v,--version}'[Print version info.]' \
+ {-x,--exclude-task}'[Specify a task to be excluded from
execution.]:task to exclude:->alltask' \
+ '*:task:->task' \
+ && ret=0
+
+ if [[ -n $state ]]; then
+ if [[ $gradle_inspect = yes ]]; then
+ # If a build file is specified after '-b' or
'--build-file', use this file. Otherwise,
+ # default is the file 'build.gradle' in the current directory.
+ local buildfile=${${(v)opt_args[(i)-b|--build-file]}:-build.gradle}
+
+ if [[ -f $buildfile ]]; then
+ # Set the caching policy to invalidate cache if the
build file is newer than the cache.
+ _gradle_caching_policy() {
+ [[ $buildfile -nt $1 ]]
+ }
+
+ # Cache name is constructed from the absolute path of
the build file.
+ local cache_name=${${buildfile:a}//[^[:alnum:]]/_}
+ if _cache_invalid $cache_name || ! _retrieve_cache
$cache_name; then
+ zle -R "Generating cache from $buildfile"
+ local outputline
+ local -a match mbegin mend
+ # Run gradle/gradlew and retrieve possible tasks.
+ for outputline in ${(f)"$($service --build-file
$buildfile -q tasks --all)"}; do
+ if [[ $outputline =
[[:blank:]]#(#b)([[:alnum:]]##)' - '(*) ]]; then
+ # The descriptions of main tasks start at
beginning of line, descriptions of
+ # secondary tasks are indented.
+ if [[ $outputline = [[:alnum:]]* ]]; then
+ gradle_group_tasks+=( "$match[1]:$match[2]" )
+ else
+ gradle_all_tasks+=( "$match[1]:$match[2]" )
+ fi
+ fi
+ done
+ _store_cache $cache_name gradle_group_tasks
gradle_all_tasks
+ fi
+
+ if [[ $state == task ]]; then
+ _tags gradle_group gradle_all
+ while _tags; do
+ # Offer main tasks and secondary tasks in
different tags.
+ _requested gradle_group && _describe 'group
tasks' gradle_group_tasks && ret=0
+ _requested gradle_all && _describe 'all
tasks' gradle_all_tasks && ret=0
+ (( ret )) || break
+ done
+ elif [[ $state == alltask ]]; then
+ # After '--exclude-task', we don't make a
distinction between main tasks and
+ # secondary tasks.
+ _describe 'all tasks' gradle_group_tasks --
gradle_all_tasks && ret=0
+ fi
+ fi
+ else
+ _describe 'built-in tasks' '(
+ "dependencies:Displays the dependencies of root project."
+ "help:Displays a help message."
+ "projects:Displays the sub-projects of root project."
+ "properties:Displays the properties of root project."
+ "tasks:Displays the tasks runnable from root project."
+ )' && ret=0
+ fi
+ fi
+
+ return ret
+}
+
+_gradle "$@"
next reply other threads:[~2012-03-24 10:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-24 10:28 Jesper Nygårds [this message]
2012-03-24 10:39 ` Mikael Magnusson
2012-03-24 10:55 ` Jesper Nygårds
2012-03-24 11:14 ` Mikael Magnusson
[not found] ` <CABZhJg9xgaM7mr4dy8GYKHopAofnVRCzZmxfOsEca1VNugv6Cw@mail.gmail.com>
2012-03-24 22:04 ` Jesper Nygårds
2012-03-24 22:16 ` Mikael Magnusson
[not found] ` <CABZhJg_Aamsf57nhBFEvc0LX-pmOkrfRtGMccJo_Uwt=hoNQ6w@mail.gmail.com>
2012-03-25 14:23 ` Jesper Nygårds
2012-03-25 14:25 ` Jesper Nygårds
2012-03-25 14:51 ` Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABZhJg_V5objd2LHhvpGbukBsgNoau_2tTYcn+UOgWh3pAEmjg@mail.gmail.com \
--to=jesper.nygards@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).