#!/usr/local/bin/cbsd
CBSDMODULE="bhyve"
CIXARG=""
CIXOPTARG="order"
MYDESC="List of the VM sorted by order"
EXTHELP="wf_border"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:

Prints a list of VMs in the order in which they are launched.
Use order=DESC to invert, it prins a list of VMs in the order to stop.

${H3_COLOR}Options${N0_COLOR}:

 ${N2_COLOR}order=${N0_COLOR}    - sort order: ASC (by default) or DESC.

${H3_COLOR}Examples${N0_COLOR}:

  # cbsd border
  # cbsd border order=DESC

${H3_COLOR}See also${N0_COLOR}:

  cbsd border-tui --help
  cbsd bconfig --help

"

. ${subrdir}/nc.subr
cixinit

[ -z "${order}" ] && order="ASC"

_first=1
cbsdsqlquery local "SELECT jname FROM jails WHERE status<2 AND emulator = 'bhyve' ORDER BY CAST(b_order AS int) ${order}" | while read q; do
	if [ ${_first} -eq 1 ]; then
		printf "${q@.jname}"
	else
		printf " ${q@.jname}"
	fi
	_first=0
done

err 0 ""
