plugins/bash/phan

Summary

Maintainability
Test Coverage
# This is a bash completion script for Phan.
# Author: Tyson Andre

# To install this, either
# 1. copy this file into /etc/bash_completion.d/phan (recommended, must be root)
#
#    Then, add `source /etc/profile.d/bash_completion.sh || true` to ~/.bashrc or ~/.profile to ensure that bash completions are set up,
#    if you haven't set them up already (make sure that bash_completion.sh was created)
#
#    If adding this to ~/.profile, you'd need to log out and log in to make it permanent - bash needs to run `/etc/profile.d/bash_completion.sh` on login for this to take effect permanently.
# 2. add `source path/to/phan/plugins/bash/phan || true` to your .bashrc and start a new bash shell.

# Refer to https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2 and other parts for how bash completion scripts work

_phan() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    # Generated by calling _debug_arguments in plugins/zsh/phan
    opts="
--file-list
-f
--exclude-file
--exclude-directory-list
-3
--include-analysis-file-list
-I
--directory
-l
--project-root-directory
-d
-r
--file-list-only
--config-file
-k
--output-mode
-m
--output
-o
--init
--init-level
--init-analyze-dir
--init-analyze-file
--init-no-composer
--init-overwrite
--color
-C
--no-color
--color-scheme
--progress-bar
-p
--no-progress-bar
--long-progress-bar
-D
--debug
--debug-emitted-issues
--debug-signal-handler
-q
--quick
--target-php-version
--minimum-target-php-version
--ignore-undeclared
-i
--minimum-severity
-y
--parent-constructor-required
-c
--dead-code-detection
-x
--dead-code-detection-prefer-false-positive
-X
--unused-variable-detection
-u
--redundant-condition-detection
-t
--processes
-j
--signature-compatibility
-z
--disable-cache
--disable-plugins
-P
--plugin
--native-syntax-check
--strict-method-checking
--strict-object-checking
--strict-param-checking
--strict-property-checking
--strict-return-checking
--strict-type-checking
--use-fallback-parser
--allow-polyfill-parser
--force-polyfill-parser
--daemonize-socket
-s
--daemonize-tcp-host
--daemonize-tcp-port
--save-baseline
-B
--load-baseline
--baseline-summary-type
--analyze-twice
--analyze-all-files
--always-exit-successfully-after-analysis
-h
--help
-v
--version
--extended-help
--dump-ast
--dump-ctags
-a
--dump-analyzed-file-list
--dump-parsed-file-list
--dump-signatures-file
--automatic-fix
--find-signature
--memory-limit
--print-memory-usage-summary
--markdown-issue-messages
--absolute-path-issue-messages
--constant-variable-detection
--require-config-exists
--help-annotaitons
    "
    case "$prev" in
        --file-list | \
        -f | \
        --exclude-file | \
        --include-analysis-file-list | \
        -I | \
        --save-baseline | \
        -B | \
        --load-baseline | \
        --file-list-only | \
        -r | \
        --config-file | \
        -k | \
        --output | \
        -o | \
        --init-analyze-file | \
        --daemonize-socket | \
        -s | \
        --dump-signatures-file)
            # Suggest file completions
            COMPREPLY=( $(compgen -f "${cur}" ) )
            return 0
            ;;
        --exclude-directory-list | \
        -3 | \
        --directory | \
        -l | \
        --project-root-directory | \
        -d | \
        --init-analyze-dir)
            # Suggest directory completions
            COMPREPLY=( $(compgen -d "${cur}" ) )
            return 0
            ;;
        --output-mode | -m)
            COMPREPLY=( $(compgen -W "text verbose json csv codeclimate checkstyle pylint html" -- "${cur}" ))
            return 0
            ;;
        --baseline-summary-type)
            COMPREPLY=( $(compgen -W "ordered_by_count ordered_by_type none" -- "${cur}" ))
            return 0
            ;;
        --init-level)
            COMPREPLY=( $(compgen -W "1 2 3 4 5" -- "${cur}" ))
            return 0
            ;;
        --target-php-version)
            COMPREPLY=( $(compgen -W "7.0 7.1 7.2 7.3 7.4 8.0" -- "${cur}" ))
            return 0
            ;;
        --minimum-severity | -y)
            COMPREPLY=( $(compgen -W "0 5 10 low normal high" -- "${cur}" ) )
            return 0
            ;;
        --color-scheme)
            COMPREPLY=( $(compgen -W "default code eclipse-dark light vim" -- "${cur}" ))
            return 0
            ;;
        --plugin | -P)
            # plugin list generated with "ls .phan/plugins|grep '\.php'|sed 's,\.php,,'|xargs echo"
            # Suggest both local files and names of known phan plugins
            COMPREPLY=( $(compgen -f -W "AlwaysReturnPlugin AvoidableGetterPlugin ConstantVariablePlugin DemoPlugin DeprecateAliasPlugin DollarDollarPlugin DuplicateArrayKeyPlugin DuplicateConstantPlugin DuplicateExpressionPlugin EmptyMethodAndFunctionPlugin EmptyStatementListPlugin FFIAnalysisPlugin HasPHPDocPlugin InlineHTMLPlugin InvalidVariableIssetPlugin InvokePHPNativeSyntaxCheckPlugin LoopVariableReusePlugin MoreSpecificElementTypePlugin NoAssertPlugin NonBoolBranchPlugin NonBoolInLogicalArithPlugin NotFullyQualifiedUsagePlugin NumericalComparisonPlugin PhanSelfCheckPlugin PHP53CompatibilityPlugin PHPDocInWrongCommentPlugin PHPDocRedundantPlugin PHPDocToRealTypesPlugin PHPUnitAssertionPlugin PHPUnitNotDeadCodePlugin PossiblyStaticMethodPlugin PreferNamespaceUsePlugin PregRegexCheckerPlugin PrintfCheckerPlugin RedundantAssignmentPlugin RemoveDebugStatementPlugin ShortArrayPlugin SimplifyExpressionPlugin SleepCheckerPlugin StrictComparisonPlugin StrictLiteralComparisonPlugin SuspiciousParamOrderPlugin UnknownClassElementAccessPlugin UnknownElementTypePlugin UnreachableCodePlugin UnsafeCodePlugin UnusedSuppressionPlugin UseReturnValuePlugin WhitespacePlugin" -- "${cur}" ) )
            return 0
            ;;
        --daemonize-tcp-host)
            COMPREPLY=( $(compgen -W "127.0.0.1 0.0.0.0 default" -- "${cur}" ) )
            return 0
            ;;
        --memory-limit | \
        --daemonize-tcp-port | \
        --find-signature)
            # We don't know how to complete these options, but they have required arguments. Don't suggest files
            COMPREPLY=()
            return 0
            ;;
    esac

    if [[ "${cur}" == '' || "${cur}" == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- "${cur}" ) )
        return 0
    fi
}
complete -F _phan phan