Skip to content

Commit 10c0df0

Browse files
committed
Update README.md.
1 parent 8991cf5 commit 10c0df0

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

README.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# *nginx* config file formatter
22

3-
This Python script formats *nginx* configuration files in consistent
4-
way, described below:
3+
This Python script formats *nginx* configuration files in consistent way, described below:
54

65
* all lines are indented in uniform manner, with 4 spaces per level
76
* neighbouring empty lines are collapsed to at most two empty lines
@@ -10,8 +9,8 @@ way, described below:
109

1110
## Installation
1211

13-
Python 3.4 or later is needed to run this program. The simplest form
14-
of installation would be copying `nginxfmt.py` to your scripts directory.
12+
Python 3.4 or later is needed to run this program. The simplest form of installation would be copying `nginxfmt.py` to
13+
your scripts directory.
1514

1615
You can also clone the repository and symlink the executable:
1716

@@ -24,30 +23,66 @@ ln -s ~/nginx-config-formatter/nginxfmt.py ~/bin/nginxfmt.py
2423
## Usage
2524

2625
```
27-
usage: nginxfmt.py [-h] [-v] [-b] config_files [config_files ...]
26+
usage: nginxfmt [-h] [-v] [-p | -b] [-i INDENT] config_files [config_files ...]
2827
29-
Script formats nginx configuration file.
28+
Formats nginx configuration files in consistent way.
3029
3130
positional arguments:
3231
config_files configuration files to format
3332
3433
optional arguments:
3534
-h, --help show this help message and exit
3635
-v, --verbose show formatted file names
36+
-p, --print-result prints result to stdout, original file is not changed
3737
-b, --backup-original
3838
backup original config file
39+
40+
formatting options:
41+
-i INDENT, --indent INDENT
42+
specify number of spaces for indentation
43+
```
44+
45+
## Using as library
46+
47+
Main logic is within `Formatter` class, which can be used in 3rd-party code.
48+
49+
```python
50+
import nginxfmt
51+
52+
# initializing with standard FormatterOptions
53+
f = nginxfmt.Formatter()
54+
55+
# format from string
56+
formatted_text = f.format_string(unformatted_text)
57+
58+
# format file and save result to the same file
59+
f.format_file(unformatted_file_path)
60+
61+
# format file and save result to the same file, original unformatted content is backed up
62+
f.format_file(unformatted_file_path, backup_path)
63+
```
64+
65+
Customizing formatting options:
66+
67+
```python
68+
import nginxfmt
69+
70+
fo = nginxfmt.FormatterOptions()
71+
fo.indentation = 2 # 2 spaces instead of default 4
72+
73+
# initializing with standard FormatterOptions
74+
f = nginxfmt.Formatter(fo)
3975
```
4076

4177
## Reporting bugs
4278

43-
Please create issue under https://github.com/slomkowski/nginx-config-formatter/issues.
44-
Be sure to add config snippets to reproduce the issue, preferably:
79+
Please create issue under https://github.com/slomkowski/nginx-config-formatter/issues. Be sure to add config snippets to
80+
reproduce the issue, preferably:
4581

4682
* snippet do be formatted
4783
* actual result with invalid formatting
4884
* desired result
4985

50-
5186
## Credits
5287

5388
Copyright 2021 Michał Słomkowski. License: Apache 2.0.

0 commit comments

Comments
 (0)