Skip to content

Commit

Permalink
docs(readme): add PowerShell, replace example
Browse files Browse the repository at this point in the history
Emphasize initool never changes the input file.
  • Loading branch information
dbohdan committed Jun 10, 2024
1 parent 7742fef commit ece9be8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The global options `-i`/`--ignore-case` and `-p`/`--pass-through` must precede t
When given a valid command, initool first reads the INI file `filename` in its entirety.
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.
For `exists`, it reports whether the section or the property exists through its exit status.
**Initool never modifies the original file.**

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

You can use pipelines in PowerShell.
The variable `$?` will be `True` only if all commands in the pipeline succeed.

```powershell
./initool delete settings.ini test | ./initool set - '' cache 1024 > settings.ini.new
if ($?) { move -Force settings.ini.new settings.ini }
```

#### Both

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`:
Expand All @@ -143,6 +152,23 @@ $ initool get tests/test.ini foo name1 --value-only
foo1
```

To replace text in a value, use `replace`.

```sh
$ initool get tests/replace-part.ini
key=A longer value.
another-key=ABAABBAAABBB
empty=
$ initool replace tests/replace-part.ini "" key value string
key=A longer string.
another-key=ABAABBAAABBB
empty=
> ./initool replace tests/replace-part.ini "" empty "" no
key=A longer value.
another-key=ABAABBAAABBB
empty=no
```

### Whitespace

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

0 comments on commit ece9be8

Please sign in to comment.