# SPDX-License-Identifier: Unlicense

complete -c s6 -f
set -l comp complete -c s6 -n __fish_use_subcommand

$comp -s v -d verbosity -r -a '0 1 2 3'
$comp -s s -r -F -d 'where s6-svscan is running'
$comp -s l -r -F -d 's6-rc live directory'
$comp -s r -r -F -d 's6-rc service set repository'
$comp -s c -r -F -d 'live database the system is booting o'

$comp -a help -d 'show help'
$comp -a version -d 'print the version of this package'
$comp -a system -d 'boot and shutdown the system'
$comp -a live -d 'start and stop services and their dependencies'
$comp -a process -d 'control individual long-running processes'
$comp -a set -d 'manipulate sets of services (offline, to later install them live)'
$comp -a repository -d 'manipulate the service repository itself'

$comp -a enable -d 's6 set enable'
$comp -a disable -d 's6 set disable'
$comp -a start -d 's6 live start'
$comp -a stop -d 's6 live stop'
$comp -a kill -d 's6 process kill'
$comp -a apply -d 's6 set apply'

complete -c s6 -n '__fish_seen_subcommand_from start stop' -a '(s6-rc-db (__fish_s6_livedir_arg) list all 2>/dev/null)'
complete -c s6 -n '__fish_seen_subcommand_from kill' -a '(s6-rc-db (__fish_s6_livedir_arg) list longruns 2>/dev/null)'

function __fish_s6_livedir_arg
    set -l tokens (commandline -xpc)
    set -e tokens[1]
    argparse -us 'l=' -- $tokens
    or return 0
    set -q _flag_l
    and echo -- -l$_flag_l
end
