diff --git a/Automation/Modules/Hello/Manuals/hello.asciidoc b/Automation/Modules/Hello/Manuals/hello.asciidoc index 37f32f6..3143a5c 100644 --- a/Automation/Modules/Hello/Manuals/hello.asciidoc +++ b/Automation/Modules/Hello/Manuals/hello.asciidoc @@ -9,7 +9,7 @@ hello - Print out greetings and exit successfully. Synopsis -------- -*centos-art hello [--help|--version|--debug|--greeting=TEXT|--lowercase|--uppercase]* +*centos-art hello [OPTIONS]* Description ----------- @@ -19,33 +19,53 @@ the ``Hello, World!'' greeting to standard output and exit successfully. You can use options to change the greeting message and the way it is printed out. The *hello* module provides a very simple example you can use as base to understand how modules work inside -*centos-art.sh* script and use that knowledge to start writing your -own modules for *centos-art.sh* script. +*centos-art.sh* script. You can this understanding to start writing +your own modules for *centos-art.sh* script. Options ------- The *hello* module accepts the following options: -*--help*:: +*-h | --help*:: Print out module's documentation. -*--version*:: +*-v | --version*:: Print out module's version and legal status. -*--debug*:: +*-d | --debug*:: Run the script in debugging mode. This option is very useful if - you want to get a closer look to the way modules are opened and - closed inside *centos-art.sh* script. - -*--greeting=TEXT*:: - Set a different greeting to be printed out. - -*--lowercase*:: - Print out the greeting in lowercase. - -*--uppercase*:: - Print out the greeting in uppercase. + you want to get a closer look to module environments being + executed and destroyed at run-time. + +*-g "TEXT" | --greeting="TEXT"*:: + Set a different greeting message to be printed out. This option + accepts a value as argument. The text you provide must not have + empty spaces on it. By default, when you don't provide this + option, *hello* module prints out ``Hello, World'' as greeting. If + translations of this message are available for your locale, they + will be printed instead. + +*-l | --lower*:: + Print greeting message in lowercase. The final output is printed + out all in one line. + +*-u | --upper*:: + Print greeting message in uppercase. The final output is printed + out all in one line. + +*-c | --camel*:: + Print greeting messages in camel-case (e.g., "HeLlO, WoRlD!"). + The output is printed out one character per line. This might not + have sense but it helps to describe how execution of sibling + modules work. Notice that, when printing final output, punctuation + marks doesn't count for formating. + +*-r | --random*:: + Print letters of a greeting message in a random order (e.g., + rdodldrl!,,!). The final output is printed out one character per + line. This might not have sense but it helps to describe how + recursive execution of sibling modules work. Exit Status ----------- diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Camel/camel.sh b/Automation/Modules/Hello/Modules/Output/Modules/Camel/camel.sh new file mode 100755 index 0000000..44997f6 --- /dev/null +++ b/Automation/Modules/Hello/Modules/Output/Modules/Camel/camel.sh @@ -0,0 +1,66 @@ +#!/bin/bash +###################################################################### +# +# camel.sh -- Print greeting messages in camel-case (e.g., "HeLlO, +# WoRlD!"). The output is printed out one character per line. This +# might not have sense but it helps to describe how execution of +# sibling modules work. Notice that, when printing final output, +# punctuation marks doesn't count for formating. +# +# Written by: +# * Alain Reguera Delgado , 2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function camel { + + local GREETING_CAMEL=1 + local GREETING_OFFSET=0 + local GREETING_CHARS=${#HELLO_WORLD} + local GREETING_MESSAGE=${HELLO_WORLD} + + while [[ ${GREETING_OFFSET} -lt ${GREETING_CHARS} ]]; do + + local HELLO_WORLD=${GREETING_MESSAGE:${GREETING_OFFSET}:1} + + if [[ ${GREETING_MESSAGE:${GREETING_OFFSET}:1} =~ '[[:alpha:]]' ]];then + + if [[ ${GREETING_CAMEL} -eq 1 ]];then + tcar_setModuleEnvironment -m 'upper' -t 'sibling' + GREETING_CAMEL=0 + else + tcar_setModuleEnvironment -m 'lower' -t 'sibling' + GREETING_CAMEL=1 + fi + + else + + if [[ ${GREETING_MESSAGE:${GREETING_OFFSET}:1} =~ ' ' ]];then + HELLO_WORLD='ยท' + fi + + tcar_printMessage "${HELLO_WORLD}" --as-stdout-line + + fi + + GREETING_OFFSET=$(( ${GREETING_OFFSET} + 1 )) + + done + +} diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Default/default.sh b/Automation/Modules/Hello/Modules/Output/Modules/Default/default.sh deleted file mode 100755 index db1e962..0000000 --- a/Automation/Modules/Hello/Modules/Output/Modules/Default/default.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -###################################################################### -# -# default.sh -- Print greetings as they come, without any -# modification. -# -# Written by: -# * Alain Reguera Delgado , 2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function default { - - tcar_printMessage "${HELLO_GREETING}" --as-stdout-line - -} diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Lower/lower.sh b/Automation/Modules/Hello/Modules/Output/Modules/Lower/lower.sh new file mode 100755 index 0000000..d1b82a9 --- /dev/null +++ b/Automation/Modules/Hello/Modules/Output/Modules/Lower/lower.sh @@ -0,0 +1,33 @@ +#!/bin/bash +###################################################################### +# +# lower.sh -- Print greeting message in lowercase. The final output +# is printed out all in one line. +# +# Written by: +# * Alain Reguera Delgado , 2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function lower { + + local GREETING=$(echo ${HELLO_WORLD} | tr '[[:upper:]]' '[[:lower:]]') + tcar_printMessage "${GREETING}" --as-stdout-line + +} diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Lowercase/lowercase.sh b/Automation/Modules/Hello/Modules/Output/Modules/Lowercase/lowercase.sh deleted file mode 100755 index 62fd435..0000000 --- a/Automation/Modules/Hello/Modules/Output/Modules/Lowercase/lowercase.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -###################################################################### -# -# lowercase.sh -- Print greetings in lowercase. -# -# Written by: -# * Alain Reguera Delgado , 2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function lowercase { - - HELLO_GREETING=$(echo ${HELLO_GREETING} | tr '[[:upper:]]' '[[:lower:]]') - - tcar_setModuleEnvironment -m 'default' -t 'sib-module' - -} diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Random/random.sh b/Automation/Modules/Hello/Modules/Output/Modules/Random/random.sh new file mode 100755 index 0000000..d63b2d7 --- /dev/null +++ b/Automation/Modules/Hello/Modules/Output/Modules/Random/random.sh @@ -0,0 +1,45 @@ +#!/bin/bash +###################################################################### +# +# random.sh -- Print letters of a greeting message in a random order +# (e.g., rdodldrl!,,!). The final output is printed out one +# character per line. This might not have sense but it helps to +# describe how recursive execution of sibling modules work. +# +# Written by: +# * Alain Reguera Delgado , 2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function random { + + local MESSAGE=${HELLO_WORLD} + local MAXCHAR=${#MESSAGE} + local COUNT=${1:-0} + local OFFSET=${RANDOM}; let "OFFSET %= ${MAXCHAR}" + + tcar_printMessage "${MESSAGE:${OFFSET}:1}" --as-stdout-line + + COUNT=$(( ${COUNT} + 1)) + + if [[ ${COUNT} -lt ${MAXCHAR} ]];then + tcar_setModuleEnvironment -m random -t sibling -g "${COUNT}" + fi + +} diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh b/Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh new file mode 100755 index 0000000..77e7c3e --- /dev/null +++ b/Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh @@ -0,0 +1,33 @@ +#!/bin/bash +###################################################################### +# +# upper.sh -- Print greeting message in uppercase. The final output +# is printed out all in one line. +# +# Written by: +# * Alain Reguera Delgado , 2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function upper { + + local GREETING=$(echo ${HELLO_WORLD} | tr '[[:lower:]]' '[[:upper:]]') + tcar_printMessage "${GREETING}" --as-stdout-line + +} diff --git a/Automation/Modules/Hello/Modules/Output/Modules/Uppercase/uppercase.sh b/Automation/Modules/Hello/Modules/Output/Modules/Uppercase/uppercase.sh deleted file mode 100755 index 7f4a37b..0000000 --- a/Automation/Modules/Hello/Modules/Output/Modules/Uppercase/uppercase.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -###################################################################### -# -# uppercase.sh -- Print greetings in uppercase. -# -# Written by: -# * Alain Reguera Delgado , 2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function uppercase { - - HELLO_GREETING=$(echo ${HELLO_GREETING} | tr '[[:lower:]]' '[[:upper:]]') - - tcar_setModuleEnvironment -m 'default' -t 'sib-module' - -} diff --git a/Automation/Modules/Hello/Modules/Output/output.sh b/Automation/Modules/Hello/Modules/Output/output.sh index e73ea12..247c783 100755 --- a/Automation/Modules/Hello/Modules/Output/output.sh +++ b/Automation/Modules/Hello/Modules/Output/output.sh @@ -1,7 +1,8 @@ #!/bin/bash ###################################################################### # -# output.sh -- Defines the way greetings are printed out. +# output.sh -- Selects how to output the greeting message, based on +# the options you provided in the command-line. # # Written by: # * Alain Reguera Delgado , 2013 @@ -26,10 +27,10 @@ function output { - local HELLO_ACTION='' + local ACTION='' - for HELLO_ACTION in ${HELLO_ACTIONS};do - tcar_setModuleEnvironment -m ${HELLO_ACTION} -t 'sub-module' + for ACTION in ${ACTIONS};do + tcar_setModuleEnvironment -m "${ACTION}" -t 'child' done } diff --git a/Automation/Modules/Hello/hello.sh b/Automation/Modules/Hello/hello.sh index 5a25e6f..dee253b 100755 --- a/Automation/Modules/Hello/hello.sh +++ b/Automation/Modules/Hello/hello.sh @@ -1,7 +1,7 @@ #!/bin/bash ###################################################################### # -# hello.sh -- Print greetings and exit successfully. +# hello.sh -- Print greeting messages and exit successfully. # # Written by: # * Alain Reguera Delgado , 2013 @@ -26,19 +26,23 @@ function hello { - # Define default message we want to print. - local HELLO_GREETING="`gettext "Hello, World!"`" + # Define default greeting message. + local HELLO_WORLD="`gettext "Hello, World!"`" # Define actions variable. Here is where actions related to - # module-specific options are stored in. - local HELLO_ACTIONS='' + # module-specific options are stored in for further processing. + local ACTIONS='' # Interpret module-specific options and store related actions. hello_getOptions - # Initiate actions sub-module. - if [[ -n ${HELLO_ACTIONS} ]];then - tcar_setModuleEnvironment -m 'output' -t 'sub-module' + # Print greeting message + if [[ -z ${ACTIONS} ]];then + # Using parent module. + tcar_printMessage "${HELLO_WORLD}" --as-stdout-line + else + # Using child module. + tcar_setModuleEnvironment -m 'output' -t 'child' fi } diff --git a/Automation/Modules/Hello/hello_getOptions.sh b/Automation/Modules/Hello/hello_getOptions.sh index 9808cad..503640c 100755 --- a/Automation/Modules/Hello/hello_getOptions.sh +++ b/Automation/Modules/Hello/hello_getOptions.sh @@ -1,7 +1,7 @@ #!/bin/bash ###################################################################### # -# hello_getOptions.sh -- Interpret hello module's specific options. +# hello_getOptions.sh -- Interpret module-specific options for hello. # # Written by: # * Alain Reguera Delgado , 2013 @@ -27,10 +27,10 @@ function hello_getOptions { # Define short options we want to support. - local ARGSS="" + local ARGSS="h::,v,g:,l,u,c,r" # Define long options we want to support. - local ARGSL="help::,version,greeting:,lowercase,uppercase" + local ARGSL="help::,version,greeting:,lower,upper,camel,random" # Redefine arguments using getopt(1) command parser. tcar_setModuleArguments @@ -43,26 +43,36 @@ function hello_getOptions { while true; do case "${1}" in - --help ) + -h | --help ) tcar_printHelp "${2}" ;; - --version ) + -v | --version ) tcar_printVersion "${TCAR_MODULE_NAME}" ;; - --greeting ) - HELLO_GREETING="${2:-${HELLO_GREETING}}" + -g | --greeting ) + HELLO_WORLD="${2:-${HELLO_WORLD}}" shift 2 ;; - --lowercase ) - HELLO_ACTIONS="lowercase ${HELLO_ACTIONS}" + -l | --lower ) + ACTIONS="lower ${ACTIONS}" shift 1 ;; - --uppercase ) - HELLO_ACTIONS="uppercase ${HELLO_ACTIONS}" + -u | --upper ) + ACTIONS="upper ${ACTIONS}" + shift 1 + ;; + + -c | --camel ) + ACTIONS="camel ${ACTIONS}" + shift 1 + ;; + + -r | --random ) + ACTIONS="random ${ACTIONS}" shift 1 ;; @@ -73,9 +83,6 @@ function hello_getOptions { esac done - # Define actions default value. - HELLO_ACTIONS=${HELLO_ACTIONS:-default} - # Redefine arguments using current positional parameters. Only # paths should remain as arguments, at this point. TCAR_MODULE_ARGUMENT="${@}"