Skip to content

Commit 7bcf072

Browse files
authored
feat: CLI entrypoint (#47)
This adds a script entrypoint to run the markup() function on a bunch of files. This makes it possible to use rfc2html with pipx/uvx as follow: $ wget https://www.rfc-editor.org/rfc/rfc8446.txt $ pipx rfc2html -v rfc8446.txt rfc8446.txt.html
1 parent edb25a8 commit 7bcf072

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ with open('rfc3344.txt') as file:
3030
html = markup(text)
3131
```
3232

33+
This function can be used via the CLI:
34+
35+
```bash
36+
$ rfc2html -v rfc3344.txt
37+
rfc3344.txt.html
38+
```
39+
3340
### History
3441

3542
As a historic artifact of being a document series which was started at the time when the easiest

rfc2html.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import unicode_literals, print_function, division
77

8+
import argparse
89
import re
910
try:
1011
from html import escape
@@ -413,3 +414,22 @@ def appendix_replacement(match):
413414
text = re.sub(r"%s\?draft=" % script, r"%s/" % path, text)
414415

415416
return text
417+
418+
419+
def main():
420+
parser = argparse.ArgumentParser(description="Convert RFC .txt files to .html ones.")
421+
parser.add_argument("files", nargs="+", metavar="FILE", help="text file to htmlize")
422+
parser.add_argument("-v", "--verbose", action="store_true", help="name the html files as they are created")
423+
options = parser.parse_args()
424+
425+
for filename_txt in options.files:
426+
filename_html = filename_txt + ".html"
427+
with open(filename_txt) as file_txt:
428+
with open(filename_html, "w") as file_html:
429+
file_html.write(markup(file_txt.read()))
430+
if options.verbose:
431+
print(filename_html)
432+
433+
434+
if __name__ == "__main__":
435+
main()

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@
106106
# To provide executable scripts, use entry points in preference to the
107107
# "scripts" keyword. Entry points provide cross-platform support and allow
108108
# pip to create the appropriate form of executable for the target platform.
109-
#entry_points={},
109+
entry_points={
110+
"console_scripts": [
111+
"rfc2html = rfc2html:main",
112+
],
113+
},
110114

111115

112116
# We're reading schema files from a package directory.

0 commit comments

Comments
 (0)