Created
July 3, 2017 23:13
-
-
Save mattrohland/43b47bd079bd3d47adf674cbdbd970c3 to your computer and use it in GitHub Desktop.
Semantic Versioning CLI powered by the "semver" semantic versioning package and the "docopt" command line interface package.
This file contains hidden or 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
"""Semantic Versioning CLI (0.1.0) | |
Usage: | |
semvercli.py compare <a> <b> | |
semvercli.py bump_major <a> | |
semvercli.py bump_minor <a> | |
semvercli.py bump_patch <a> | |
semvercli.py (-h | --help) | |
semvercli.py --version | |
Options: | |
-h --help Show this screen. | |
--version Show version. | |
""" | |
from docopt import docopt | |
import semver | |
def compare(**kwargs): | |
return semver.compare(kwargs.get('<a>'), kwargs.get('<b>')) | |
def bump_major(**kwargs): | |
return semver.bump_major(kwargs.get('<a>')) | |
def bump_minor(**kwargs): | |
return semver.bump_minor(kwargs.get('<a>')) | |
def bump_patch(**kwargs): | |
return semver.bump_patch(kwargs.get('<a>')) | |
def _get_version(): | |
return __doc__.split('\n', 1)[0] | |
if __name__ == '__main__': | |
arguments = docopt(__doc__, version=_get_version()) | |
for argument, value in arguments.items(): | |
if( | |
value is True and | |
argument in locals() and | |
callable(locals()[argument]) | |
): | |
print locals()[argument](**arguments) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment