fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a9618477e
master
1function __fish_parse_configure 2if test ( count $argv ) -ne 1 3echo "Usage: parse_configure path/to/configure" 1>&2 4return 1 5end 6 7# `complete` parses `./configure` as `configure` so we have to handle all paths, not just ./ 8if not test -x $argv [ 1 ] 9printf "Cannot find or execute '%s'\n" $argv [ 1 ] 1>&2 10return 1 11end 12 13# Must support output along the lines of 14# -h, --help display this help and exit 15# --help=short display options specific to this package 16# --help=recursive display the short help of all the included packages 17# -V, --version display version information and exit 18# -q, --quiet, --silent do not print `checking ...' messages 19 20set -l next_line 21set -l line 22set -l buffer 23# Just fish's `./configure --help` takes ~350ms to run, before parsing 24# The following chain attempts to extract the help message: 25cat $argv [ 1 ] | tr \n \u0e | sed -n's/.*Report the --help message\(.*\?\)ac_status.*/\1/; s/ac_status.*//p' | tr \u0e \n | 26while test -n " $next_line " || read -lL next_line 27# In autoconfigure scripts, the first column wraps at 26 chars 28# echo next_line: $next_line 29# echo old_line: $line 30if test -z " $line " 31set line$next_line 32set next_line"" # mark it as consumed 33continue 34else if string match -qr'^( |\t){2,}[^-]\S*' --$next_line 35# echo "continuation line found. Old value of line: " \"$line\" 36set line" $line " ( string trim$next_line ) 37set next_line"" # mark it as consumed 38continue 39end 40 41# echo line: $line 42 43# Search for one or more strings starting with `-` separated by commas 44if string replace -fr'^\s+(-.*?)\s+([^\s\-].*)' '$1\n$2' --$line | read -lL opts description 45for optin ( string split -n , --$opts | string trim) 46 47if string match -qr --'--[a-z_0-9-]+=\[.*\]' $opt 48# --option=[OPTIONAL_VALUE] 49string replace -r --'(--[a-z_0-9-]+)=.*' '$1' $opt | read opt 50else if string match -qr --'--[a-z_0-9-]+\[=.*\]' $opt 51# --option[=OPTIONAL_VALUE] 52string replace -r --'(--[a-z_0-9-]+)\[=.*' '$1' $opt | read opt 53else if string match -qr --'--[a-z_0-9-]+=[A-Z]+' $opt 54# --option=CLASS_OF_VALUE (eg FILE or DIR) 55string replace -r --'(--[a-z_0-9-]+)=.*' '$1' $opt | read opt 56else if string match -qr --'--[a-z_0-9-]+=\S+' $opt 57# --option=literal_value, leave as-is 58else if string match -qr --'--[a-z_0-9-]+$' $opt 59# long option, leave as-is 60else if string match -qr --'-[^-]$' $opt 61# short option, leave as-is 62else 63continue 64end 65 66echo " $opt "\t" $description " # parsed by `complete` as value and description 67end 68end 69 70set line"" 71end 72end 73 74complete -c configure -s h -l help -x -a"short recursive" -d"Display help and exit" 75complete -c configure -s V -l version -d"Display version and exit" 76complete -c configure -s q -l quiet -d"Quiet mode" 77complete -c configure -l cache-file -f -d"Cache test results in specified file" 78complete -c configure -s C -l config-cache -d"Cache test results in file config.cache" 79complete -c configure -s n -l no-create -d"Do not create output files" 80complete -c configure -l srcdir -d"Set source directory" -a"(__fish_complete_directories)" -x 81complete -c configure -l prefix -d"Architecture-independent install directory" -a"(__fish_complete_directories)" -x 82complete -c configure -l exec-prefix -d"Architecture-dependent install directory" -a"(__fish_complete_directories)" -x 83complete -c configure -l build -d"Configure for building on BUILD" -x 84complete -c configure -l host -d"Cross-compile to build programs to run on HOST" -x 85complete -c configure -l target -d"Configure for building compilers for TARGET" -x 86 87# use autoconf's --help to generate completions: 88complete -c configure -a'(for tok in (commandline -xpc) 89if string match -q "*configure" -- $tok 90__fish_parse_configure $tok 91break 92end 93end)'