Redo ant completions

Closes #5475
This commit is contained in:
wyahiro 2019-01-03 23:03:22 +09:00 committed by Mahmoud Al-Qudsi
parent 5adc07bf28
commit e9f0a8cf2c
3 changed files with 97 additions and 15 deletions

View File

@ -1,3 +1,36 @@
# Apache Ant (1.9.5) completion for Fish Shell.
# completion for ant targets
complete -x -c ant -a "(__fish_complete_ant_targets)"
# Script Options:
complete -f -c ant -l help -l h -d 'print help message and ant help'
complete -f -c ant -l noconfig -d 'suppress sourcing of /etc/ant.conf, $HOME/.ant/ant.conf, and $HOME/.antrc configuration files'
complete -f -c ant -l usejikes -d 'enable use of jikes by default, unless set explicitly in configuration files'
complete -f -c ant -l execdebug -d 'print ant exec line generated by this launch script'
# Options:
complete -f -c ant -o help -s h -d 'print help message and exit'
complete -f -c ant -o projecthelp -s p -d 'print project help information and exit'
complete -f -c ant -o version -d 'print the version information and exit'
complete -f -c ant -o diagnostics -d 'print information that might be helpful to diagnose or report problems and exit'
complete -f -c ant -o quiet -s q -d 'be extra quiet'
complete -f -c ant -o silent -s S -d 'print nothing but task outputs and build failures'
complete -f -c ant -o verbose -s v -d 'be extra verbose'
complete -f -c ant -o debug -s d -d 'print debugging information'
complete -f -c ant -o emacs -s e -d 'produce logging information without adornments'
complete -f -c ant -o noinput -d 'do not allow interactive input'
complete -f -c ant -s D -d 'use value for given property like -D<property>=<value>'
complete -f -c ant -o keep-going -s k -d 'execute all targets that do not depend on failed target(s)'
complete -f -c ant -o nouserlib -d 'Run ant without using the jar files from ${user.home}/.ant/lib'
complete -f -c ant -o noclasspath -d 'Run ant without using CLASSPATH'
complete -f -c ant -o autoproxy -d 'Java1.5+: use the OS proxy settings'
complete -r -c ant -o lib -d 'specifies a path to search for jars and classes'
complete -r -c ant -o logfile -s l -d 'use given file for log'
complete -r -c ant -o logger -d 'the class which is to perform logging'
complete -r -c ant -o listener -d 'add an instance of class as a project listener'
complete -r -c ant -o buildfile -o file -s f -d 'use given buildfile'
complete -r -c ant -o propertyfile -d 'load all properties from file with -D properties taking precedence'
complete -r -c ant -o inputhandler -d 'the class which will handle input requests'
complete -r -c ant -o find -s s -d '(s)earch for buildfile towards the root of the filesystem and use it'
complete -r -c ant -o nice -d 'A niceness value for the main thread: 1 (lowest) to 10 (highest); 5 is the default'
complete -r -c ant -o main -d 'override Ant\'s normal entry point'

View File

@ -1,16 +1,68 @@
function __fish_complete_ant_targets -d "Print list of targets from build.xml and imported files"
set -l buildfile "build.xml"
if test -f $buildfile
# show ant targets
__fish_filter_ant_targets $buildfile
# find files with buildfile
set files (sed -n "s/^.*<import[^>]* file=[\"']\([^\"']*\)[\"'].*\$/\1/p" < $buildfile)
# iterate through files and display their targets
for file in $files
__fish_filter_ant_targets $file
function __filter_xml_start_tag -d "Filter xml start-tags in a buildfile"
set -l buildfile $argv[1] # full path to buildfile
set -l tag_pattern $argv[2] # regex pattern for tagname
# regex to filter start-tags ignoring newlines and '>' in attr values
# https://www.debuggex.com/r/wRgxHE1yTIgnjfNz
string join ' ' <$buildfile | string match -ar "<(?:$tag_pattern)(?:[^>\"']*?(?:(?:'[^']*?')|(?:\"[^\"]*\"))?)*?>"
end
function __filter_xml_attr_value -d "Filter xml attr value in a start-tag"
set -l tag $argv[1] # start-tag
set -l attr $argv[2] # attr name
# regex to filter attr values ignoring (single|double) quotes in attr values
# https://www.debuggex.com/r/x7lhtLJSP4msleik
string replace -rf "^.*$attr=((?:'(?:.*?)')|(?:\"(?:.*?)\")).*\$" '$1' $tag | string trim -c='"\''
end
function __get_buildfile -d "Get a buildfile that will be used by ant"
set -l tokens $argv # tokens from 'commandline -co'
set -l prev $tokens[1]
set -l buildfile "build.xml"
for token in $argv[2..-1]
switch $prev
case -buildfile -file -f
set buildfile (eval echo $token)
end
set prev $token
end
# return last one
echo $buildfile
end
function __parse_ant_targets -d "Parse ant targets in the given build file"
set -l buildfile $argv[1] # full path to buildfile
set -l targets (__filter_xml_start_tag $buildfile 'target|extension-point')
for target in $targets
set -l target_name (__filter_xml_attr_value $target 'name')
if [ $status -eq 0 ]
set -l target_description (__filter_xml_attr_value $target 'description')
if [ $status -eq 0 ]
echo $target_name\t$target_description
else
echo $target_name
end
end
end
end
function __get_ant_targets -d "Get ant targets recursively"
set -l buildfile $argv[1] # full path to buildfile
__parse_ant_targets $buildfile
set -l basedir (string split -r -m 1 / $buildfile)[1]
set -l imports (__filter_xml_start_tag $buildfile 'import')
for import in $imports
set -l filepath (__filter_xml_attr_value $import 'file')
# Set basedir if $filepath is not a full path
if string match -rvq '^/.*' $filepath
set filename $basedir/$filepath
end
if [ -f $filepath ]
__get_ant_targets $filepath
end
end
end
set -l tokens (commandline -co)
set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens))
if [ $status -eq 0 ]
__get_ant_targets $buildfile
end
end

View File

@ -1,3 +0,0 @@
function __fish_filter_ant_targets -d "Display targets within an ant build.xml file"
sed -n "s/^.*<target[^>]* name=[\"']\([^\"']*\)[\"'].*\$/\1/p" <$argv[1]
end