python-argparse-generator
v0.2.1
Published
NPM package for generation of Python code (as text) to streamline writing boilerplate argparse setup.
Downloads
4
Readme
Python Argparse Generator
Package for generation of Python code (as text) to streamline writing boilerplate Python argparse setup.
Installing
Using npm:
$ npm install python-argparse-generator
Using unpkg CDN:
<script src="https://unpkg.com/python-argparse-generator/lib/index.js"></script>
Example
Within HTML:
<html>
<head>
<script>var exports={}</script>
<script src="https://unpkg.com/python-argparse-generator/lib/index.js"></script>
</head>
<script>
const pythonCode = argparseCode([
{ name: 'folder', type: 'str' },
{ name: 'limit', type: 'int' },
]);
console.log(pythonCode);
</script>
</html>
Within Typescript:
import { Argument, argparseCode } from 'python-argparse-generator';
const args: Argument[] = [
{ name: 'folder', type: 'str' },
{ name: 'limit', type: 'int' },
];
const pythonCode = argparseCode(args);
Where content of pythonCode
string is:
import argparse
from typing import Dict, Any
def main(folder: str, limit: int) -> None:
# Contents of main
return
def cli() -> Dict[str, Any]:
formatter_class = argparse.ArgumentDefaultsHelpFormatter
parser = argparse.ArgumentParser(formatter_class=formatter_class)
parser.add_argument("folder", type=str, default="/data")
parser.add_argument("limit", type=int, default=10)
args = parser.parse_args()
return {"folder": args.folder,
"limit": int(args.limit)}
if __name__ == '__main__':
args = cli()
main(folder=args["folder"], limit=args["limit"])