diff --git a/README.rst b/README.rst index 52bd4d9..c80bc5f 100644 --- a/README.rst +++ b/README.rst @@ -2,11 +2,35 @@ varST(var ➡️ reStructuredText) ============================== -|pre-commit.ci status| |Documentation Status| +|PyPI version| |pre-commit.ci status| |GitHub Workflow Status| |Documentation Status| Replace substitutions in rst files with variables. +Installation +------------ + +.. code:: bash + + $ pip install varst + +Usage +----- + +.. code:: bash + + $ varst [-i INPUT] [-o OUTPUT] [name=value ...] + +License +------- + +`MIT +License `__ + + +.. |PyPI version| image:: https://img.shields.io/pypi/v/varst + :target: https://pypi.org/project/varst/ .. |pre-commit.ci status| image:: https://results.pre-commit.ci/badge/github/junghoon-vans/varst/main.svg :target: https://results.pre-commit.ci/latest/github/junghoon-vans/varst/main +.. |GitHub Workflow Status| image:: https://img.shields.io/github/workflow/status/junghoon-vans/varst/Upload%20Python%20Package .. |Documentation Status| image:: https://readthedocs.org/projects/varst/badge/?version=latest :target: https://varst.readthedocs.io/en/latest/?badge=latest diff --git a/docs/source/varst.application.rst b/docs/source/api/varst.application.rst similarity index 100% rename from docs/source/varst.application.rst rename to docs/source/api/varst.application.rst diff --git a/docs/source/varst.cli.rst b/docs/source/api/varst.cli.rst similarity index 100% rename from docs/source/varst.cli.rst rename to docs/source/api/varst.cli.rst diff --git a/docs/source/api/varst.rst b/docs/source/api/varst.rst new file mode 100644 index 0000000..3db1192 --- /dev/null +++ b/docs/source/api/varst.rst @@ -0,0 +1,9 @@ +API docs +======== + +.. toctree:: + :maxdepth: 4 + + varst.cli + varst.application + varst.utils diff --git a/docs/source/varst.utils.parser.rst b/docs/source/api/varst.utils.parser.rst similarity index 100% rename from docs/source/varst.utils.parser.rst rename to docs/source/api/varst.utils.parser.rst diff --git a/docs/source/varst.utils.rst b/docs/source/api/varst.utils.rst similarity index 100% rename from docs/source/varst.utils.rst rename to docs/source/api/varst.utils.rst diff --git a/docs/source/varst.utils.rst_file.rst b/docs/source/api/varst.utils.rst_file.rst similarity index 100% rename from docs/source/varst.utils.rst_file.rst rename to docs/source/api/varst.utils.rst_file.rst diff --git a/docs/source/varst.utils.substitution.rst b/docs/source/api/varst.utils.substitution.rst similarity index 100% rename from docs/source/varst.utils.substitution.rst rename to docs/source/api/varst.utils.substitution.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 8a63a8d..77f22dc 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -2,13 +2,30 @@ var ➡️ reStructuredText ======================= -Contents -======== +Replace substitutions in rst files with variables. + +Installation +============ + +.. code:: bash + + $ pip install varst + +Usage +===== + +.. code:: bash + + $ varst [-i INPUT] [-o OUTPUT] [name=value ...] + + +API documentation +================= .. toctree:: :maxdepth: 2 - varst + api/varst Changelog ========= diff --git a/docs/source/varst.rst b/docs/source/varst.rst deleted file mode 100644 index 0c8fac0..0000000 --- a/docs/source/varst.rst +++ /dev/null @@ -1,27 +0,0 @@ -varst package -============= - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - varst.utils - -Submodules ----------- - -.. toctree:: - :maxdepth: 4 - - varst.application - varst.cli - -Module contents ---------------- - -.. automodule:: varst - :members: - :undoc-members: - :show-inheritance: diff --git a/varst/application.py b/varst/application.py index 307a7d4..6222b62 100644 --- a/varst/application.py +++ b/varst/application.py @@ -3,6 +3,8 @@ from typing import Sequence from varst.utils.parser import Parser +from varst.utils.rst_file import RstFile +from varst.utils.substitution import Substitution class Application: @@ -12,10 +14,16 @@ def __init__(self) -> None: self.parser = Parser() def run(self, argv: Optional[Sequence[str]]): - """Run application + """Run application to replace substitutions. Args: argv: Arguments vector """ self.parser.parse(argv) + + rst_file = RstFile(src=self.parser.input_file) + substitution = Substitution(rst_file) + for k, v in self.parser.variables.items(): + substitution.update(k, v) + rst_file.save(dest=self.parser.output_file) diff --git a/varst/utils/parser.py b/varst/utils/parser.py index 10ddbf2..6c7585d 100644 --- a/varst/utils/parser.py +++ b/varst/utils/parser.py @@ -21,8 +21,8 @@ class Parser: def __init__(self) -> None: self._parser.add_argument( - "variables", nargs="*", - help="key-value pairs of substitutions", + "name=value", nargs="*", + help="name-value pairs of substitutions", type=_pattern_type, ) self._parser.add_argument( @@ -53,7 +53,7 @@ def parse(self, argv: Optional[Sequence[str]]) -> None: self.input_file = arg_dict['input'] self.output_file = arg_dict['output'] - self.variables = _parse_kv(arg_dict['variables']) + self.variables = _parse_kv(arg_dict['name=value']) _VARIABLE_PATTERN = re.compile(r"[^=]+=[^=]+")