# SPDX-License-Identifier: Unlicense

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

$comp -s a -d 'add current set of active services to selection'
$comp -s b -d 'blocking lock'
$comp -s d -d 'bring services down'
$comp -s D -d 'force services down'
$comp -s e -d 'do not print essential services'
$comp -s l -r -F -d 'live dataspace path'
$comp -s n -r -f -d 'dry run'
$comp -s p -d prune
$comp -s t -r -d timeout
$comp -s u -d 'bring services up'
$comp -s v -d verbosity -r -a '0 1 2 3'

$comp -a help -d 'show help'
$comp -a list -d 'print current selection'
$comp -a listall -d 'print the dependency tree of the selection'
$comp -a diff -d 'check consistency between s6-rc and s6'
$comp -a start -d 'start a set of services'
$comp -a stop -d 'stop a set of services'
$comp -a change -d 'change service states'

complete -c s6-rc -n '__fish_seen_subcommand_from list listall start stop change' -a '(s6-rc-db (__fish_s6_livedir_arg) list all 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
