#compdef miniserve

autoload -U is-at-least

_miniserve() {
    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[@]}" : \
'--temp-directory=[The path to where file uploads will be written to before being moved to their correct location. It'\''s wise to make sure that this directory will be written to disk and not into memory]:TEMP_UPLOAD_DIRECTORY:_files' \
'--index=[The name of a directory index file to serve, like "index.html"]:INDEX:_files' \
'-p+[Port to use]:PORT:_default' \
'--port=[Port to use]:PORT:_default' \
'*-i+[Interface to listen on]:INTERFACES:_default' \
'*--interfaces=[Interface to listen on]:INTERFACES:_default' \
'*-a+[Set authentication]:AUTH:_default' \
'*--auth=[Set authentication]:AUTH:_default' \
'--auth-file=[Read authentication values from a file]:AUTH_FILE:_files' \
'--route-prefix=[Use a specific route prefix]:ROUTE_PREFIX:_default' \
'-S+[Default sorting method for file list]:DEFAULT_SORTING_METHOD:((name\:"Sort by name"
size\:"Sort by size"
date\:"Sort by last modification date (natural sort\: follows alphanumerical order)"))' \
'--default-sorting-method=[Default sorting method for file list]:DEFAULT_SORTING_METHOD:((name\:"Sort by name"
size\:"Sort by size"
date\:"Sort by last modification date (natural sort\: follows alphanumerical order)"))' \
'-O+[Default sorting order for file list]:DEFAULT_SORTING_ORDER:((asc\:"Ascending order"
desc\:"Descending order"))' \
'--default-sorting-order=[Default sorting order for file list]:DEFAULT_SORTING_ORDER:((asc\:"Ascending order"
desc\:"Descending order"))' \
'-c+[Default color scheme]:COLOR_SCHEME:(squirrel archlinux zenburn monokai)' \
'--color-scheme=[Default color scheme]:COLOR_SCHEME:(squirrel archlinux zenburn monokai)' \
'-d+[Default color scheme]:COLOR_SCHEME_DARK:(squirrel archlinux zenburn monokai)' \
'--color-scheme-dark=[Default color scheme]:COLOR_SCHEME_DARK:(squirrel archlinux zenburn monokai)' \
'*-u+[Enable file uploading (and optionally specify for which directory)]' \
'*--upload-files=[Enable file uploading (and optionally specify for which directory)]' \
'--web-upload-files-concurrency=[Configure amount of concurrent uploads when visiting the website. Must have upload-files option enabled for this setting to matter]:WEB_UPLOAD_CONCURRENCY:_default' \
'*-m+[Specify uploadable media types]:MEDIA_TYPE:(image audio video)' \
'*--media-type=[Specify uploadable media types]:MEDIA_TYPE:(image audio video)' \
'(-m --media-type)-M+[Directly specify the uploadable media type expression]:MEDIA_TYPE_RAW:_default' \
'(-m --media-type)--raw-media-type=[Directly specify the uploadable media type expression]:MEDIA_TYPE_RAW:_default' \
'-o+[What to do if existing files with same name is present during file upload]:ON_DUPLICATE_FILES:(error overwrite rename)' \
'--on-duplicate-files=[What to do if existing files with same name is present during file upload]:ON_DUPLICATE_FILES:(error overwrite rename)' \
'-t+[Shown instead of host in page title and heading]:TITLE:_default' \
'--title=[Shown instead of host in page title and heading]:TITLE:_default' \
'*--header=[Inserts custom headers into the responses. Specify each header as a '\''Header\:Value'\'' pair. This parameter can be used multiple times to add multiple headers]:HEADER:_default' \
'--print-completions=[Generate completion file for a shell]:shell:(bash elvish fish powershell zsh)' \
'--tls-cert=[TLS certificate to use]:TLS_CERT:_files' \
'--tls-key=[TLS private key to use]:TLS_KEY:_files' \
'--size-display=[Show served file size in exact bytes]:SIZE_DISPLAY:(human exact)' \
'--file-external-url=[Optional external URL (e.g., '\''http\://external.example.com\:8081'\'') prepended to file links in listings]:FILE_EXTERNAL_URL:_default' \
'-v[Be verbose, includes emitting access logs]' \
'--verbose[Be verbose, includes emitting access logs]' \
'--spa[Activate SPA (Single Page Application) mode]' \
'--pretty-urls[Activate Pretty URLs mode]' \
'(--route-prefix)--random-route[Generate a random 6-hexdigit route]' \
'-P[Hide symlinks in listing and prevent them from being followed]' \
'--no-symlinks[Hide symlinks in listing and prevent them from being followed]' \
'-H[Show hidden files]' \
'--hidden[Show hidden files]' \
'-q[Enable QR code display]' \
'--qrcode[Enable QR code display]' \
'--directory-size[Enable recursive directory size calculation]' \
'-U[Enable creating directories]' \
'--mkdir[Enable creating directories]' \
'-r[Enable uncompressed tar archive generation]' \
'--enable-tar[Enable uncompressed tar archive generation]' \
'-g[Enable gz-compressed tar archive generation]' \
'--enable-tar-gz[Enable gz-compressed tar archive generation]' \
'-z[Enable zip archive generation]' \
'--enable-zip[Enable zip archive generation]' \
'-C[Compress response]' \
'--compress-response[Compress response]' \
'-D[List directories first]' \
'--dirs-first[List directories first]' \
'-l[Visualize symlinks in directory listing]' \
'--show-symlink-info[Visualize symlinks in directory listing]' \
'-F[Hide version footer]' \
'--hide-version-footer[Hide version footer]' \
'--hide-theme-selector[Hide theme selector]' \
'-W[If enabled, display a wget command to recursively download the current directory]' \
'--show-wget-footer[If enabled, display a wget command to recursively download the current directory]' \
'--print-manpage[Generate man page]' \
'--readme[Enable README.md rendering in directories]' \
'-I[Disable indexing]' \
'--disable-indexing[Disable indexing]' \
'--enable-webdav[Enable read-only WebDAV support (PROPFIND requests)]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'::path -- Which path to serve:_files' \
&& ret=0
}

(( $+functions[_miniserve_commands] )) ||
_miniserve_commands() {
    local commands; commands=()
    _describe -t commands 'miniserve commands' commands "$@"
}

if [ "$funcstack[1]" = "_miniserve" ]; then
    _miniserve "$@"
else
    compdef _miniserve miniserve
fi
