Created
June 26, 2016 23:21
-
-
Save cyberbikepunk/b543429be9f83bc83ce67a6be799939a to your computer and use it in GitHub Desktop.
Get command line scripts from setup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
"""The project dommand line interface for developers. | |
""" | |
from __future__ import (absolute_import, | |
division, | |
print_function, | |
unicode_literals) | |
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(file.read()) | |
return package['scripts'] | |
scripts = get_scripts() | |
def build_parser(): | |
parser = ArgumentParser(prog='python run.py', | |
description=__doc__, | |
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