Table of Contents

patchconf - Smart patching of config files

Name

patchconf — Smart patching of config files

Synopsis

patchconf --file <filename> --name <name> --value <value> [options]

Goal

Patchconf is very simple utility for patching configurationfiles. All configuration files contains strings as "name=value". For changing this value Youmust open the file and edit it byhand. But patchconf does it for You.

Implements

  • patch value(s) of defined variable;
  • patch one-line comments before string which contains defined variable;
  • addnecessary line at file if defined variablenotfound.

Examples

Example 1:

Change value(s) of defined variable. Patchconf can adds new value at the end ( at the start) of old values or replace old value(s) for new.

In file test.conf:

...
some_value=some_value
...

Command: patchconf -f test.conf -n some_name -v new_value -m replace

In file test.conf:

...
some_value=new_value
...

Example 2:

Modify of comments: patchconf can adds/erase/keep one-line comment before string which contains defined variable.

In file test.conf:


...
# some comment
some_value=some_value
...

Command: patchconf -f test.conf -n some_name -v new_value --com-mode replace

In file test.conf:


...
# patchconf: next line modified by patchconf
some_value=some_value
...

Options

--file, -f

config file for patching

--name, -n

name of variable which must be patching

--value, -v

value that must be assign for 'name'

--help, -h

print help to stdout

--line-comment, -l

comment line before line which was patched

--line-separator

start characters of comment line

--comment, -c

multi-line comment

--comment-start

start characters of multi-line comment

--comment-end

end characters of multi-line comment

--section

section which contain 'name'

--section-start

start characters of section

--section-end

end charactrers of section

--separator, -s

separator characters between 'name' and values

--delimiter, -d

delimiter characters of values

--value-mode, -m

value mode

--com-mode

comment mode

--add-name

add name mode

Patching of 'name'

The main target of patchconf is a simple patching of values of some variable called 'name'. Patchconf can do it. 'Value' defined by user may be adding to the end of already exist values, insert at begin of already exist values or insert instead of already exist values. New position of 'value' defined by follow option:

--value-mode, -m

this key may contain three value:

add 'value' adding at the end(this option set as default)

ins insert 'value' at the begin

replace replace old values

But what happened if 'name' not found? In this case patchconf can add new string: "name=value" at the begin or at the end of file. This possibility defined by follow option:

--add-name, -a

this key may contain next values:

add add to string to end(tihs opion set as default)

ins insert at the begin

nothing do nothing

Working with comments

Before all patching lines patchconf insert own comment as: "# pathconf: next line was patching by patchconf". Patchconf correctly parse line comments before line and can patching it also. Also allowed user-defined line-comments.

--com-mode

this key may contain next values:

keep keep old comment only (defined as default).

replace insert new comment instead of old comment.

add add new comment after old comment.

erase erase old comment only.

What doing in case if 'name' not found

May be config file doesn't contain 'name', but user can define what must be done in this case. It defined by next option:

--add-name

this key may contain next values:

add add string with appropriating name and value at the end of file.

ins insert string with appropriating name and value at the begin of file.

nothing do nothing (defined as default).