fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge pull request #116984a12d5771

master
3.4 KiB81 linesraw
1function __fish_argparse_exclusive_args --description 'Helper function to list unused options'
2    set --local all_tokens (commandline --tokens-expanded)
3    set --erase all_tokens[1]
4    set --local current_token (commandline --current-token)
5
6    if set --local index (contains --index -- '--' $all_tokens)
7        set index (math $index - 1)
8    else
9        set index (count $all_tokens)
10    end
11
12    set --local specifications
13    while test $index -gt 0
14        and set -l tok $all_tokens[$index]
15        and not string match --quiet -- '-*' $tok
16
17        if string match --quiet '*,*' $tok
18            set index (math $index - 1)
19            continue
20        end
21
22        set -l opt (string replace --regex '=.*' '' $tok)
23
24        if string match --quiet '*/*' $opt
25            set --append specifications (string split '/' $opt)
26        else if string match --quiet '*#*' $opt
27            set --append specifications (string split '#' $opt)
28        else
29            set --append specifications $opt
30        end
31        set index (math $index - 1)
32    end
33
34    if string match --quiet -- '-x*' $current_token
35        set current_token (string replace --regex -- '^-x' '' $current_token)
36    end
37
38    if test $index -gt 1
39        and string match --regex --quiet -- '^(-x|--exclusive)$' $all_tokens[(math $index - 1)]
40        and not test -z $current_token
41        set --erase specifications[(count $specifications)]
42    end
43
44    set --local used_options (string split -- ',' $current_token)
45    set --local unused_specifications
46
47    for item in $specifications
48        if not contains -- $item $used_options
49            set --append unused_specifications $item
50        end
51    end
52
53    string join \n $unused_specifications
54end
55
56complete --command argparse --no-files
57
58complete --command argparse --short-option h --long-option help --description 'Show help'
59
60complete --command argparse --short-option n --long-option name --require-parameter --no-files \
61    --arguments '(functions --all | string replace ", " "\n")' --description 'Use function name'
62complete --command argparse --short-option x --long-option exclusive --no-files --require-parameter \
63    --arguments '(__fish_append "," (__fish_argparse_exclusive_args))' \
64    --description 'Specify mutually exclusive options'
65complete --command argparse --short-option N --long-option min-args --no-files --require-parameter \
66    --description 'Specify minimum non-option argument count'
67complete --command argparse --short-option X --long-option max-args --no-files --require-parameter \
68    --description 'Specify maximum non-option argument count'
69complete --command argparse --short-option i --long-option ignore-unknown \
70    -n '! __fish_seen_argument --short u --long move-unknown' \
71    --description 'Ignore unknown options'
72complete --command argparse --short-option u --long-option move-unknown \
73    -n '! __fish_seen_argument --short i --long ignore-unknown' \
74    --description 'Move unknown options into \$argv_opts'
75complete --command argparse --short-option S --long-option strict-longopts \
76    --description 'Pass long options strictly'
77complete --command argparse --short-option U --long-option unknown-arguments --no-files --require-parameter \
78    --arguments "optional required none" \
79    --description 'Whether unknown options can have arguments'
80complete --command argparse --short-option s --long-option stop-nonopt \
81    --description 'Exit on subcommand'