#!/bin/bash

########################################################################
#
#PROJECT:      Unified Sessions Manager
#AUTHOR:       Arno-Can Uestuensoez - acue@UnifiedSessionsManager.org
#MAINTAINER:   Arno-Can Uestuensoez - acue_sf1@sourceforge.net
#SHORT:        ctys
#CALLFULLNAME: Commutate To Your Session
#LICENCE:      GPL3
#VERSION:      01_02_007a17
#
########################################################################
#
# Copyright (C) 2007 Arno-Can Uestuensoez (UnifiedSessionsManager.org)
#
########################################################################

_myPKGNAME_CLI_INFO="${BASH_SOURCE}"
_myPKGVERS_CLI_INFO="01.02.001b01"
hookInfoAdd $_myPKGNAME_CLI_INFO $_myPKGVERS_CLI_INFO
_myPKGBASE_CLI_INFO="`dirname ${_myPKGNAME_CLI_INFO}`"

_CLI_INFO="${_myPKGNAME_CLI_INFO}"



#FUNCBEG###############################################################
#NAME:
#  infoCLI4Action
#
#TYPE:
#  bash-function
#
#DESCRIPTION:
#  Shows results for "-a INFO" on-screen-display
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
#  RETURN:
#
#  VALUES:
#
#FUNCEND###############################################################
function infoCLI4Action () {
    local _allign=$1

    printf "%"$((2*_allign))"s%-"${_label}"s %"$((2*_allign))"s\n" " " "CLI:" "Plugin Version:${_myPKGVERS_CLI}"
    printf "%"$((2*_allign))"s%-"${_label}"s %"$((2*_allign))"s\n" " " ""     "Operational State:${CLI_STATE}"

    if [ -n "${CLI_VERSTRING}" ];then
    printf "%"$((2*_allign))"s%-"${_label}"s %"$((2*_allign))"s\n" " " ""     "bash version:"
  	printf "%"$((2*_allign))"s%-"${_label}"s ->%"$((2*_allign))"s\n" " " " " "${CLI_VERSTRING}"
 	printf "%"$((3*_allign))"s%-"${_label}"s %"$((2*_allign))"s\n" " " " " "Magic-Number:${CLI_MAGIC}"
  	printf "%"$((3*_allign))"s%-"${_label}"s %"$((2*_allign))"s\n" " " " " "Verified Prerequisites:"
	local i2=;
	for i2 in ${CLI_PREREQ//,/ };do
  	    printf "%"$((3*_allign))"s%-"${_label}"s ->%s\n" " " " " "${i2}"
	done

    fi
    echo

    return
}


#FUNCBEG###############################################################
#NAME:
#  infoCLI4MACHINE
#
#TYPE:
#  bash-function
#
#DESCRIPTION:
#  Shows results of "-a INFO" for post-processing, therefor the plugin
#  has to be initialized completely to full init-level.
#
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
#  RETURN:
#    Returns relevant information for current plugin in terse format.
#
#    <type>;<plug-vers>;<plug-magic>;<plug-state>;<prereq-list>
#
#      <type>
#        Current type "CLI".
#
#      <plug-vers>
#        The version of current plugin, which is the value 
#        of _myPKGVERS_CLI.
#
#      <plug-magic>
#        The magic ID, which is the shortform of the version of 
#        current plugin stored in CLI_MAGIC.
#
#      <plug-state>
#        This field represents the current value of the operational 
#        state for the CLI plugin. The managed states are
#
#          DISABLED(0)
#          ENABLED(1)
#          BUSY(3)
#
#      <prereq-list>
#        Comma seperated list of all pathless or fully qualified 
#        executable names required for proper execution. These need not 
#        all to be mandatory, e.g. vmware of vmplayer will be decided 
#        generic. Same for dependency of WS6 on CLI.
#
#
#  VALUES:
#
#FUNCEND###############################################################
function infoCLI4MACHINE () {
    local _out=;
    _out="CLI"
    _out="${_out};${_myPKGVERS_CLI}"
    _out="${_out};${CLI_MAGIC}"
    _out="${_out};${CLI_STATE}"
    _out="${_out};${CLI_PREREQ}"
    echo "${_out}"
    return
}


#FUNCBEG###############################################################
#NAME:
#  infoCLI
#
#TYPE:
#  bash-function
#
#DESCRIPTION:
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
#  RETURN:
#
#  VALUES:
#
#FUNCEND###############################################################
function infoCLI () {
    local _arg1=$1

    case $_arg1 in
        [mM][aA][cC][hH][iI][nN][eE])
	    infoCLI4MACHINE $*
	    ;;
	[0-9]*)
            if [ -n "${CTRL_TERSE}" ];then
		infoCLI4MACHINE $*
	    else
		infoCLI4Action $*
	    fi
	    ;;
	*)
            ABORT=2;
            printERR $LINENO $BASH_SOURCE ${ABORT} "$FUNCNAME:Unknown parameter:"
            printERR $LINENO $BASH_SOURCE ${ABORT} "$FUNCNAME:   \$1=$1"
            printERR $LINENO $BASH_SOURCE ${ABORT} "$FUNCNAME:   \$*=$*"
            gotoHell ${ABORT};
	    ;;
    esac
}

