Skip to content

Instantly share code, notes, and snippets.

@hannahherbig
Created May 23, 2018 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannahherbig/d87863f89f3f972cfb117e3e2f862c2c to your computer and use it in GitHub Desktop.
Save hannahherbig/d87863f89f3f972cfb117e3e2f862c2c to your computer and use it in GitHub Desktop.
import argparse
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument('-major', action='store_true')
group.add_argument('-minor', action='store_true')
group.add_argument('-patch', action='store_true')
parser.add_argument('--file', '-f', default='VERSION')
args = parser.parse_args()
try:
with open(args.file, 'r') as f:
version = f.read().strip()
except FileNotFoundError:
version = '0.0.0'
major, minor, patch = [int(x, 10) for x in version.split('.')]
if args.major:
major += 1
minor = 0
patch = 0
elif args.minor:
minor += 1
patch = 0
elif args.patch:
patch += 1
version = '%d.%d.%d' % (major, minor, patch)
with open(args.file, 'w') as f:
f.write('%s\n' % version)
print(version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment