diff options
author | rsiddharth <s@ricketyspace.net> | 2018-03-25 19:44:00 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2018-03-25 19:44:00 +0000 |
commit | 937ff835b5808f184162d68d5eb93e12a7c5de86 (patch) | |
tree | 8f2640f53130eab687a0f9a672e4b70144611d70 /md_tw.py | |
parent | e357ce168c8f6a78df349fbb262d71bf46fe11b5 (diff) |
md_tw.py: Update main.
* md_tw.py (main): Update function.
Diffstat (limited to 'md_tw.py')
-rw-r--r-- | md_tw.py | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -18,6 +18,7 @@ # along with markdown-textwrap (see COPYING). If not, see # <http://www.gnu.org/licenses/>. +import argparse import re import textwrap @@ -516,4 +517,34 @@ class TWMarkdown(mistune.Markdown): def main(): - print('USAGE: md_tw 72 file.md file2.md [...]') + def parse_args(): + parser = argparse.ArgumentParser() + + # Options for args. + w_opts = { + 'type': int, + 'dest':'width', + 'default':72, + 'help': 'Max. line width. Default is 72.' + } + f_opts = { + 'type': argparse.FileType('r'), + 'help': 'File path of Markdown document.' + } + + # Define expected args. + parser.add_argument('-w', '--width', **w_opts) + parser.add_argument('md_file', **f_opts) + + # Parse 'em. + a = parser.parse_args() + + return {'width': a.width, 'text': a.md_file.read()} + + def wrap(text, width): + return TWMarkdown(tw_width=width)(text) + + def out(text): + print('{}'.format(text)) + + return out(wrap(**parse_args())) |