Error caused by an invalid or missing command line option
-
main(argv:list) → None
+
main() → None
Main CLI
+ Runs the main quickdocs program. Generates the docs/index.html from
+ the README.md file and from the module created using the
+ pyproject.toml file. If the WITHCSS is set to a file that exists, it
+ also copies that file to the docs/ folder and references it in the HTML
+ file.
Arguments
argv (list[str]): argument list (default is sys.argv)
@@ -87,7 +92,18 @@
Returns
int: exit code
-
+
Properties
+
DEBUG (bool): enable debugging traceback on exception
+
WITHCSS (str): enable copying CSS file to `docs/`
+
+
+
Exceptions
+
Exception: exceptions are only raised if `DEBUG` is `True`.
+
FileNotFoundError: exception raised when an input file is not found.
+
QuickdocsError: exception raised when an invalid command argument is encountered.
+
+
+
Python Constants
E_ERROR = 1E_OK = 0
Package Metadata
diff --git a/quickdocs.py b/quickdocs.py
index 7a0b1fd..94b2e9b 100644
--- a/quickdocs.py
+++ b/quickdocs.py
@@ -92,21 +92,13 @@
import datetime as dt
import shutil
-class CommandError(Exception):
+class QuickdocsError(Exception):
"""Error caused by an invalid or missing command line option"""
E_OK = 0
E_ERROR = 1
-def main(argv:list[str]=sys.argv):
- """Main CLI
-
- Arguments:
- argv (list[str]): argument list (default is sys.argv)
-
- Returns:
- int: exit code
- """
+def _main(argv:list[str]=sys.argv):
main.DEBUG = False
withcss = False
@@ -126,7 +118,7 @@ def main(argv:list[str]=sys.argv):
elif key == "--withcss":
withcss = value if value else "quickdocs.css"
elif arg != "-":
- raise CommandError(f"invalid option '{arg}'")
+ raise QuickdocsError(f"invalid option '{arg}'")
with open("pyproject.toml","rb") as fh:
package = tomllib.load(fh)["project"]
@@ -151,6 +143,9 @@ def main(argv:list[str]=sys.argv):
os.makedirs("docs",exist_ok=True)
+ if withcss:
+ shutil.copy(withcss,"docs/quickdocs.css")
+
with open("docs/index.html","w",encoding="utf-8") as html:
def write_html(text,md=True,nl=False):
@@ -335,7 +330,7 @@ def get_mode():
write_html(f" → *{c}*")
except KeyError:
write_html(" → *None*")
- write_html("\n")
+ write_html("\n")
for line in value.__doc__.split("\n"):
if len(line) == 0:
@@ -353,7 +348,7 @@ def get_mode():
write_html(f"
{part[0]}
\n",md=False)
else:
set_mode(None)
- write_html(f"{line}\n")
+ write_html(f"{line}\n")
else:
print(f"WARNING: function '{name}' has no __doc__")
set_mode(None)
@@ -384,18 +379,42 @@ def get_mode():
write_html("""