Skip to content

Commit

Permalink
Merge pull request #23 from junghoon-vans/feature/running-application…
Browse files Browse the repository at this point in the history
…-with-only-input-path

feat: Running application with only input path
  • Loading branch information
junghoon-vans authored Nov 28, 2022
2 parents fa88f33 + 3651018 commit ae599a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tests/utils/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def parser() -> Generator[Parser, None, None]:
yield parser


def test_parse_variables(parser: Parser):
assert parser.variables == {
def test_parse_sub_pairs(parser: Parser):
assert parser.sub_pairs == {
'varst': 'variable to reStructuredText',
'version': '0.2.0',
'release': 'v0.2.0',
Expand Down
2 changes: 1 addition & 1 deletion varst/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def run(self, argv: Optional[Sequence[str]]) -> None:

rst_file = RstFile(src=self.parser.input_file)
substitution = Substitution(rst_file)
for k, v in self.parser.variables.items():
for k, v in self.parser.sub_pairs.items():
substitution.update(k, v)
rst_file.save(dest=self.parser.output_file)
19 changes: 9 additions & 10 deletions varst/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
class Parser:
"""Parser class that parse arguments from cli"""

_parser = ArgumentParser()

input_file: str = ""
output_file: str = ""
variables: Dict[str, str] = {}

def __init__(self) -> None:
self._parser = ArgumentParser()
self.input_file: str = ""
self.output_file: str = ""
self.sub_pairs: Dict[str, str] = {}

self._parser.add_argument(
"name=value", nargs="*",
help="name-value pairs of substitutions",
Expand All @@ -37,7 +36,6 @@ def __init__(self) -> None:
"--output",
type=_file_type,
help="rst file path as output",
default="./README.rst",
)

def parse(self, argv: Optional[Sequence[str]]) -> None:
Expand All @@ -51,9 +49,10 @@ def parse(self, argv: Optional[Sequence[str]]) -> None:
args = self._parser.parse_args(argv)
arg_dict = vars(args)

self.input_file = arg_dict['input']
self.output_file = arg_dict['output']
self.variables = _parse_kv(arg_dict['name=value'])
self.input_file = self.output_file = arg_dict['input']
if arg_dict['output'] is not None:
self.output_file = arg_dict['output']
self.sub_pairs = _parse_kv(arg_dict['name=value'])


_VARIABLE_PATTERN = re.compile(r"[^=]+=[^=]+")
Expand Down

0 comments on commit ae599a3

Please sign in to comment.