NAME
util::argv - optex argument utility modules
SYNOPSIS
optex command -Mutil::argv
DESCRIPTION
This module is a collection of sample utility functions for command optex.
Function can be called with option declaration. Parameters for the function are passed by name and value list: name=value. Value 1 is assigned for the name without value.
In this example,
optex -Mutil::argv::function(debug,message=hello,count=3)
option debug has value 1, message has string "hello", and count also has string "3".
FUNCTION
- times(count=n,suffix=str)
-
Multiply each arguments. Default count is 2.
% optex echo -Mutil::argv::times(count=3) 1 2 3 1 1 1 2 2 2 3 3 3
Put suffix to duplicated arguments.
% optex echo -Mutil::argv::times(suffix=.bak) a b c a a.bak b b.bak c c.bak
- reverse()
-
Reverse arguments.
- collect(index=2:4:6)
- collect(glob=*.c)
- collect(include=.c$)
- collect(exclude=.c$)
-
Collect arguments based on the given parameter.
- index
-
% optex echo -Mutil::argv::collect(index=2:4:6) ichi ni san shi go roku
will print:
ni shi roku
- glob
-
% optex ls -Mutil::argv::collect(glob=*.c) foo.h foo.c foo.1
will print:
foo.c
- include
-
% optex ls -Mutil::argv::collect(include=.c$) foo.h foo.c foo.1
will print:
foo.c
- exclude
-
% optex ls -Mutil::argv::collect(exclude=.c$) foo.h foo.c foo.1
will print:
foo.h foo.1
- proc()
-
Process substitution.
% optex diff -Mutil::argv::proc= '<(date)' '<(date -u)'
- filter(command=command)
-
Execute filter command for each file. Specify any command which should be invoked for each argument.
% optex diff -Mutil::argv::filter=command='cat -n' foo bar
In this example,
foo
andbar
are replaced by the result output ofcat -n < foo
andcat -n < bar
. The replacement only occurs when the file corresponding to the argument exists.
OPTIONS
Several options are prepared and enabled by request. To enable specific option, use enable function like this to enable --move and --copy options.
-Mutil::argv::enable=move,copy
Parameter :all can be used to enable everything.
-Mutil::argv::enable=:all
You can use alternative names:
-Mutil::argv::enable(move=mymove,copy=mycopy)
- --move param
- --remove param
- --copy param
-
These options are converted
$<command(param)>
notation, where param is offset or offset,length.--move 0 moves all following arguments there, --remove 0 just removes them, and --copy 0 copies them.
--move 0,1 moves following argument (which does not change anything), and --move 1,1 moves second argument (exchange following two).
--move -1 moves the last argument.
--copy 0,1 duplicates the next.
- --exch
-
Exchanges following two arguments. This is same as --move 1,1.
optex -Mutil::argv::enable=exch echo --exch foo bar
will print:
bar foo
- --filter command
-
Set input filter for each file argument.
Next command passes the result of the
expand
filter to thecat -n
for each file in the command line.optex -Mutil::argv::enable=filter cat -n --filter=expand a b c
Following options are interface for builtin functions.