
use builtin;
use str;

set edit:completion:arg-completer[oparlint] = {|@words|
    fn spaces {|n|
        builtin:repeat $n ' ' | str:join ''
    }
    fn cand {|text desc|
        edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
    }
    var command = 'oparlint'
    for word $words[1..-1] {
        if (str:has-prefix $word '-') {
            break
        }
        set command = $command';'$word
    }
    var completions = [
        &'oparlint'= {
            cand -h 'Print help'
            cand --help 'Print help'
            cand -V 'Print version'
            cand --version 'Print version'
            cand check 'Check a URL endpoint for compliance with OParl'
            cand generate-shell-completion 'Generate shell comletion'
            cand help 'Print this message or the help of the given subcommand(s)'
        }
        &'oparlint;check'= {
            cand -h 'Print help'
            cand --help 'Print help'
        }
        &'oparlint;generate-shell-completion'= {
            cand -h 'Print help'
            cand --help 'Print help'
        }
        &'oparlint;help'= {
            cand check 'Check a URL endpoint for compliance with OParl'
            cand generate-shell-completion 'Generate shell comletion'
            cand help 'Print this message or the help of the given subcommand(s)'
        }
        &'oparlint;help;check'= {
        }
        &'oparlint;help;generate-shell-completion'= {
        }
        &'oparlint;help;help'= {
        }
    ]
    $completions[$command]
}
