App-optex

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    expand no_archive   ! -iname *.tar  ! -iname *.tbz  ! -iname *.tgz
    expand no_pdf       ! -iname *.pdf

    option --clean \
            repository -prune -o \
            -type f \
            no_dots \
            no_version no_backup \
            no_image \
            no_archive \
            no_pdf

    % find . --clean -print

## MODULES

**optex** also supports module extension.  In the example of `date`,
module file is found at `~/.optex.d/date/` directory.  If default
module, `~/.optex.d/date/default.pm` exists, it is loaded
automatically on every execution.

This is a normal Perl module, so package declaration and the final
true value is necessary.  Between them, you can put any kind of Perl
code.  For example, next program set environment variable `LANG` to
`C` before executing `date` command.

    package default;
    $ENV{LANG} = 'C';
    1;

    % /bin/date
    2017年 10月22日 日曜日 18時00分00秒 JST

    % date
    Sun Oct 22 18:00:00 JST 2017

Other modules are loaded using `-M` option.  Unlike other options,
`-M` have to be placed at the beginning of argument list.  Module
files in `~/.optex.d/date/` directory are used only for `date`
command.  If the module is placed on `~/.optex.d/` directory, it can
be used from all commands.

If you want use `-Mes` module, make a file `~/.optex.d/es.pm` with
following content.

    package es;
    $ENV{LANG} = 'es_ES';
    1;

    % date -Mes
    domingo, 22 de octubre de 2017, 18:00:00 JST

When the specified module was not found in library path, **optex**
ignores the option and stops argument processing immediately.  Ignored
options are passed through to the target command.

Module is also used with subroutine call.  Suppose
`~/.optex.d/env.pm` module look like:

    package env;
    sub setenv {
        while (($a, $b) = splice @_, 0, 2) {
            $ENV{$a} = $b;
        }
    }
    1;

Then it can be used in more generic fashion.  In the next example,
first format is easy to read, but second one is more easy to type
because it does not have special characters to be escaped.

    % date -Menv::setenv(LANG=de_DE) # need shell quote
    % date -Menv::setenv=LANG=de_DE  # alternative format
    So 22 Okt 2017 18:00:00 JST

Option aliases can be also declared in the module, at the end of file,
following special literal `__DATA__`.  Using this, you can prepare
multiple set of options for different purposes.  Think about generic
**i18n** module:

    package i18n;
    1;
    __DATA__
    option --cn -Menv::setenv(LANG=zh_CN) // 中国語 - 簡体字
    option --tw -Menv::setenv(LANG=zh_TW) // 中国語 - 繁体字
    option --us -Menv::setenv(LANG=en_US) // 英語
    option --fr -Menv::setenv(LANG=fr_FR) // フランス語
    option --de -Menv::setenv(LANG=de_DE) // ドイツ語
    option --it -Menv::setenv(LANG=it_IT) // イタリア語
    option --jp -Menv::setenv(LANG=ja_JP) // 日本語
    option --kr -Menv::setenv(LANG=ko_KR) // 韓国語
    option --br -Menv::setenv(LANG=pt_BR) // ポルトガル語 - ブラジル
    option --es -Menv::setenv(LANG=es_ES) // スペイン語
    option --ru -Menv::setenv(LANG=ru_RU) // ロシア語

This can be used like:

    % date -Mi18n --tw
    2017年10月22日 週日 18時00分00秒 JST

You can declare autoload module in your `~/.optex.d/optex.rc` like:

    autoload -Mi18n --cn --tw --us --fr --de --it --jp --kr --br --es --ru

Then you can use them without module option.  In this case, option
`--ru` is replaced by `-Mi18n --ru` automatically.

    % date --ru
    воскресенье, 22 октября 2017 г. 18:00:00 (JST)

Module `i18n` is implemented as [Getopt::EX::i18n](https://metacpan.org/pod/Getopt%3A%3AEX%3A%3Ai18n) and included in
this distribution.  So it can be used as above without additional
installation.

# STANDARD MODULES

Standard modules are installed at `App::optex`, and they can be
addressed with and without `App::optex` prefix.

- -M**help**

    Print available option list.  Option name is printed with substitution
    form, or help message if defined.  Use **-x** option to omit help
    message.

    Option **--man** or **-h** will print document if available.  Option
    **-l** will print module path.  Option **-m** will show the module
    itself.  When used after other modules, print information about the
    last declared module.  Next command show the document about **second**
    module.

        optex -Mfirst -Msecond -Mhelp --man

- -M**debug**

    Print debug messages.

- -M**util::argv**

    Module to manipulate command argument.
    See [App::optex::util::argv](https://metacpan.org/pod/App%3A%3Aoptex%3A%3Autil%3A%3Aargv) for detail.

- -M**util::filter**

    Module to implement command input/output filters.
    See [App::optex::util::filter](https://metacpan.org/pod/App%3A%3Aoptex%3A%3Autil%3A%3Afilter) for detail.

# Getopt::EX MODULES

In addition to its own modules, **optex** can also use `Getopt::EX`
modules.  The standard `Getopt::EX` modules installed are these.

- -M**i18n** ([Getopt::EX::i18n](https://metacpan.org/pod/Getopt%3A%3AEX%3A%3Ai18n))



( run in 0.703 second using v1.01-cache-2.11-cpan-5837b0d9d2c )