~zethra/license

3c3644a3ed0106dcb809adeb290582ec7dfc77b7 — Ben Aaron Goldberg 27 days ago 1ff986c
Added completions
A completions/_license => completions/_license +124 -0
@@ 0,0 1,124 @@
#compdef license

autoload -U is-at-least

_license_list() {
    compadd -a "$(license list | tr '\n' ' ')"
}

_license() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" \
'-v[Print addition debugging information]' \
'--verbose[Print addition debugging information]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
":: :_license_commands" \
"*::: :->license" \
&& ret=0
    case $state in
    (license)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:license-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(header)
_arguments "${_arguments_options[@]}" \
'-a+[Author of the project]' \
'--author=[Author of the project]' \
'-y+[Year of the project'\''s copyright]' \
'--copyright-year=[Year of the project'\''s copyright]' \
'-p+[Project name]' \
'--project-name=[Project name]' \
'-d+[Project description]' \
'--description=[Project description]' \
':license-name -- Name of the license to print:->list' \
'::comment-prefix -- Optional prefix to appended to every line of the header ex. '//' or '#'' \
&& ret=0
;;
(text)
_arguments "${_arguments_options[@]}" \
'-a+[Author of the project]' \
'--author=[Author of the project]' \
'-y+[Year of the project'\''s copyright]' \
'--copyright-year=[Year of the project'\''s copyright]' \
'-p+[Project name]' \
'--project-name=[Project name]' \
'-d+[Project description]' \
'--description=[Project description]' \
':license-name -- Name of the license to print:->list' \
&& ret=0
;;
(help)
ret=0
;;
        esac
    ;;
esac

case "$state" in
    list)
        _values '<license name>' $(license list | tr '\n' ' ')
esac
}

(( $+functions[_license_commands] )) ||
_license_commands() {
    local commands; commands=(
        "list:List available license names" \
"header:Print the header text for a license" \
"text:Print the text of a license" \
"help:Prints this message or the help of the given subcommand(s)" \
    )
    _describe -t commands 'license commands' commands "$@"
}
(( $+functions[_license__header_commands] )) ||
_license__header_commands() {
    local commands; commands=(
        
    )
    _describe -t commands 'license header commands' commands "$@"
}
(( $+functions[_license__help_commands] )) ||
_license__help_commands() {
    local commands; commands=(
        
    )
    _describe -t commands 'license help commands' commands "$@"
}
(( $+functions[_license__list_commands] )) ||
_license__list_commands() {
    local commands; commands=(
        
    )
    _describe -t commands 'license list commands' commands "$@"
}
(( $+functions[_license__text_commands] )) ||
_license__text_commands() {
    local commands; commands=(
        
    )
    _describe -t commands 'license text commands' commands "$@"
}

_license "$@"

A completions/_license.ps1 => completions/_license.ps1 +83 -0
@@ 0,0 1,83 @@

using namespace System.Management.Automation
using namespace System.Management.Automation.Language

Register-ArgumentCompleter -Native -CommandName 'license' -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)

    $commandElements = $commandAst.CommandElements
    $command = @(
        'license'
        for ($i = 1; $i -lt $commandElements.Count; $i++) {
            $element = $commandElements[$i]
            if ($element -isnot [StringConstantExpressionAst] -or
                $element.StringConstantType -ne [StringConstantType]::BareWord -or
                $element.Value.StartsWith('-')) {
                break
        }
        $element.Value
    }) -join ';'

    $completions = @(switch ($command) {
        'license' {
            [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Print addition debugging information')
            [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Print addition debugging information')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
            [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'List available license names')
            [CompletionResult]::new('header', 'header', [CompletionResultType]::ParameterValue, 'Print the header text for a license')
            [CompletionResult]::new('text', 'text', [CompletionResultType]::ParameterValue, 'Print the text of a license')
            [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Prints this message or the help of the given subcommand(s)')
            break
        }
        'license;list' {
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
            break
        }
        'license;header' {
            [CompletionResult]::new('-a', 'a', [CompletionResultType]::ParameterName, 'Author of the project')
            [CompletionResult]::new('--author', 'author', [CompletionResultType]::ParameterName, 'Author of the project')
            [CompletionResult]::new('-y', 'y', [CompletionResultType]::ParameterName, 'Year of the project''s copyright')
            [CompletionResult]::new('--copyright-year', 'copyright-year', [CompletionResultType]::ParameterName, 'Year of the project''s copyright')
            [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Project name')
            [CompletionResult]::new('--project-name', 'project-name', [CompletionResultType]::ParameterName, 'Project name')
            [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Project description')
            [CompletionResult]::new('--description', 'description', [CompletionResultType]::ParameterName, 'Project description')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
            break
        }
        'license;text' {
            [CompletionResult]::new('-a', 'a', [CompletionResultType]::ParameterName, 'Author of the project')
            [CompletionResult]::new('--author', 'author', [CompletionResultType]::ParameterName, 'Author of the project')
            [CompletionResult]::new('-y', 'y', [CompletionResultType]::ParameterName, 'Year of the project''s copyright')
            [CompletionResult]::new('--copyright-year', 'copyright-year', [CompletionResultType]::ParameterName, 'Year of the project''s copyright')
            [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Project name')
            [CompletionResult]::new('--project-name', 'project-name', [CompletionResultType]::ParameterName, 'Project name')
            [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Project description')
            [CompletionResult]::new('--description', 'description', [CompletionResultType]::ParameterName, 'Project description')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
            break
        }
        'license;help' {
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
            break
        }
    })

    $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
        Sort-Object -Property ListItemText
}

A completions/license.bash => completions/license.bash +179 -0
@@ 0,0 1,179 @@
_license() {
    local i cur prev opts cmds
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    cmd=""
    opts=""

    for i in ${COMP_WORDS[@]}
    do
        case "${i}" in
            license)
                cmd="license"
                ;;
            
            header)
                cmd+="__header"
                ;;
            help)
                cmd+="__help"
                ;;
            list)
                cmd+="__list"
                ;;
            text)
                cmd+="__text"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        license)
            opts=" -v -h -V  --verbose --help --version   list header text help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        
        license__header)
            opts="-a -y -p -d --author --copyright-year --project-name --description "
            opts+="$(license list | tr '\n' ' ')"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                --author)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -a)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --copyright-year)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -y)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --project-name)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --description)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -d)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        license__help)
            opts=" -h -V --help --version  "
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        license__list)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        license__text)
            opts="-a -y -p -d --author --copyright-year --project-name --description "
            opts+="$(license list | tr '\n' ' ')"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                --author)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -a)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --copyright-year)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -y)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --project-name)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --description)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                    -d)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

