apply-subs-0.5.5
توضیحات
A command line tool to apply substitutions to a text file
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | apply-subs-0.5.5 |
| نام | apply-subs |
| نسخه کتابخانه | 0.5.5 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | C.M.T. Robert |
| ایمیل نویسنده | - |
| آدرس صفحه اصلی | https://github.com/neutrinoceros/apply_subs |
| آدرس اینترنتی | https://pypi.org/project/apply-subs/ |
| مجوز | GPL-3.0 |
# apply-subs


[](https://codecov.io/gh/neutrinoceros/apply_subs)
[](https://results.pre-commit.ci/latest/github/neutrinoceros/apply_subs/main)
[](https://pycqa.github.io/isort/)
[](https://github.com/psf/black)
A command line application to apply a dictionnary (json) of substitutions to
text file corpus. This program is a find-and-replace tool to perform a
arbitrarily large set of substitutions in a reproducible fashion.
Disclaimer, this app is far less powerful than `sed` and in particular doesn't
support regex replacement. What it offers a simpler interface to make simple
sweeping changes across a whole project in a reproducible fashion.
# Installation
The easiest installation method is
```shell
$ pip install apply-subs
```
In order to install `apply-subs` in isolation, use [`pipx`](https://pipxproject.github.io/pipx/) instead.
# Examples
`apply-subs` uses a json file as input. This file should specify substitutions
as `new: old`, where `old` can either be a single str, or a list of strings.
## minimal case
```shell
echo "bunnies and bongos and bananas" > mytext.txt
echo '{"bunnies": "rabbits", "SECRETS": ["bongos", "bananas"]}' > mysubs.json
apply-subs mytext.txt -s mysubs.json
```
will print the patched content
```
bunnies and SECRETS and SECRETS
```
## diff mode
Use diff mode (`-d/--diff`) to print a diff instead of the end result
```patch
--- mytext.txt
+++ mytext.txt (patched)
@@ -1 +1 @@
-Lorem ipsum dolor sit amet, consectetur adipiscing elit
+Hello dolor sit amet, consectetur goodbye
```
Use `-cp/--cdiff/--colored-diff` for a colored output (when supported).
## inplace substitutions
`-i/--inplace`
```shell
apply-subs --inplace mytext.txt -s mysubs.json
```
is equivalent to
```shell
apply-subs mytext.txt -s mysubs.json > mytext.txt
```
## target several files in one go
The `target` positional argument can consist of a single file (as illustrated above),
or many. This is useful for instance if you need to apply a set of subtitutions to
all files in a project whose name match a regexp.
```shell
git ls-files | egrep "(.md|.py)$" | xargs apply-subs -s subsubs.json -i
```
نیازمندی
| مقدار | نام |
|---|---|
| >=8.7.0 | more-itertools |
| >=9.10.0 | rich |
| >=0.7.4 | schema |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7 | Python |
نحوه نصب
نصب پکیج whl apply-subs-0.5.5:
pip install apply-subs-0.5.5.whl
نصب پکیج tar.gz apply-subs-0.5.5:
pip install apply-subs-0.5.5.tar.gz