#compdef cmd

_alternative 'arguments:custom arg:(a b c)' 'files:filename:_files'

#compdef foo

autoload -U is-at-least

_foo() {
  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[@]}" : \
    '*:file:_files' \
    {-h,--help}'[Print help and exit]' \
    '--full-help[Print help, including hidden options, and exit]' \
    {-V,--version}'[Print version and exit]' \
    {-v,--verbose=}'[Print more information (default=0)]:INT:' \
    {-i,--input=}'[Filename to use as input, - for stdin (default=-)]:STRING:_files' \
    '-c+[Minimum lines of leading and trailing context surrounding each match]:NUM:_default' \
    '--min-context=[Minimum lines of leading and trailing context surrounding each match]:NUM:_default' \
    '-C+[Maximum lines of leading and trailing context surrounding each match]:NUM:_default' \
    '--max-context=[Maximum lines of leading and trailing context surrounding each match]:NUM:_default' \
    '--tab=[Number of spaces for tab character. Set 0 to pass tabs through directly]:NUM:_default' \
    '--theme=[Theme for syntax highlighting. Use --list-themes flag to print the theme list]:THEME:_default' \
    '-p+[Printer to print the match results]:PRINTER:(syntect bat)' \
    '--printer=[Printer to print the match results]:PRINTER:(syntect bat)' \
    '--term-width=[Width (number of characters) of terminal window]:NUM:_default' \
    '--wrap=[Text-wrapping mode. '\''char'\'' enables character-wise text-wrapping. '\''never'\'' disables text-wrapping]:MODE:(char never)' \
    '-E+[Specify the text encoding that hgrep will use on all files printed like '\''sjis'\'']:ENCODING:_default' \
    '--encoding=[Specify the text encoding that hgrep will use on all files printed like '\''sjis'\'']:ENCODING:_default' \
    '--generate-completion-script=[Print completion script for SHELL to stdout]:SHELL:(bash zsh powershell fish elvish nushell)' \
    '*--ignore-file=[Specify a path to one or more gitignore formatted rules files. These patterns are applied after the patterns found in .gitignore, .rgignore and .ignore are applied and are matched relative to the current working directory]:PATH:_default' \
    '*-g+[Include or exclude files and directories for searching that match the given glob]:GLOB:_default' \
    '*--glob=[Include or exclude files and directories for searching that match the given glob]:GLOB:_default' \
    '-m+[Limit the number of matching lines per file searched to NUM]:NUM:_default' \
    '--max-count=[Limit the number of matching lines per file searched to NUM]:NUM:_default' \
    '--max-depth=[Limit the depth of directory traversal to NUM levels beyond the paths given]:NUM:_default' \
    '*-t+[Only search files matching TYPE. This option is repeatable. --type-list can print the list of types]:TYPE:_default' \
    '*--type=[Only search files matching TYPE. This option is repeatable. --type-list can print the list of types]:TYPE:_default' \
    '*-T+[Do not search files matching TYPE. Inverse of --type. This option is repeatable. --type-list can print the list of types]:TYPE:_default' \
    '*--type-not=[Do not search files matching TYPE. Inverse of --type. This option is repeatable. --type-list can print the list of types]:TYPE:_default' \
    '--max-filesize=[Ignore files larger than NUM in size. This does not apply to directories.The input format accepts suffixes of K, M or G which correspond to kilobytes, megabytes and gigabytes, respectively. If no suffix is provided the input is treated as bytes]:NUM+SUFFIX?:_default' \
    '--regex-size-limit=[The upper size limit of the compiled regex. The default limit is 10M. For the size suffixes, see --max-filesize]:NUM+SUFFIX?:_default' \
    '--dfa-size-limit=[The upper size limit of the regex DFA. The default limit is 10M. For the size suffixes, see --max-filesize]:NUM+SUFFIX?:_default' \
    '-j+[The approximate number of threads to use. A The default value causes ripgrep to choose the thread count using heuristics]:NUM:_default' \
    '--threads=[The approximate number of threads to use. A The default value causes ripgrep to choose the thread count using heuristics]:NUM:_default' \
    '-G[Remove borderlines for more compact output]' \
    '--no-grid[Remove borderlines for more compact output]' \
    '--grid[Add borderlines to output. This flag is an opposite of --no-grid]' \
    '--list-themes[List all available theme names and their samples. Samples show the output where '\''let'\'' is searched. The names can be used at --theme option]' \
    '-f[Show only the first code snippet per file]' \
    '--first-only[Show only the first code snippet per file]' \
    '--generate-man-page[Print man page to stdout]' \
    '--custom-assets[Load bat'\''s custom assets. Note that this flag may not work with some version of \`bat\` command. This flag is only for bat printer]' \
    '--background[Paint background colors. This flag is only for syntect printer]' \
    '--no-ignore[Don'\''t respect ignore files (.gitignore, .ignore, etc.)]' \
    '-i[When this flag is provided, the given pattern will be searched case insensitively. This flag overrides --smart-case]' \
    '--ignore-case[When this flag is provided, the given pattern will be searched case insensitively. This flag overrides --smart-case]' \
    '-S[Search case insensitively if the pattern is all lowercase. Search case sensitively otherwise. This flag overrides --ignore-case]' \
    '--smart-case[Search case insensitively if the pattern is all lowercase. Search case sensitively otherwise. This flag overrides --ignore-case]' \
    '-.[Search hidden files and directories. By default, hidden files and directories are skipped]' \
    '--glob-case-insensitive[Process glob patterns given with the -g/--glob flag case insensitively]' \
    '--multiline-dotall[Enable "dot all" in your regex pattern, which causes '\''.'\'' to match newlines when multiline searching is enabled]' \
    '--crlf[When enabled, hgrep will treat CRLF ('\''\\r\\n'\'') as a line terminator instead of just '\''\\n'\''. This flag is useful on Windows]' \
    '--mmap[Search using memory maps when possible. mmap is disabled by default unlike ripgrep]' \
    '-x[Only show matches surrounded by line boundaries. This is equivalent to putting ^...\$ around the search pattern. This flag overrides --word-regexp]' \
    '--line-regexp[Only show matches surrounded by line boundaries. This is equivalent to putting ^...\$ around the search pattern. This flag overrides --word-regexp]' \
    '*-u[Reduce the level of "smart" filtering by repeated uses (up to 2). A single flag is equivalent to --no-ignore. Two flags are equivalent to --no-ignore --hidden. Unlike ripgrep, three flags are not supported since hgrep doesn'\''t support --binary flag]' \
    '*--unrestricted[Reduce the level of "smart" filtering by repeated uses (up to 2). A single flag is equivalent to --no-ignore. Two flags are equivalent to --no-ignore --hidden. Unlike ripgrep, three flags are not supported since hgrep doesn'\''t support --binary flag]' \
    '::PATTERN -- Pattern to search. Regular expression is available:_default' \
    '*::PATH -- Paths to search:_files' \
    && ret=0
}

(( $+functions[_foo_commands] )) \
  || _foo_commands() {
    local commands
    commands=()
    _describe -t commands 'foo commands' commands "$@"
  }

if [ "$funcstack[1]" = "_foo" ]; then
  _foo "$@"
else
  compdef _foo foo
fi
