Skip to content

Commit ece9be8

Browse files
committed
docs(readme): add PowerShell, replace example
Emphasize initool never changes the input file.
1 parent 7742fef commit ece9be8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The global options `-i`/`--ignore-case` and `-p`/`--pass-through` must precede t
5353
When given a valid command, initool first reads the INI file `filename` in its entirety.
5454
If the filename is `-`, initool reads standard input. For the commands `get`, `set`, `replace`, and `delete`, it then prints to standard output the file's contents with the desired change.
5555
For `exists`, it reports whether the section or the property exists through its exit status.
56+
**Initool never modifies the original file.**
5657

5758
An INI file consists of properties (`key=value` lines) and sections (designated with a `[section name]` header line).
5859
A property can be at the "top level" of the file (before any section headers) or in a section (after a section header).
@@ -131,6 +132,14 @@ initool delete settings.ini test | initool set - "" cache 1024 > settings.ini.ne
131132
move /y settings.ini.new settings.ini
132133
```
133134

135+
You can use pipelines in PowerShell.
136+
The variable `$?` will be `True` only if all commands in the pipeline succeed.
137+
138+
```powershell
139+
./initool delete settings.ini test | ./initool set - '' cache 1024 > settings.ini.new
140+
if ($?) { move -Force settings.ini.new settings.ini }
141+
```
142+
134143
#### Both
135144

136145
To retrieve only the value of a property rather than the whole property (the section, key, and value), use the flag `-v` or `--value-only`:
@@ -143,6 +152,23 @@ $ initool get tests/test.ini foo name1 --value-only
143152
foo1
144153
```
145154

155+
To replace text in a value, use `replace`.
156+
157+
```sh
158+
$ initool get tests/replace-part.ini
159+
key=A longer value.
160+
another-key=ABAABBAAABBB
161+
empty=
162+
$ initool replace tests/replace-part.ini "" key value string
163+
key=A longer string.
164+
another-key=ABAABBAAABBB
165+
empty=
166+
> ./initool replace tests/replace-part.ini "" empty "" no
167+
key=A longer value.
168+
another-key=ABAABBAAABBB
169+
empty=no
170+
```
171+
146172
### Whitespace
147173

148174
Initool defines whitespace as any mix of space and tab characters.

0 commit comments

Comments
 (0)