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

Prints a list of containers in the order in which they are launched.
Use order=DESC to invert, it prins a list of jails 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 jorder
  # cbsd jorder order=DESC

${H3_COLOR}See also${N0_COLOR}:

  cbsd jorder-tui --help
  cbsd jconfig --help

"

. ${subrdir}/nc.subr
cixinit

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

_first=1
cbsdsqlquery local "SELECT jname FROM jails WHERE status<2 AND emulator = 'jail' 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 ""