complete -F _license license

A completions/license.elv => completions/license.elv +71 -0
@@ 0,0 1,71 @@

edit:completion:arg-completer[license] = [@words]{
    fn spaces [n]{
        repeat $n ' ' | joins ''
    }
    fn cand [text desc]{
        edit:complex-candidate $text &display-suffix=' '(spaces (- 14 (wcswidth $text)))$desc
    }
    command = 'license'
    for word $words[1:-1] {
        if (has-prefix $word '-') {
            break
        }
        command = $command';'$word
    }
    completions = [
        &'license'= {
            cand -v 'Print addition debugging information'
            cand --verbose 'Print addition debugging information'
            cand -h 'Prints help information'
            cand --help 'Prints help information'
            cand -V 'Prints version information'
            cand --version 'Prints version information'
            cand list 'List available license names'
            cand header 'Print the header text for a license'
            cand text 'Print the text of a license'
            cand help 'Prints this message or the help of the given subcommand(s)'
        }
        &'license;list'= {
            cand -h 'Prints help information'
            cand --help 'Prints help information'
            cand -V 'Prints version information'
            cand --version 'Prints version information'
        }
        &'license;header'= {
            cand -a 'Author of the project'
            cand --author 'Author of the project'
            cand -y 'Year of the project''s copyright'
            cand --copyright-year 'Year of the project''s copyright'
            cand -p 'Project name'
            cand --project-name 'Project name'
            cand -d 'Project description'
            cand --description 'Project description'
            cand -h 'Prints help information'
            cand --help 'Prints help information'
            cand -V 'Prints version information'
            cand --version 'Prints version information'
        }
        &'license;text'= {
            cand -a 'Author of the project'
            cand --author 'Author of the project'
            cand -y 'Year of the project''s copyright'
            cand --copyright-year 'Year of the project''s copyright'
            cand -p 'Project name'
            cand --project-name 'Project name'
            cand -d 'Project description'
            cand --description 'Project description'
            cand -h 'Prints help information'
            cand --help 'Prints help information'
            cand -V 'Prints version information'
            cand --version 'Prints version information'
        }
        &'license;help'= {
            cand -h 'Prints help information'
            cand --help 'Prints help information'
            cand -V 'Prints version information'
            cand --version 'Prints version information'
        }
    ]
    $completions[$command]
}

A completions/license.fish => completions/license.fish +23 -0
@@ 0,0 1,23 @@
complete -c license -n "__fish_use_subcommand" -s v -l verbose -d 'Print addition debugging information'
complete -c license -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
complete -c license -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
complete -c license -n "__fish_use_subcommand" -f -a "list" -d 'List available license names'
complete -c license -n "__fish_use_subcommand" -f -a "header" -d 'Print the header text for a license'
complete -c license -n "__fish_use_subcommand" -f -a "text" -d 'Print the text of a license'
complete -c license -n "__fish_use_subcommand" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)'
complete -c license -n "__fish_seen_subcommand_from list" -s h -l help -d 'Prints help information'
complete -c license -n "__fish_seen_subcommand_from list" -s V -l version -d 'Prints version information'
complete -c license -n "__fish_seen_subcommand_from header" -s a -l author -d 'Author of the project'
complete -c license -n "__fish_seen_subcommand_from header" -s y -l copyright-year -d 'Year of the project\'s copyright'
complete -c license -n "__fish_seen_subcommand_from header" -s p -l project-name -d 'Project name'
complete -c license -n "__fish_seen_subcommand_from header" -s d -l description -d 'Project description'
complete -c license -n "__fish_seen_subcommand_from header" -s h -l help -d 'Prints help information'
complete -c license -n "__fish_seen_subcommand_from header" -s V -l version -d 'Prints version information'
complete -c license -n "__fish_seen_subcommand_from text" -s a -l author -d 'Author of the project'
complete -c license -n "__fish_seen_subcommand_from text" -s y -l copyright-year -d 'Year of the project\'s copyright'
complete -c license -n "__fish_seen_subcommand_from text" -s p -l project-name -d 'Project name'
complete -c license -n "__fish_seen_subcommand_from text" -s d -l description -d 'Project description'
complete -c license -n "__fish_seen_subcommand_from text" -s h -l help -d 'Prints help information'
complete -c license -n "__fish_seen_subcommand_from text" -s V -l version -d 'Prints version information'
complete -c license -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information'
complete -c license -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'