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
6c4982
    case "$OPTIONNAM" 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
41f1ec
The @var{OPTIONNAM} 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
41f1ec
argument is @option{--hello='World'}, the value of @var{OPTIONNAM}
41f1ec
variable would be @samp{--hello}.  Using this configuration let us
41f1ec
deside which action to perform based on the option 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
41f1ec
The @samp{*} case and its two further lines should always be present
41f1ec
in @file{_getActions.sh} function scripts, no matter what specific
41f1ec
functionality you are creating. This convenction helps the user to
41f1ec
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
6c4982
    cli_printMessage "`gettext "Hello"` $OPTIONVAL"
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
6c4982
    cli_printMessage "`gettext "Goodbye"` $OPTIONVAL"
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
41f1ec
The @var{OPTIONVAL} 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
41f1ec
argument is @option{--hello='World'}, the value of @var{OPTIONVAL}
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,
41f1ec
we use its directory path and the @code{help} functionality
be6bef
(@pxref{trunk Scripts Bash Functions Help}) of @file{centos-art.sh}
be6bef
script, just as the following command illustrates: 
be6bef
be6bef
@verbatim
be6bef
centos-art help --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
be6bef
@defvar ACTION
2bb528
Default action 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}.
be6bef
@end defvar
6c4982
be6bef
@defvar OPTIONNAM
2bb528
Default option name passed as second 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{OPTIONNAM} passed
2bb528
to @file{centos-art.sh} script is @option{--entry}.
be6bef
@end defvar
6c4982
be6bef
@defvar OPTIONVAL
2bb528
Default option value passed as second 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{OPTIONVAL} passed
2bb528
to @file{centos-art.sh} script is @option{path/to/dir}.
be6bef
@end defvar
6c4982
be6bef
@defvar REGEX
2bb528
Default option value passed as third 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{REGEX} passed to
2bb528
@file{centos-art.sh} is @option{regex}. 
2bb528
2bb528
The third argument option name is not variable as second argument
915635
option name is. The third argument option name is fixed to
915635
@option{--filter} for whatever value it passes at the right side of
2bb528
its equal sign. 
2bb528
2bb528
Generally, third argument option value is used to pass regular
2bb528
expression patterns that modify the list of files to process, but this
915635
is not the only feature @var{REGEX} global variable may serve to.
be6bef
@end defvar
6c4982
97552b
@defvar ARGUMENTS 
97552b
Define optional arguments. 
97552b
97552b
Inside @file{centos-art.sh} script, specifically inside @command{path}
97552b
functionality, we consider optional arguments as all command-line
97552b
arguments passed to @file{centos-art.sh} script, from third argument
97552b
position on.  
97552b
97552b
Optional arguments are appended to commands in order for
97552b
@file{centos-art.sh} script to support them.  Such commands are
97552b
executed inside @file{centos-art.sh} script using Bash's
97552b
@command{eval} built-in.  
97552b
97552b
If you provide unrecognized options to such commands, they will
97552b
complain just as they would do from the command-line.  Or what is the
97552b
same, final verification of which options are valid or not is done
97552b
inside the command options wered appended to, not by
97552b
@file{centos-art.sh} script.  
97552b
97552b
When parsing @var{ARGUMENTS}, we may find short options (e.g.,
97552b
@option{-m}) or long options (e.g., @option{--message}). When using
97552b
short options, arguments are separated by one space from the option
97552b
(e.g., @option{-m 'This is a commit message.'}).  When using long
97552b
options arguments are separated by an equal sign (@samp{=}) (e.g.,
97552b
@option{--message='This is a commit message'}). To know which option
97552b
have required arguments let @file{centos-art.sh} script to know how to
97552b
build the optional argument string by quoting the option's argument.  
97552b
97552b
Note that if we don't use @command{getopt} to parse the command-line
97552b
arguments it would complicate to determine when an argument is an
97552b
option argument and when it is not; when options' argument are
97552b
optional and where they are not. Inside getopt, required option
97552b
arguments are defined using the colon (@samp{:}) symbol after the
97552b
option (e.g., @option{-o m: -l message:}).
97552b
97552b
As convenction we use long options as reference. We take the value of
97552b
@var{ARGSLONG} and split it using the comma (@samp{,}) character as
97552b
separator and check if the last character of the option is a colon
97552b
like in the regular expression @code{[[:alpha:]]+:,}.
97552b
97552b
Take care not to match two colons like in the regular expression
97552b
@code{[[:alpha:]]+::,}, this construction is used to specify that
97552b
option can receive and argument but it is not required.
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
6c4982
@subsubsection Global functions
6c4982
6c4982
The following global functions of @file{centos-art.sh} script, are
6c4982
available for you to use inside specific functions:
6c4982
97552b
@defun cli_commitRepoChanges [LOCATION]
06048d
Commit changes from the working copy up to the repository.
06048d
915635
The @code{cli_commitRepoChanges} function uses the value of
06048d
@var{OPTIONVAL} variable as reference to perform change verifications
0646d4
inside the working copy.
06048d
06048d
The @code{cli_commitRepoChanges} function brings changes from the
06048d
repository to the working copy---using @command{svn update}---, check
06048d
the working copy changes---using @command{svn status} command---,
06048d
print status report---using both @command{svn update} and @command{svn
06048d
status} commands output, and finally, commit recent changes from the
06048d
working copy up to the repository---using @command{svn commit}
06048d
command---.
06048d
06048d
Previous to commit the working copy changes up to the repository, the
06048d
@code{cli_commitRepoChanges} function asks you to verify changes, and
06048d
later, another confirmation question is shown to be sure you really
06048d
want to commit changes up to central repository.
06048d
0646d4
Call the @code{cli_commitRepoChanges} function after functions that
0646d4
modify files or directories inside the working copy.  
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
2bb528
Ends script execution if @var{FILE} is neither a regular file or a
2bb528
symbolic link.
97552b
@item fd
97552b
Ends script execution if @var{FILE} is neither a regular file or a
97552b
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]
2bb528
Output country codes.
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]
2bb528
Output country names.
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.
2bb528
2bb528
The @code{cli_getCountryName} function outputs country name supported
2bb528
by @file{centos-art.sh} script.
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
41f1ec
@samp{en_GB} is used, we are also saying that no common language
41f1ec
specification is used for English language (i.e., @samp{en}). Instead,
41f1ec
we are using English non-common country-specific language
41f1ec
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.
2bb528
2bb528
The @code{cli_getCurrentLocale} function outputs current locale used
2bb528
by @file{centos-art.sh} script.
be6bef
@end defun
be6bef
be6bef
@defun cli_getLangCodes [FILTER]
2bb528
Output language codes.
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.
2bb528
2bb528
The @code{cli_getLangCodes} function outputs language codes supported
2bb528
by @file{centos-art.sh} script.
be6bef
@end defun
be6bef
41f1ec
@defun cli_getLangName [FILTER]
2bb528
Output language names.
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.
2bb528
2bb528
The @code{cli_getLangName} function outputs language names supported
2bb528
by @file{centos-art.sh} script.
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
41f1ec
The @var{TYPE} variable can be one of the following values:
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
2bb528
correctly, the @var{OPTIONVAL} 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:
be6bef
centos-art help --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 Help::
38bcd9
* trunk Scripts Bash Functions Html::
38bcd9
* trunk Scripts Bash Functions Locale::
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