Blame Manuals/en/Texinfo/Repository/trunk/Scripts/Bash/Functions.texi

4c79b5
@subsection Goals
4c79b5
6c4982
The @file{trunk/Scripts/Bash/Functions} directory exists to organize
6c4982
@file{centos-art.sh} specific functionalities.
4c79b5
4c79b5
@subsection Description
4c79b5
6c4982
The specific functions of @file{centos-art.sh} script are designed
6c4982
with ``Software Toolbox'' philosophy (@pxref{Toolbox
6c4982
introduction,,,coreutils.info}) in mind: each program ``should do one
6c4982
thing well''.  Inside @file{centos-art.sh} script, each specific
6c4982
functionality is considered a program that should do one thing well.
6c4982
Of course, if you find that they still don't do it, feel free to
6c4982
improve them in order for them to do so.
6c4982
6c4982
The specific functions of @file{centos-art.sh} script are organized
6c4982
inside specific directories under @file{trunk/Scripts/Bash/Functions}
6c4982
location. Each specific function directory should be named as the
6c4982
function it represents, with the first letter in uppercase. For
41f1ec
example, if the function name is @code{render}, the specific function
6c4982
directory for it would be @samp{trunk/Scripts/Bash/Functions/Render}.
6c4982
6c4982
To better understand how specific functions of @file{centos-art.sh}
6c4982
script are designed, lets create one function which only goal is to
6c4982
output different kind of greetings to your screen.
6c4982
2bb528
When we create specific functions for @file{centos-art.sh} script it
2bb528
is crucial to know what these functions will do exactly and if there
2bb528
is any function that already does what we intend to do. If there is no
6c4982
one, it is good time to create them then. Otherwise, if
6c4982
functionalities already available don't do what you exactly expect,
6c4982
contact their authors and work together to improve them.
6c4982
6c4982
@quotation
be6bef
@strong{Tip} Join CentOS developers mailing list
2bb528
@email{centos-art@@centos.org} to share your ideas.
6c4982
@end quotation
6c4982
915635
It is also worth to know what global functions and variables do we
915635
have available inside @file{centos-art.sh} script, so advantage can be
915635
taken from them. Global variables are defined inside global function
915635
scripts. Global functions scripts are stored immediatly under
915635
@file{trunk/Scripts/Bash/Functions} directory, in files begining with
2bb528
@samp{cli} prefix.
6c4982
2bb528
OK, let's begin with our functionality example.
6c4982
be6bef
What function name do we use? Well, lets use @code{greet}. Note that
2bb528
@samp{hello} word is not a verb; but an expression, a kind of
2bb528
greeting, an interjection specifically. In contrast, @samp{greet} is a
2bb528
verb and describes what we do when we say @samp{Hello!}, @samp{Hi!},
2bb528
and similar expressions.
be6bef
6c4982
So far, we've gathered the following function information:
6c4982
6c4982
@verbatim
6c4982
Name: greet
6c4982
Path: trunk/Scripts/Bash/Functions/Greet
6c4982
File: trunk/Scripts/Bash/Functions/Greet/greet.sh
6c4982
@end verbatim
6c4982
41f1ec
The @file{greet.sh} function script is the first file
41f1ec
@file{centos-art.sh} script loads when the @samp{greet} functionality
41f1ec
is called using commands like @samp{centos-art greet --hello='World'}.
be6bef
The @file{greet.sh} function script contains the @code{greet} function
41f1ec
definition. 
41f1ec
2bb528
Inside @file{centos-art.sh} script, as convenction, each function
2bb528
script has one top commentary, followed by one blank line, and then
2bb528
one function defintion below it only.
6c4982
915635
Inside @file{centos-art.sh} script functions, top commentaries have
915635
the following components: the functionality description, one-line for
915635
copyright note with your personal information,  the license under
915635
which the function source code is released ---the @file{centos-art.sh}
915635
script is released as GPL, so do all its functions---, subversion's
915635
@code{$Id$} keyword which is later expanded by @command{svn propset}
915635
command.
41f1ec
2bb528
In our @code{greet} function example, top commentary for
2bb528
@file{greet.sh} function script would look like the following:
6c4982
6c4982
@verbatim
6c4982
#!/bin/bash
6c4982
#
6c4982
# greet.sh -- This function outputs different kind of greetings to
6c4982
# your screen. Use this function to understand how centos-art.sh
6c4982
# script specific functionalities work.
6c4982
#
be6bef
# Copyright (C) YEAR YOURFULLNAME
6c4982
#
6c4982
# This program is free software; you can redistribute it and/or modify
6c4982
# it under the terms of the GNU General Public License as published by
6c4982
# the Free Software Foundation; either version 2 of the License, or
6c4982
# (at your option) any later version.
6c4982
# 
6c4982
# This program is distributed in the hope that it will be useful, but
6c4982
# WITHOUT ANY WARRANTY; without even the implied warranty of
6c4982
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
6c4982
# General Public License for more details.
6c4982
#
6c4982
# You should have received a copy of the GNU General Public License
6c4982
# along with this program; if not, write to the Free Software
6c4982
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
6c4982
# USA.
6c4982
# 
6c4982
# ----------------------------------------------------------------------
be6bef
# $Id$
6c4982
# ----------------------------------------------------------------------
6c4982
@end verbatim
6c4982
2bb528
After top commentary, separated by one blank line, the @code{greet}
2bb528
function definition would look like the following:
6c4982
6c4982
@verbatim
6c4982
function greet {
6c4982
6c4982
    # Define global variables.
6c4982
6c4982
    # Define command-line interface.
6c4982
    greet_getActions
6c4982
6c4982
}
6c4982
@end verbatim
6c4982
41f1ec
The first definition inside @code{greet} function, are global
41f1ec
variables that will be available along @code{greet} function execution
41f1ec
environment. This time we didn't use global variable definitions for
41f1ec
@code{greet} function execution environment, so we left that section
41f1ec
empty.
6c4982
41f1ec
Later, we call @code{greet_getActions} function to define the
2bb528
command-line interface of @code{greet} functionality. The @code{greet}
2bb528
functionality command-line interface defines what and how actions are
2bb528
performed, based on arguments combination passed to
2bb528
@file{centos-art.sh} script.
6c4982
6c4982
@verbatim
6c4982
function greet_getActions {
6c4982
06717d
    case "$ACTIONNAM" in
6c4982
6c4982
        --hello )
