#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: t; sh-basic-offset: 8; sh-indentation: 8; sh-indent-for-case-alt: + -*-
script_path=`dirname $0`
script_name=`basename $0`
pbench_bin="`cd ${script_path}/..; /bin/pwd`"

# source the base script
. "$pbench_bin"/base

# This script can list all tools from all groups,
# list tools from a specific group, or list which
# groups contain a specific tool

# Defaults
name=""
group=""
with_options=0

# Process options and arguments

opts=$(getopt -q -o to:g: --longoptions "group:" -n "getopt.sh" -- "$@");
if [ $? -ne 0 ]; then
	printf "\n"
	printf "$script_name: you specified an invalid option\n\n"
	printf "The following option is available: \n\n"
	printf -- "\t-g str --group=str, list the triggers used by this group\n"
	exit 1
fi
eval set -- "$opts";
while true; do
	case "$1" in
		-g|--group)
		shift;
		group="$1"
		shift;
		;;
		--)
		shift;
		break;
		;;
	esac
done
if [ -d "$pbench_run" ]; then
	pushd "$pbench_run" >/dev/null
	# list tool triggers in one or all groups
	if [ -z "$group" ]; then
		groups=`/bin/cat tool-triggers 2>/dev/null | grep -v '^#' | sed -e s/:.*//`
	else
		groups="$group"
	fi

	for grp in $groups ;do
		sed -n '/^'$grp'/p' tool-triggers
	done
	popd  >/dev/null
fi
