• Duy Nguyen's avatar
    completion: collapse extra --no-.. options · b221b5ab
    Duy Nguyen authored
    The commands that make use of --git-completion-helper feature could
    now produce a lot of --no-xxx options that a command can take. This in
    many case could nearly double the amount of completable options, using
    more screen estate and also harder to search for the wanted option.
    
    This patch attempts to mitigate that by collapsing extra --no-
    options, the ones that are added by --git-completion-helper and not in
    original struct option arrays. The "--no-..." option will be displayed
    in this case to hint about more options, e.g.
    
        > ~/w/git $ git clone --
        --bare                 --origin=
        --branch=              --progress
        --checkout             --quiet
        --config=              --recurse-submodules
        --depth=               --reference=
        --dissociate           --reference-if-able=
        --filter=              --separate-git-dir=
        --hardlinks            --shallow-exclude=
        --ipv4                 --shallow-since=
        --ipv6                 --shallow-submodules
        --jobs=                --shared
        --local                --single-branch
        --mirror               --tags
        --no-...               --template=
        --no-checkout          --upload-pack=
        --no-hardlinks         --verbose
        --no-tags
    
    and when you complete it with --no-<tab>, all negative options will be
    presented:
    
        > ~/w/git $ git clone --no-
        --no-bare                 --no-quiet
        --no-branch               --no-recurse-submodules
        --no-checkout             --no-reference
        --no-config               --no-reference-if-able
        --no-depth                --no-separate-git-dir
        --no-dissociate           --no-shallow-exclude
        --no-filter               --no-shallow-since
        --no-hardlinks            --no-shallow-submodules
        --no-ipv4                 --no-shared
        --no-ipv6                 --no-single-branch
        --no-jobs                 --no-tags
        --no-local                --no-template
        --no-mirror               --no-upload-pack
        --no-origin               --no-verbose
        --no-progress
    
    Corner case: to make sure that people will never accidentally complete
    the fake option "--no-..." there must be one real --no- in the first
    complete listing even if it's not from the original struct option.
    
    PS. This could could be made simpler with ";&" to fall through from
    "--no-*" block and share the code but ";&" is not available on bash-3
    (i.e. Mac)
    Signed-off-by: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    b221b5ab
parse-options.c 19.6 KB