6c4982
            greet_doHello
6c4982
            ;;
6c4982
6c4982
        --bye )
6c4982
            greet_doBye
6c4982
            ;;
6c4982
6c4982
        * )
6c4982
            cli_printMessage "`gettext "The option provided is not valid."`"
6c4982
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'
6c4982
6c4982
    esac
6c4982
6c4982
}
6c4982
@end verbatim
6c4982
06717d
The @var{ACTIONNAM} global variable is defined in @file{cli.sh}
41f1ec
function script and contains the value passed before the equal sign
41f1ec
(i.e., @samp{=}) in the second command-line argument of
41f1ec
@file{centos-art.sh} script. For example, if the second command-line
06717d
argument is @option{--hello='World'}, the value of @var{ACTIONNAM}
41f1ec
variable would be @samp{--hello}.  Using this configuration let us
e1a26a
deside which action to perform based on the action name passed to
41f1ec
@file{centos-art.sh} script as second argument. 
41f1ec
2bb528
The @code{greet} function definition makes available two valid
2bb528
greetings through @option{--hello} and @option{--bye} options.  If no
2bb528
one of them is provided as second command-line argument, the @samp{*}
2bb528
case is evaluated instead. 
41f1ec
f7b7e3
The @samp{*} case and its two lines further on should always be
f7b7e3
present in @file{_getActions.sh} function scripts, no matter what
f7b7e3
specific functionality you are creating. This convenction helps the
f7b7e3
user to find out documentation about current functionality in use.  
41f1ec
41f1ec
The @code{greet_doHello} and @code{greet_doBye} function definitions
41f1ec
are the core of @code{greet} specific functionality.  In such function
41f1ec
definitions we set what our @code{greet} function really does: to
41f1ec
output different kinds of greetings.
6c4982
6c4982
@verbatim
6c4982
function greet_doHello {
6c4982
06717d
    cli_printMessage "`gettext "Hello"` $ACTIONVAL"
6c4982
6c4982
}
6c4982
@end verbatim
6c4982
be6bef
The @code{greet_doHello} function definition is stored in
be6bef
@file{greet_doHello.sh} function script. 
be6bef
6c4982
@verbatim
6c4982
function greet_doBye {
6c4982
06717d
    cli_printMessage "`gettext "Goodbye"` $ACTIONVAL"
6c4982
6c4982
}
6c4982
@end verbatim
6c4982
be6bef
The @code{greet_doBye} function definition is stored in the
be6bef
@file{greet_doBye.sh} function script. 
be6bef
be6bef
Both @file{greet_doHello.sh} and @file{greet_doBye.sh} function
be6bef
scripts are stored inside @code{greet}'s function directory path (i.e.
be6bef
@file{trunk/Scripts/Bash/Functions/Greet}).
be6bef
06717d
The @var{ACTIONVAL} global variable is defined in @file{cli.sh}
41f1ec
function script and contains the value passed after the equal sign
41f1ec
(i.e., @samp{=}) in the second command-line argument of
41f1ec
@file{centos-art.sh} script. For example, if the second command-line
06717d
argument is @option{--hello='World'}, the value of @var{ACTIONVAL}
41f1ec
variable would be @samp{World} without quotes.
6c4982
be6bef
Let's see how @code{greet} specific functionality files are organzied
41f1ec
under @code{greet}'s function directory. To see file organization we
be6bef
use the @command{tree} command:
6c4982
6c4982
@verbatim
6c4982
trunk/Scripts/Bash/Functions/Greet
6c4982
|-- greet_doBye.sh
6c4982
|-- greet_doHello.sh
6c4982
|-- greet_getActions.sh
6c4982
`-- greet.sh
6c4982
@end verbatim
6c4982
2bb528
To try the @code{greet} specific functionality we've just created,
2bb528
pass the function name (i.e., @samp{greet}) as first argument to
2bb528
@file{centos-art.sh} script, and any of the valid options as second
2bb528
argument. Some examples are illustrated below:
6c4982
6c4982
@verbatim
6c4982
[centos@projects ~]$ centos-art greet --hello='World'
6c4982
Hello World
6c4982
[centos@projects ~]$ centos-art greet --bye='World'
6c4982
Goodbye World
6c4982
[centos@projects ~]$ 
6c4982
@end verbatim
6c4982
41f1ec
The word @samp{World} in the examples above can be anything. In fact,
41f1ec
change it to have a little fun.
be6bef
be6bef
Now that we have a specific function that works as we expect, it is
be6bef
time to document it. To document @code{greet} specific functionality,
831389
we use its directory path and the @code{manual} functionality
035049
(@pxref{trunk Scripts Bash Functions Manual}) of @file{centos-art.sh}
831389
script, just as the following command illustrates: 
be6bef
be6bef
@verbatim
f7b7e3
centos-art manual --edit=trunk/Scripts/Bash/Functions/Greet
be6bef
@end verbatim
be6bef
41f1ec
Now that we have documented our function, it is time to translate its
41f1ec
output messages to different languages. To translate specific
41f1ec
functionality output messages to different languages we use the
41f1ec
@code{locale} functionality (@pxref{trunk Scripts Bash Functions
41f1ec
Locale}) of @file{centos-art.sh} script, just as the following command
41f1ec
illustrates:
41f1ec
41f1ec
@verbatim
41f1ec
centos-art locale --edit
41f1ec
@end verbatim
41f1ec
41f1ec
@quotation
41f1ec
@strong{Warning} To translate output messages in different languages,
41f1ec
your system locale information ---as in @env{LANG} environment
41f1ec
variable--- must be set to that locale you want to produce translated
41f1ec
messages for. For example, if you want to produce translated messages
41f1ec
for Spanish language, your system locale information must be set to
41f1ec
@samp{es_ES.UTF-8} or similar.  
41f1ec
@end quotation
41f1ec
be6bef
Well, it seems that our example is rather complete by now. 
6c4982
41f1ec
In @code{greet} function example we've described so far, we only use
41f1ec
@command{cli_printMessage} global function in action specific function
41f1ec
definitions in order to print a message simply, but more interesting
41f1ec
things can be achieved inside action specific function definitions.
6c4982
For example, if you pass a directory path as second argument option
6c4982
value, you could retrive a list of files from therein, and process
2bb528
them. If the list of files turns too long or you just want to control
2bb528
which files to process, you could add the third argument in the form
2bb528
@option{--filter='regex'} and reduce the amount of files to process
2bb528
using a regular expression pattern.
6c4982
2bb528
The @code{greet} function described in this section may serve you as
2bb528
an introduction to understand how specific functionalities work inside
2bb528
@file{centos-art.sh} script. With some of luck this introduction will
2bb528
also serve you as motivation to create your own @file{centos-art.sh}
2bb528
script specific functionalities.
6c4982
be6bef
By the way, the @code{greet} functionality doesn't exist inside
41f1ec
@file{centos-art.sh} script yet. Would you like to create it?
6c4982
6c4982
@subsection Usage
6c4982
6c4982
@subsubsection Global variables
6c4982
6c4982
The following global variables of @file{centos-art.sh} script, are
6c4982
available for you to use inside specific functions:
6c4982
be6bef
@defvar TEXTDOMAIN
6c4982
Default domain used to retrieve translated messages. This value is set
2bb528
in @file{initFunctions.sh} and shouldn't be changed.
be6bef
@end defvar
6c4982
be6bef
@defvar TEXTDOMAINDIR
6c4982
Default directory used to retrieve translated messages. This value is
2bb528
set in @file{initFunctions.sh} and shouldn't be changed.
be6bef
@end defvar
6c4982
06717d
@defvar FUNCNAM
e1a26a
Define function name.
e1a26a
e1a26a
Function names associate sets of actions. There is one set of actions
e1a26a
for each unique function name inside @file{centos-art.sh} script.
e1a26a
e1a26a
Dunction names are passed as first argument in @file{centos-art.sh}
2bb528
command-line interface. For example, in the command @samp{centos-art
2bb528
render --entry=path/to/dir --filter=regex}, the @var{ACTION} passed to
2bb528
@file{centos-art.sh} script is @option{render}.
e1a26a
e1a26a
When first argument is not provided, the @file{centos-art.sh} script
e1a26a
immediatly ends its execution.
be6bef
@end defvar
6c4982
06717d
@defvar ACTIONNAM
e1a26a
Define action name.
e1a26a
e1a26a
Each action name identifies an specific action to perform, inside an
e1a26a
specific function.
e1a26a
e1a26a
Action name names aare passed as second argument in
e1a26a
@file{centos-art.sh} command-line interface. For example, in the
e1a26a
command @samp{centos-art render --entry=path/to/dir --filter=regex},
e1a26a
the @var{ACTIONNAM} passed to @file{centos-art.sh} script is
e1a26a
@option{--entry}.
e1a26a
e1a26a
When second argument is not provided, the @file{centos-art.sh} script
e1a26a
immediatly ends its execution.
be6bef
@end defvar
6c4982
06717d
@defvar ACTIONVAL
e1a26a
Define action value.
e1a26a
e1a26a
Action values are associated to just one action name. Action values
e1a26a
contain the repository entry over which its associated action will be
e1a26a
performed in.  Repository entries can be directories, files, or URLs
e1a26a
refering the repository structure.
e1a26a
e1a26a
When action value is not specified as repository entry, the
e1a26a
@file{centos-art.sh} script evaluates the current directory it was
e1a26a
executed from. If such directory is under the repository structure
e1a26a
(i.e., @file{/home/centos/artwork/}), the @file{centos-art.sh} script
e1a26a
uses that directory as value to @var{ACTIONVAL} variable. Otherwise,
e1a26a
if outside the repository structure, the @file{centos-art.sh} script
e1a26a
prints the message @samp{The path provided can't be processed.} and,
e1a26a
after it, immediatly ends script execution.
e1a26a
e1a26a
Default action value is passed as second argument in
e1a26a
@file{centos-art.sh} command-line interface. For example, in the
e1a26a
command @samp{centos-art render --entry=path/to/dir --filter=regex},
e1a26a
the @var{ACTIONVAL} passed to @file{centos-art.sh} script is
e1a26a
@option{path/to/dir}.
be6bef
@end defvar
6c4982
be6bef
@defvar REGEX
e1a26a
Define regular expression used as pattern to build the list of files
e1a26a
to process.
2bb528
e1a26a
By default, @var{REGEX} variable is set to @code{.+} to match all
e1a26a
files.
2bb528
e1a26a
Functions that need to build a list of files to process use the option
e1a26a
@option{--filter} to redefine @var{REGEX} variable default value, and
e1a26a
so, control the amount of files to process.
be6bef
@end defvar
6c4982
97552b
@defvar ARGUMENTS 
97552b
Define optional arguments. 
97552b
008ee0
Optional arguments, inside @file{centos-art.sh} script, are considered
008ee0
as all command-line arguments passed to @file{centos-art.sh} script,
008ee0
from third argument position on. For example, in the command
008ee0
@samp{centos-art render --entry=path/to/dir --filter=regex} , the
008ee0
optional arguments are from @samp{--filter=regex} argument on.
008ee0
008ee0
Optional arguments are parsed using @command{getopt} command through
008ee0
the following base construction: 
008ee0
008ee0
@verbatim
008ee0
# Define short options we want to support.
008ee0
local ARGSS=""
008ee0
008ee0
# Define long options we want to support.
008ee0
local ARGSL="filter:,to:"
008ee0
008ee0
# Parse arguments using getopt(1) command parser.
008ee0
cli_doParseArguments
008ee0
008ee0
# Reset positional parameters using output from (getopt) argument
008ee0
# parser.
008ee0
eval set -- "$ARGUMENTS"
008ee0
008ee0
# Define action to take for each option passed.
008ee0
while true; do
008ee0
    case "$1" in
008ee0
        --filter )
008ee0
            REGEX="$2" 
008ee0
            shift 2
008ee0
            ;;
008ee0
        --to )
008ee0
            TARGET="$2" 
008ee0
            shift 2
008ee0
            ;;
008ee0
        * )
008ee0
            break
008ee0
    esac
008ee0
done
008ee0
@end verbatim
008ee0
008ee0
Optional arguments provide support to command options inside
008ee0
@file{centos-art.sh} script. For instance, consider the Subversion
008ee0
(@command{svn}) command, where there are many options (e.g.,
008ee0
@option{copy}, @option{delete}, @option{move}, etc), and inside each
008ee0
option there are several modifiers (e.g., @samp{--revision},
008ee0
@samp{--message}, @samp{--username}, etc.) that can be combined one
008ee0
another in their short or long variants. 
008ee0
008ee0
The @var{ARGUMENTS} variable is used to store arguments passed from
008ee0
command-line for later use inside @file{centos-art.sh} script. Storing
008ee0
arguments is specially useful when we want to run a command with some
008ee0
specific options from them. Consider the following command:
008ee0
008ee0
@verbatim
008ee0
centos-art path --copy=SOURCE --to=TARGET --message="The commit message goes here." --username='johndoe'
008ee0
@end verbatim
008ee0
008ee0
In the above command, the @option{--message}, and @option{--username}
008ee0
options are specific to @command{svn copy} command. In such cases,
008ee0
options are not interpreted by @file{centos-art.sh} script itself.
008ee0
Instead, the @file{centos-art.sh} script uses @command{getopt} to
008ee0
retrive them and stores them in the @var{ARGUMENT} variable for later
008ee0
use, as described in the following command:
008ee0
008ee0
@verbatim
008ee0
# Build subversion command to duplicate locations inside the
008ee0
# workstation.
008ee0
eval svn copy $SOURCE $TARGET --quiet $ARGUMENTS
008ee0
@end verbatim
008ee0
008ee0
When @command{getopt} parses @var{ARGUMENTS}, we may use short options
008ee0
(e.g., @option{-m}) or long options (e.g., @option{--message}). When
008ee0
we use short options, arguments are separated by one space from the
008ee0
option (e.g., @option{-m 'This is a commit message.'}).  When we use
008ee0
long options arguments are separated by an equal sign (@samp{=})
008ee0
(e.g., @option{--message='This is a commit message'}).
008ee0
008ee0
In order for @command{getopt} to parse @var{ARGUMENTS} correctly, it
008ee0
is required to provide the short and long definition of options that
008ee0
will be passed or at least supported by the command performing the
008ee0
final action the function script exists for.
008ee0
008ee0
As convenction, inside @file{centos-art.sh} script, short option
008ee0
definitions are set in the @var{ARGSS} variable; and long option
008ee0
definitions are set in the @var{ARGSL} variable.
008ee0
008ee0
When you define short and long options, it may be needed to define
008ee0
which of these option arguments are required and which not. To define
008ee0
an option argument as required, you need to set one colon @samp{:}
008ee0
after the option definition (e.g., @option{-o m: -l message:}).  On
008ee0
the other hand, to define an option argument as not required, you need
008ee0
to set two colons @samp{::} after the option definition (e.g.,
008ee0
@option{-o m:: -l message::}).
97552b
@end defvar
97552b
be6bef
@defvar EDITOR 
2bb528
Default text editor. 
2bb528
2bb528
The @file{centos-art.sh} script uses default text @env{EDITOR} to edit
2bb528
pre-commit subversion messages, translation files, configuration
2bb528
files, script files, and similar text-based files.
2bb528
2bb528
If @env{EDITOR} environment variable is not set, @file{centos-art.sh}
2bb528
script uses @file{/usr/bin/vim} as default text editor. Otherwise, the
2bb528
following values are recognized by @file{centos-art.sh} script:
6c4982
4c79b5
@itemize
2bb528
@item @file{/usr/bin/vim}
2bb528
@item @file{/usr/bin/emacs}
2bb528
@item @file{/usr/bin/nano}
4c79b5
@end itemize
2bb528
2bb528
If no one of these values is set in @env{EDITOR} environment variable,
2bb528
@file{centos-art.sh} uses @file{/usr/bin/vim} text editor by default. 
be6bef
@end defvar
6c4982
f7b7e3
@subsubsection Functions
6c4982
f7b7e3
Functions defined under @file{trunk/Scripts/Bash/Functions/} directory
f7b7e3
are considered global. Global function can be used inside action
f7b7e3
specific functionalities and reused inside themselves. This section
f7b7e3
provides introductory information to global functions you can use
f7b7e3
inside @file{centos-art.sh} script.
6c4982
97552b
@defun cli_commitRepoChanges [LOCATION]
06717d
06717d
Syncronize changes between repository and working copy.
06048d
06048d
The @code{cli_commitRepoChanges} function brings changes from the
f7b7e3
central repository down to the working copy---using @command{svn
f7b7e3
update}---, checks the working copy changes---using @command{svn
f7b7e3
status} command---, prints status report---using both @command{svn
f7b7e3
update} and @command{svn status} commands output, and finally, commits
f7b7e3
recent changes from the working copy up to the repository---using
e1a26a
@command{svn commit} command---.
06048d
f7b7e3
Previous to commit the working copy changes up to the central
f7b7e3
repository, the @code{cli_commitRepoChanges} function asks you to
f7b7e3
verify changes---using @command{svn diff} command---, and later,
f7b7e3
another confirmation question is shown to be sure you really want to
f7b7e3
commit changes up to central repository.
f7b7e3
f7b7e3
If @var{LOCATION} argument is not specified, the value of
f7b7e3
@var{ACTIONVAL} variable is used as reference instead.
06717d
06717d
@float Figure, trunk/Scripts/Bash/Functions/cli_commitRepoChanges
06717d
@verbatim
06717d
----------------------------------------------------------------------
06717d
--> Bringing changes from the repository into the working copy
06717d
--> Checking changes in the working copy
06717d
----------------------------------------------------------------------
06717d
Added           0 file from the repository.
06717d
Deleted         0 file from the repository.
06717d
Updated         0 file from the repository.
06717d
Conflicted      0 file from the repository.
06717d
Merged          0 file from the repository.
06717d
Modified        4 files from the working copy.
06717d
Unversioned     0 file from the working copy.
06717d
Deleted         0 file from the working copy.
06717d
Added           0 file from the working copy.
06717d
----------------------------------------------------------------------
06717d
@end verbatim
06717d
@caption{The @code{cli_commitRepoChanges} function output.}
06717d
@end float
06048d
06717d
Call the @code{cli_commitRepoChanges} function before or/and after
f7b7e3
calling functions that modify files or directories inside the working
f7b7e3
copy as you may need to.  
be6bef
@end defun
be6bef
2bb528
@defun cli_checkFiles FILE [TYPE]
915635
Verify files existence.
be6bef
2bb528
@code{cli_checkFiles} receives a @var{FILE} absolute path and performs
2bb528
file verification as specified in @var{TYPE}.  When @var{TYPE} is not
2bb528
specified, @code{cli_checkFiles} verifies @var{FILE} existence, no
2bb528
matter what kind of file it be.  If @var{TYPE} is specified, use one
2bb528
of the following values:
be6bef
be6bef
@table @option
be6bef
@item d
be6bef
@itemx directory
2bb528
Ends script execution if @var{FILE} is not a directory.
2bb528
2bb528
When you verify directories with cli_checkFiles, if directory doesn't
2bb528
exist, @file{centos-art.sh} script asks you for confirmation in order
2bb528
to create that directory. If you answer positively,
2bb528
@file{centos-art.sh} script creates that directory and continues
2bb528
script flows normally. Otherwise, if you answer negatively,
2bb528
@file{centos-art.sh} ends script execution with an error and
2bb528
documentation message.
2bb528
be6bef
@item f
be6bef
@item regular-file
2bb528
Ends script execution if @var{FILE} is not a regular file.
be6bef
@item h
be6bef
@itemx symbolic-link
2bb528
Ends script execution if @var{FILE} is not a symbolic link.
2bb528
@item x
2bb528
@itemx execution
2bb528
Ends script execution if @var{FILE} is not executable.
be6bef
@item fh
f7b7e3
Ends script execution if @var{FILE} is neither a regular file nor a
2bb528
symbolic link.
f7b7e3
@item fd
f7b7e3
Ends script execution if @var{FILE} is neither a regular file nor a
f7b7e3
directory.
be6bef
@end table
6c4982
2bb528
As default behaviour, if @var{FILE} passes all verifications,
2bb528
@file{centos-art.sh} script continues with its normal flow. 
be6bef
@end defun
be6bef
be6bef
@defun cli_getCountryCodes [FILTER]
f7b7e3
Output country codes supported by @file{centos-art.sh} script. 
2bb528
2bb528
The @code{cli_getCountryCodes} function outputs a list with country
2bb528
codes as defined in ISO3166 standard. When @var{FILTER} is provided,
41f1ec
@code{cli_getCountryCodes} outputs country codes that match
be6bef
@var{FILTER} regular expression pattern.
be6bef
@end defun
be6bef
2bb528
@defun cli_getCountryName [FILTER]
f7b7e3
Outputs country name supported by @file{centos-art.sh} script.
2bb528
2bb528
The @code{cli_getCountryName} function reads one language locale code
2bb528
in the format LL_CC and outputs the name of its related country as in
2bb528
ISO3166. If filter is specified, @code{cli_getCountryName} returns the
2bb528
country name that matches the locale code specified in @var{FILTER},
2bb528
exactly.
be6bef
@end defun
6c4982
 
be6bef
@defun cli_getCurrentLocale
2bb528
Output current locale used by @file{centos-art.sh} script. 
2bb528
2bb528
The @code{cli_getCurrentLocale} function uses @env{LANG} environment
41f1ec
variable to build a locale pattern that is later applied to
41f1ec
@code{cli_getLocales} function output in order to return the current
41f1ec
locale that @file{centos-art.sh} script works with. 
41f1ec
41f1ec
The current locale information, returned by
41f1ec
@code{cli_getCurrentLocale}, is output from more specific to less
41f1ec
specific. For example, if @samp{en_GB} locale exists in
41f1ec
@code{cli_getLocales} function output, the @samp{en_GB} locale would
41f1ec
take precedence before @samp{en} locale.
41f1ec
41f1ec
Locale precedence selection is quite important in order to define the
41f1ec
locale type we use for message translations. For example, if
f7b7e3
@samp{en_GB} is used, we are also saying that the common language
f7b7e3
specification for English language (i.e., @samp{en}) is no longer
f7b7e3
used. Instead, we are using English non-common country-specific
f7b7e3
language specifications like @samp{en_AU}, @samp{en_BW}, @samp{en_GB},
41f1ec
@samp{en_US}, etc., for message translations.  
41f1ec
41f1ec
Use @code{cli_getCurrentLocale} function to know what current locale
41f1ec
information to use inside @file{centos-art.sh} script.
be6bef
@end defun
be6bef
be6bef
@defun cli_getLangCodes [FILTER]
f7b7e3
Outputs language codes supported by @file{centos-art.sh} script.
2bb528
be6bef
@code{cli_getLangCodes} function outputs a list of language codes as
be6bef
defined in ISO639 standard. When @var{FILTER} is provided,
be6bef
@code{cli_getLangCodes} outputs language codes that match @var{FILTER}
be6bef
regular expression pattern.
be6bef
@end defun
be6bef
41f1ec
@defun cli_getLangName [FILTER]
f7b7e3
Outputs language names supported by @file{centos-art.sh} script.
2bb528
41f1ec
@code{cli_getLangName} function reads one language locale code in the
2bb528
format LL_CC and outputs the language related name as in ISO639. If
2bb528
filter is specified, @code{cli_getLangName} returns the language name
2bb528
that matches the locale code specified in @var{FILTER}, exactly.
be6bef
@end defun
be6bef
be6bef
@defun cli_getLocales
2bb528
Output locale codes supported by @file{centos-art.sh} script.
41f1ec
41f1ec
Occasionally, you use @code{cli_getLocales} function to add locale
41f1ec
information in non-common country-specific language (@samp{LL_CC})
41f1ec
format for those languages (e.g., @samp{bn_IN}, @samp{pt_BR}, etc.)
41f1ec
which locale differences cannot be solved using common language
41f1ec
specifications (@samp{LL}) into one unique common locale specification
41f1ec
(e.g., @samp{bn}, @samp{pt}, etc.).  
be6bef
@end defun
be6bef
41f1ec
@defun cli_getRepoName NAME TYPE
2bb528
Sanitate file names.
2bb528
2bb528
Inside @file{centos-art.sh} script, specific functionalities rely both
2bb528
in @code{cli_getRepoName} and repository file system organization to
2bb528
achieve their goals.  Consider @code{cli_getRepoName} function as
2bb528
central place to manage file name convenctions for other functions
2bb528
inside @file{centos-art.sh} script.
41f1ec
41f1ec
@quotation
915635
@strong{Important} @code{cli_getRepoName} function doesn't verify file
41f1ec
or directory existence, for that purpose use @code{cli_checkFiles}
41f1ec
function instead.
41f1ec
@end quotation
41f1ec
41f1ec
The @var{NAME} variable contains the file name or directory name you
41f1ec
want to sanitate.
41f1ec
f7b7e3
The @var{TYPE} variable specifies what type of sanitation you want to
f7b7e3
perform on @var{NAME}. The @var{TYPE} can be one of the following
f7b7e3
values:
f7b7e3
41f1ec
@table @option
41f1ec
@item d
41f1ec
@itemx directory
41f1ec
Sanitate directory @var{NAME}s.
41f1ec
@item f
41f1ec
@item regular-file
41f1ec
Sanitate regular file @var{NAME}s.
41f1ec
@end table
41f1ec
41f1ec
Use @code{cli_getRepoName} function to sanitate file names and
41f1ec
directory names before their utilization. 
41f1ec
41f1ec
Use @code{cli_getRepoName} when you need to change file name
2bb528
convenctions inside @file{centos-art.sh} script. 
2bb528
2bb528
When changing file name convenctions inside @code{cli_getRepoName}
2bb528
what you are really changing is the way functions interpret repository
2bb528
file system organization. In order to a complete file name convenction
2bb528
change, you also need to change file names and directory names inside
2bb528
repository file system organization, just as you did in
2bb528
@code{cli_getRepoName} function. 
41f1ec
41f1ec
@quotation
41f1ec
@strong{Note} @xref{trunk Scripts Bash Functions Path}, for more
41f1ec
information on how to rename files and directories massively inside
41f1ec
repository file system organization.
41f1ec
@end quotation
be6bef
@end defun
be6bef
915635
@defun cli_getTemporalFile @var{NAME}
915635
Output absolute path to temporal file @var{NAME}.
915635
915635
@code{cli_getTemporalFile} uses @file{/tmp} directory as source
915635
location to store temporal files, the @file{centos-art.sh} script
915635
name, and a random identification string to let you run more than one
915635
@file{centos-art.sh} script simultaneously on the same user session.
915635
For example, due the following temporal file defintion:
915635
915635
@verbatim
915635
cli_getTemporalFile $FILE
915635
@end verbatim
915635
915635
If @var{FILE} name is @file{instance.svg} and unique random string is
915635
@samp{f16f7b51-ac12-4b7f-9e66-72df847f12de}, the final temporal file,
915635
built from previous temporal file definition, would be:
915635
915635
@verbatim
915635
/tmp/centos-art.sh-f16f7b51-ac12-4b7f-9e66-72df847f12de-instance.svg
915635
@end verbatim
915635
915635
When you use @code{cli_getTemporalFile} function to create temporal
915635
files, be sure to remove temporal files created once you've ended up
915635
with them.  For example, consider the following construction:
915635
915635
@verbatim
915635
for FILE in $FILES;do
915635
915635
    # Initialize temporal instance of file.
915635
    INSTANCE=$(cli_getTemporalFile $FILE)
915635
915635
    # Do something ... 
915635
915635
    # Remove temporal instance of file.
915635
    if [[ -f $INSTANCE ]];then
915635
        rm $INSTANCE
915635
    fi
915635
915635
done
915635
@end verbatim
915635
915635
Use @code{cli_getTemporalFile} function whenever you need to create
915635
temporal files inside @file{centos-art.sh} script.
915635
@end defun
915635
be6bef
@defun cli_getThemeName
2bb528
Output theme name.
2bb528
2bb528
In order for @code{cli_getThemeName} function to extract theme name
06717d
correctly, the @var{ACTIONVAL} variable must contain a directory path
2bb528
under @file{trunk/Identity/Themes/Motifs/} directory structure.
2bb528
Otherwise, @code{cli_getThemeName} returns an empty string.  
be6bef
@end defun
be6bef
be6bef
@defun cli_printMessage MESSAGE [FORMAT]
2bb528
Give format to output messages.
be6bef
be6bef
When @var{FORMAT} is not specified, @code{cli_printMessage} outputs
be6bef
information just as it was passed in @var{MESSAGE} variable.
be6bef
Otherwise, @var{FORMAT} can take one of the following values:
be6bef
be6bef
@table @option
be6bef
@item AsHeadingLine
2bb528
To print heading messages.
be6bef
@verbatim
be6bef
----------------------------------------------------------------------
be6bef
$MESSAGE
be6bef
----------------------------------------------------------------------
be6bef
@end verbatim
be6bef
be6bef
@item AsWarningLine
2bb528
To print warning messages.
be6bef
@verbatim
be6bef
----------------------------------------------------------------------
be6bef
WARNING: $MESSAGE
be6bef
----------------------------------------------------------------------
be6bef
@end verbatim
be6bef
be6bef
@item AsNoteLine
2bb528
To print note messages.
be6bef
@verbatim
be6bef
----------------------------------------------------------------------
be6bef
NOTE: $MESSAGE
be6bef
----------------------------------------------------------------------
be6bef
@end verbatim
be6bef
be6bef
@item AsUpdatingLine
2bb528
To print @samp{Updating} messages using two-columns format.
be6bef
@verbatim
be6bef
Updating        $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsRemovingLine
2bb528
To print @samp{Removing} messages using two-columns format.
be6bef
@verbatim
be6bef
Removing        $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsCheckingLine
2bb528
To print @samp{Checking} messages using two-columns format.
be6bef
@verbatim
be6bef
Checking        $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsCreatingLine
2bb528
To print @samp{Creating} messages using two-columns format.
be6bef
@verbatim
be6bef
Creating        $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsSavedAsLine
2bb528
To print @samp{Saved as} messages using two-columns format.
be6bef
@verbatim
be6bef
Saved as        $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsLinkToLine
2bb528
To print @samp{Linked to} messages using two-columns format.
be6bef
@verbatim
be6bef
Linked to       $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsMovedToLine
2bb528
To print @samp{Moved to} messages using two-columns format.
be6bef
@verbatim
be6bef
Moved to        $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsTranslationLine
2bb528
To print @samp{Translation} messages using two-columns format.
be6bef
@verbatim
be6bef
Translation     $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsConfigurationLine
2bb528
To print @samp{Configuration} messages using two-columns format.
be6bef
@verbatim
be6bef
Configuration   $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsResponseLine
2bb528
To print response messages using one-column format.
be6bef
@verbatim
be6bef
--> $MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsRequestLine
2bb528
To print request messages using one-column format. Request messages
2bb528
supress the trailing newline character from final output.
be6bef
@verbatim
be6bef
$MESSAGE
be6bef
@end verbatim
be6bef
be6bef
@item AsYesOrNoRequestLine
2bb528
To print @samp{yes or no} request messages using one-column format. If
2bb528
something different from @samp{y} is answered (when using
be6bef
@code{en_US.UTF-8} locale), script execution ends immediatly.  
be6bef
be6bef
@verbatim
be6bef
$MESSAGE [y/N]:
be6bef
@end verbatim
be6bef
be6bef
When you are using @file{centos-art.sh} script in a locale different
be6bef
from @code{en_US.UTF-8}, confirmation answer may be different from
be6bef
@samp{y}. For example, if you are using @code{es_ES.UTF-8} locale, the
be6bef
confirmation question would look like:
be6bef
be6bef
@verbatim
be6bef
$MESSAGE [s/N]:
be6bef
@end verbatim
be6bef
be6bef
and the confirmation answer would be @samp{s}, as it is on Spanish
be6bef
@samp{sí} word.
be6bef
be6bef
Definition of which confirmation word to use is set on translation
be6bef
messages for your specific locale information. @xref{trunk Scripts
be6bef
Bash Functions Locale}, for more information about locale-specific
be6bef
translation messages.
be6bef
be6bef
@item AsToKnowMoreLine
be6bef
To standardize @samp{to know more, run the following command:}
be6bef
messages. When the @option{AsToKnowMoreLine} option is used, the
be6bef
@var{MESSAGE} value should be set to @code{"$(caller)"}. @code{caller}
be6bef
is a Bash builtin that returns the context of the current subroutine
be6bef
call. @option{AsToKnowMoreLine} option uses @code{caller} builtin
2bb528
output to build documentation entries dynamically.
be6bef
be6bef
@verbatim
be6bef
----------------------------------------------------------------------
be6bef
To know more, run the following command:
f7b7e3
centos-art manual --read='path/to/dir'
be6bef
----------------------------------------------------------------------
be6bef
@end verbatim
be6bef
be6bef
Use @option{AsToKnowMoreLine} option after errors and for intentional
be6bef
script termination. 
be6bef
be6bef
@item AsRegularLine
be6bef
To standardize regular messages using one-column format. 
be6bef
be6bef
When @var{MESSAGE} contains a colon inside (e.g., @samp{description:
be6bef
message}), the @code{cli_printMessage} function outputs @var{MESSAGE}
be6bef
using two-columns format. 
6c4982
@end table
2bb528
2bb528
@quotation
2bb528
@strong{Tip} To improve two-columns format, change the following file:
2bb528
@verbatim
2bb528
trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
2bb528
@end verbatim
2bb528
@end quotation
2bb528
41f1ec
Use @code{cli_printMessage} function whenever you need to output
2bb528
information from @file{centos-art.sh} script.
be6bef
@end defun
6c4982
6c4982
@subsubsection Specific functions
6c4982
6c4982
The following specific functions of @file{centos-art.sh} script, are
6c4982
available for you to use:
4c79b5
38bcd9
@menu
38bcd9
* trunk Scripts Bash Functions Html::
38bcd9
* trunk Scripts Bash Functions Locale::
035049
* trunk Scripts Bash Functions Manual::
38bcd9
* trunk Scripts Bash Functions Path::
38bcd9
* trunk Scripts Bash Functions Render::
b17ce8
* trunk Scripts Bash Functions Render Config::
38bcd9
* trunk Scripts Bash Functions Shell::
38bcd9
* trunk Scripts Bash Functions Svg::
38bcd9
* trunk Scripts Bash Functions Verify::
38bcd9
@end menu
4c79b5
4c79b5
@subsection See also
4c79b5
4c79b5
@menu
38bcd9
* trunk Scripts Bash::
efa7b7
* trunk Scripts Bash Locale::
4c79b5
@end menu