Skip to content

Instantly share code, notes, and snippets.

Created Jun 26, 2016
What would you like to do?
Get command line scripts from
#! /usr/bin/env python
"""The project dommand line interface for developers.
from __future__ import (absolute_import,
from io import open
from os.path import join, dirname
from json import loads
from argparse import ArgumentParser
from subprocess import call
def get_scripts():
filepath = join(dirname(__file__), 'package.json')
with open(filepath, encoding='utf-8') as file:
package = loads(
return package['scripts']
scripts = get_scripts()
def build_parser():
parser = ArgumentParser(prog='python',
epilog='See package.json')
parser.add_argument('script', choices=scripts.keys())
return parser
if __name__ == '__main__':
choice = build_parser().parse_args().script
command = scripts[choice]
print('{script} running {command}'.format(script=choice, command=command))
exit(call(command, shell=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment