.TH "md_src_plugins_rename_README" 3elektra "Thu Sep 7 2023" "Version 0.11.0" "Elektra" \" -*- nroff -*-
.ad l
.nh
.SH NAME
md_src_plugins_rename_README \- Plugin: rename 

.IP "\(bu" 2
infos = Information about rename plugin is in keys below
.IP "\(bu" 2
infos/author = Felix Berlakovich elektra@berlakovich.net
.IP "\(bu" 2
infos/licence = BSD
.IP "\(bu" 2
infos/provides = filter
.IP "\(bu" 2
infos/needs =
.IP "\(bu" 2
infos/placements = presetstorage postgetstorage
.IP "\(bu" 2
infos/status = maintained unittest nodep libc configurable
.IP "\(bu" 2
infos/metadata = rename/to rename/toupper rename/tolower rename/cut origname
.IP "\(bu" 2
infos/description = renaming of keys
.PP
.SH "Introduction"
.PP
This plugin can be used to perform rename operations on keys\&. This is useful if a backend does not provide keys with the required names or case\&.
.PP
If keys are renamed, their original name is stored in the \fCorigname\fP MetaKey\&.
.PP
There are 2 types of transformations:
.PP
.IP "\(bu" 2
basic
.IP "\(bu" 2
advanced
.PP
.SH "Basic Transformations"
.PP
are applied before and after the advanced transformations\&.
.SS "Get"
first transformation to be applied to all keys on kdbGet\&.
.PP
\fCget/case\fP
.PP
.IP "\(bu" 2
toupper
.IP "\(bu" 2
tolower
.IP "\(bu" 2
unchanged // this is the default value if no configuration is given
.PP
.PP
converts the whole keyname below the parentKey to upper- or lowercase\&. if no configuration or \fCunchanged\fP is used no transformation is done here\&.
.SS "Set"
last transformation to be applied to all keys on kdbSet\&.
.PP
\fCset/case\fP
.PP
.IP "\(bu" 2
toupper
.IP "\(bu" 2
tolower
.IP "\(bu" 2
keyname
.IP "\(bu" 2
unchanged // this is the default value if no configuration is given
.PP
.PP
\fCtoupper\fP or \fCtolower\fP tells the rename plugin to convert the whole keyname below the parentKey to lower or uppercase\&.
.PP
\fCunchanged\fP returns the key to its original name
.PP
\fCkeyname\fP tells the plugin to keep the name of the advanced transformation
.SH "Advanced Transformations"
.PP
.SS "Cut"
.SS "Operation"
The cut operation can be used to strip parts of a key’s name\&. The cut operation is able to cut anything below the path of the parent key\&. A renamed key may even replace the parent key\&. For example consider a KeySet with the parent key \fCuser:/config\fP\&. If the KeySet contained a key with the name \fCuser:/config/with/long/path/key1\fP, the cut operation would be able to strip the following key name parts:
.PP
.IP "\(bu" 2
with
.IP "\(bu" 2
with/long
.IP "\(bu" 2
with/long/path
.IP "\(bu" 2
with/long/path/key1
.PP
.SS "Configuration"
The cut operation takes as its only configuration parameter the key name part to strip\&. This configuration can be supplied in two different ways\&. First, the global configuration key \fCcut\fP can be used\&. Second, keys to be stripped can be tagged with the MetaKey \fCrename/cut\fP\&. If both options are given, the MetaKey takes precedence\&. For example, consider the following setup:
.PP
.PP
.nf
config/cut = will/be
parent key = user:/config

user:/config/will/be/stripped/key1              <- meta rename/cut = will/be/stripped
user:/config/will/be/stripped/key2              <- meta rename/cut = will/be/stripped
user:/config/will/be/stripped/key3
user:/config/will/not/be/stripped/key4
.fi
.PP
.PP
The result of the cut operation would be the following KeySet:
.PP
.PP
.nf
user:/config/key1
user:/config/key2
user:/config/stripped/key3
user:/config/will/not/be/stripped/key4
.fi
.PP
.PP
The cut operation is agnostic to a single trailing slash in the configuration\&. This means that it makes no difference whether \fCcut = will/be/stripped\fP or \fCcut = will/be/stripped/\fP\&. However, the cut operation refuses cut paths with leading slash\&. This is to clarify that key name parts can only be stripped after the parent key path\&.
.PP
If an invalid configuration is given or the cut operation would cause a parent key duplicate, the affected keys are simply skipped and not renamed\&.
.SS "Replace"
Using the \fC/replacewith\fP global key or \fCrename/to\fP MetaKey the rename plugin will replace the part removed by \fCcut\fP with the supplied String
.SS "To upper/lower"
Using the \fC/toupper\fP or \fC/tolower\fP global configuration key, or the \fCrename/toupper\fP or \fCrename/tolower\fP metakey the rename plugin will convert the keynames to uppercase or lowercase\&. The supplied values tell the plugin how many levels starting from the right will be converted\&. \fCtoupper\fP and \fCtolower\fP can be combined\&. When no value or '0' is supplied with the keys the whole name below the parentkey will be converted\&.
.PP
The toupper/tolower conversions are applied after cut/replace\&.
.PP
Note that the names refer to the representation as KeySet\&. For example, if you have a configuration file where every name is uppercase:
.PP
.PP
.nf
KEY=value
OTHER/KEY=otherval
.fi
.PP
.PP
you can use \fCtolower=0\fP to get the keys \fCkey\fP and \fCother/key\fP\&.
.SS "Examples"
.PP
.nf
sudo kdb mount caseconversion\&.ini user:/tests/rename mini rename toupper=1,tolower=3

kdb set user:/tests/rename/MIXED/CASE/conversion 1

kdb ls user:/tests/rename
#> user:/tests/rename/mixed/case/CONVERSION

# Undo modifications
kdb rm -r user:/tests/rename
sudo kdb umount user:/tests/rename
.fi
.PP
.PP
.PP
.nf
sudo kdb mount renameTest\&.ini user:/tests/rename mini rename get/case=toupper,set/case=keyname,/cut=REMOVED

printf 'removed/key=test' > `kdb file user:/tests/rename`

kdb ls user:/tests/rename
#> user:/tests/rename/KEY

kdb set user:/tests/rename ""

cat "`kdb file user:/tests/rename`" | tail -n1
#> KEY=test

# Undo modifications
kdb rm -r user:/tests/rename
sudo kdb umount user:/tests/rename
.fi
.PP
.PP
.PP
.nf
# If you always want the keys in the configuration file upper case,
# but for your application lower case you would use:
sudo kdb mount caseconversion\&.ini user:/tests/rename mini rename get/case=tolower,set/case=toupper

kdb set user:/tests/rename/section/key value
kdb get user:/tests/rename/section/key
#> value

cat "`kdb file user:/tests/rename`"
#> SECTION/KEY=value

# Undo modifications
kdb rm -r user:/tests/rename
sudo kdb umount user:/tests/rename
.fi
.PP
.SH "Planned Operations"
.PP
Additional rename operations are planned for future versions of the rename plugin:
.PP
.IP "\(bu" 2
trim: remove spaces in the name (that are not part of parentKey)
.IP "\(bu" 2
ranges for toupper, tolower
.IP "\(bu" 2
allow one to specify the case in configuration files (#485) 
.PP

