diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc1a9e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# ignore ALL files from the dist directory +dist/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d013185 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +``` +Generate automatic command index from a program. + +Usage: + make-readme [options] COMMAND + +It outputs a Markdown section with program name, +help and version information. + +Works for any installed program that has --help +and --version options. Especially useful for Docopt. +It can be used with the following command to generate readme files: + pip install -e . + +Options: + -h LEVEL, --heading LEVEL Start from hLEVEL heading [default: 2]. + --help Display this message. + --version Display version information. +``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5da3f0d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "markdown_help" +version = "0.9" +authors = [ + { name="Michal Moroz", email="michal@makimo.pl" }, + { name="Wojciech Mielczarek", email="wojciech.mielczarek@makimo.pl" }, +] +description = "Generate automatic command index from a program." +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +dependencies = [ + 'docopt == 0.6.2', +] + +[project.urls] +"Homepage" = "https://github.com/makimo/markdown-help" +"Bug Tracker" = "https://github.com/makimo/markdown-help/issues" + +[project.scripts] +markdown-help = "markdown_help:main" \ No newline at end of file diff --git a/src/markdown_help.egg-info/PKG-INFO b/src/markdown_help.egg-info/PKG-INFO new file mode 100644 index 0000000..ececcac --- /dev/null +++ b/src/markdown_help.egg-info/PKG-INFO @@ -0,0 +1,34 @@ +Metadata-Version: 2.1 +Name: markdown-help +Version: 0.9 +Summary: Generate automatic command index from a program. +Author-email: Michal Moroz , Wojciech Mielczarek +Project-URL: Homepage, https://github.com/makimo/markdown-help +Project-URL: Bug Tracker, https://github.com/makimo/markdown-help/issues +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.7 +Description-Content-Type: text/markdown +License-File: LICENSE +Requires-Dist: docopt==0.6.2 + +``` +Generate automatic command index from a program. + +Usage: + make-readme [options] COMMAND + +It outputs a Markdown section with program name, +help and version information. + +Works for any installed program that has --help +and --version options. Especially useful for Docopt. +It can be used with the following command to generate readme files: + pip install -e . + +Options: + -h LEVEL, --heading LEVEL Start from hLEVEL heading [default: 2]. + --help Display this message. + --version Display version information. +``` diff --git a/src/markdown_help.egg-info/SOURCES.txt b/src/markdown_help.egg-info/SOURCES.txt new file mode 100644 index 0000000..657d2d5 --- /dev/null +++ b/src/markdown_help.egg-info/SOURCES.txt @@ -0,0 +1,11 @@ +LICENSE +README.md +pyproject.toml +src/markdown_help.py +src/markdown_help/__init__.py +src/markdown_help.egg-info/PKG-INFO +src/markdown_help.egg-info/SOURCES.txt +src/markdown_help.egg-info/dependency_links.txt +src/markdown_help.egg-info/entry_points.txt +src/markdown_help.egg-info/requires.txt +src/markdown_help.egg-info/top_level.txt \ No newline at end of file diff --git a/src/markdown_help.egg-info/dependency_links.txt b/src/markdown_help.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/markdown_help.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/src/markdown_help.egg-info/entry_points.txt b/src/markdown_help.egg-info/entry_points.txt new file mode 100644 index 0000000..1a8a9d6 --- /dev/null +++ b/src/markdown_help.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +markdown-help = markdown_help:main diff --git a/src/markdown_help.egg-info/requires.txt b/src/markdown_help.egg-info/requires.txt new file mode 100644 index 0000000..1d9dff8 --- /dev/null +++ b/src/markdown_help.egg-info/requires.txt @@ -0,0 +1 @@ +docopt==0.6.2 diff --git a/src/markdown_help.egg-info/top_level.txt b/src/markdown_help.egg-info/top_level.txt new file mode 100644 index 0000000..0f1f4a3 --- /dev/null +++ b/src/markdown_help.egg-info/top_level.txt @@ -0,0 +1 @@ +markdown_help diff --git a/src/markdown_help.py b/src/markdown_help.py new file mode 100644 index 0000000..0c15097 --- /dev/null +++ b/src/markdown_help.py @@ -0,0 +1,60 @@ +""" +Generate automatic command index from a program. + +Usage: + make-readme [options] COMMAND + +It outputs a Markdown section with program name, +help and version information. + +Works for any installed program that has --help +and --version options. Especially useful for Docopt. +It can be used with the following command to generate readme files: + pip install -e . + +Options: + -h LEVEL, --heading LEVEL Start from hLEVEL heading [default: 2]. + --help Display this message. + --version Display version information. +""" + +VERSION = '0.9' + + +import sys +import re + +import subprocess + +from docopt import docopt + + +TEXT = """{title_heading} {command_name} ({version}) + +``` +{help_text} +``` +""" + + +def doc_for(command_name, fmt_string=TEXT, title_heading="##"): + version = subprocess.check_output([command_name, '--version']).strip().decode('utf-8') + help_text = subprocess.check_output([command_name, '--help']).strip().decode('utf-8') + + return fmt_string.format( + command_name=command_name, + title_heading=title_heading, + version=version, + help_text=help_text + ) + + +def main(): + arguments = docopt(__doc__, version=VERSION) + + command = arguments['COMMAND'] + + print(doc_for( + command, + title_heading='#' * int(arguments['--heading']) + ), end='') \ No newline at end of file diff --git a/src/markdown_help/__init__.py b/src/markdown_help/__init__.py new file mode 100644 index 0000000..e69de29