#!/bin/bash

function cmd_ti_must()
{
	local ti_file="${1}"
	local ti_args="${2}"
	local cmd_mod_names="${3}"
	local cmd_hosts="${4}"
	local cmd_indexes="${5}"
	local mods="${6}"
	shift 6

	if [ -z "${1+x}" ] || [ -z "${1}" ]; then
		echo "[cmd must] usage: ti.sh [flags] ti_file_path must cmd [args]"
		exit 1
	fi

	local cmds_str=`esc_args "${@}"`

	for (( r = 0; 0 == 0; r++ )); do
		if [ -z "`echo ${cmds_str} | grep '":"'`" ]; then
			print_hhr
			echo ":: must ${r}> ${@}"
			print_hr
		fi
		local res=`"${integrated}/ops/ti.sh" -h "${cmd_hosts}" -m "${cmd_mod_names}" \
			-i "${cmd_indexes}" -k "${ti_args}" "${ti_file}" "${@}" 1>&2 && echo 'true'`
		if [ "${res}" == 'true' ]; then
			break
		fi
		sleep 0.1
	done
}

source "`cd $(dirname ${BASH_SOURCE[0]}) && pwd`/_env.sh"
cmd_ti_must "${@}"
