diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7bf1e73 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2023 Mark Sellors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/Makefile b/Makefile index a268b7f..3ae006a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ all: README.md README.md: README.bashdown bashdown - ./bashdown README.bashdown > README.md + bashdown README.bashdown > README.md diff --git a/README.bashdown b/README.bashdown index b360437..caaa348 100644 --- a/README.bashdown +++ b/README.bashdown @@ -24,13 +24,13 @@ significantly fewer dependencies due to it's much more limited scope. Basic usage is as follows: ```bash -# ./bashdown README.bashdown > README.md +# bashdown README.bashdown > README.md ``` Full usage information can be obtained from the built in help. ```bash -./bashdown --help +bashdown --help ``` diff --git a/README.md b/README.md index 8100a46..01b6085 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ significantly fewer dependencies due to it's much more limited scope. Basic usage is as follows: ```bash -# ./bashdown README.bashdown > README.md +# bashdown README.bashdown > README.md ``` Full usage information can be obtained from the built in help. ```bash -./bashdown --help +bashdown --help ``` ```output @@ -41,7 +41,7 @@ Processes in-line bash in markdown files positional arguments: filename -optional arguments: +options: -h, --help show this help message and exit For more information please see the docs diff --git a/bashdown b/bashdown/__init__.py old mode 100755 new mode 100644 similarity index 88% rename from bashdown rename to bashdown/__init__.py index b8918a4..7ec424b --- a/bashdown +++ b/bashdown/__init__.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """ Takes a markdown file with bash code blocks, executes the bash commands and returns the original markdown content with output blocks containing the @@ -8,6 +7,7 @@ import argparse import re import subprocess +import sys def process_content(input_lines): @@ -42,16 +42,24 @@ def process_content(input_lines): print(line, end="") -if __name__ == "__main__": +def cli_arg_parser(args=None): parser = argparse.ArgumentParser( prog="bashdown", description="Processes in-line bash in markdown files", epilog="For more information please see the docs", ) parser.add_argument("filename") - args = parser.parse_args() + return parser.parse_args() + + +def main(): + args = cli_arg_parser(sys.argv[1:]) - with open(args.filename, "r") as file: + with open(args.filename, "r", encoding="utf8") as file: content = file.readlines() process_content(content) + + +if __name__ == "__main__": + main() diff --git a/bashdown/__pycache__/__init__.cpython-310.pyc b/bashdown/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..854ef82 Binary files /dev/null and b/bashdown/__pycache__/__init__.cpython-310.pyc differ diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..cf161de --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.0" +python-versions = "^3.10" +content-hash = "53f2eabc9c26446fbcc00d348c47878e118afc2054778c3c803a0a8028af27d9" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c6936db --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "bashdown" +version = "0.1.0" +description = "Executes in-line bash in markdown files" +authors = ["Mark Sellors "] +readme = "README.md" +repository = "https://github.com/python-poetry/poetry" +homepage = "https://python-poetry.org/" + + +[tool.poetry.dependencies] +python = "^3.10" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +bashdown = "bashdown:main" +