
use builtin;
use str;

set edit:completion:arg-completer[install] = {|@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 = 'install'
    for word $words[1..-1] {
        if (str:has-prefix $word '-') {
            break
        }
        set command = $command';'$word
    }
    var completions = [
        &'install'= {
            cand --backup 'make a backup of each existing destination file'
            cand -g 'set group ownership, instead of process''s current group'
            cand --group 'set group ownership, instead of process''s current group'
            cand -m 'set permission mode (as in chmod), instead of rwxr-xr-x'
            cand --mode 'set permission mode (as in chmod), instead of rwxr-xr-x'
            cand -o 'set ownership (super-user only)'
            cand --owner 'set ownership (super-user only)'
            cand --strip-program 'program used to strip binaries'
            cand -S 'override the usual backup suffix'
            cand --suffix 'override the usual backup suffix'
            cand -t 'move all SOURCE arguments into DIRECTORY'
            cand --target-directory 'move all SOURCE arguments into DIRECTORY'
            cand --context 'set security context of files and directories'
            cand -b 'like --backup but does not accept an argument'
            cand -c 'ignored'
            cand -C 'compare each pair of source and destination files, and in some cases, do not modify the destination at all'
            cand --compare 'compare each pair of source and destination files, and in some cases, do not modify the destination at all'
            cand -d 'treat all arguments as directory names. create all components of the specified directories'
            cand --directory 'treat all arguments as directory names. create all components of the specified directories'
            cand -D 'create all leading components of DEST except the last, then copy SOURCE to DEST'
            cand -p 'apply access/modification times of SOURCE files to corresponding destination files'
            cand --preserve-timestamps 'apply access/modification times of SOURCE files to corresponding destination files'
            cand -s 'strip symbol tables'
            cand --strip 'strip symbol tables'
            cand -T 'treat DEST as a normal file'
            cand --no-target-directory 'treat DEST as a normal file'
            cand -v 'explain what is being done'
            cand --verbose 'explain what is being done'
            cand -P 'preserve security context'
            cand --preserve-context 'preserve security context'
            cand -Z 'set SELinux security context of destination file and each created directory to default type'
            cand -U 'do not require elevated privileges to change the owner, the group, or the file flags of the destination'
            cand --unprivileged 'do not require elevated privileges to change the owner, the group, or the file flags of the destination'
            cand -h 'Print help'
            cand --help 'Print help'
            cand -V 'Print version'
            cand --version 'Print version'
        }
    ]
    $completions[$command]
}
