Skip to content

Commit

Permalink
Merge pull request #18 from junghoon-vans/feature/implement-applicati…
Browse files Browse the repository at this point in the history
…on-to-replace-substitutions

feat: Implement application to replace substitutions
  • Loading branch information
junghoon-vans authored Nov 24, 2022
2 parents 50f078b + db22179 commit 17afbb1
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 35 deletions.
26 changes: 25 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/junghoon-vans/varst/blob/main/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
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions docs/source/api/varst.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
API docs
========

.. toctree::
:maxdepth: 4

varst.cli
varst.application
varst.utils
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 20 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=========
Expand Down
27 changes: 0 additions & 27 deletions docs/source/varst.rst

This file was deleted.

10 changes: 9 additions & 1 deletion varst/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
6 changes: 3 additions & 3 deletions varst/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"[^=]+=[^=]+")
Expand Down

0 comments on commit 17afbb1

Please sign in to comment.