diff --git a/bumpversion/cli.py b/bumpversion/cli.py index 5a7d5317..236faf5b 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import argparse +import subprocess from datetime import datetime import io import itertools @@ -113,6 +114,8 @@ def main(original_args=None): config, config_file, config_newlines, config_file_exists, args.new_version, args.dry_run, ) + _run_commands(defaults, args.dry_run,) + # commit and tag if vcs: context = _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, current_version, new_version) @@ -270,7 +273,7 @@ def _load_configuration(config_file, explicit_config, defaults): defaults.update(dict(config.items("bumpversion"))) - for listvaluename in ("serialize",): + for listvaluename in ("serialize", 'commands'): try: value = config.get("bumpversion", listvaluename) defaults[listvaluename] = list( @@ -628,6 +631,15 @@ def _update_config_file( ) +def _run_commands(defaults, dry_run): + """Run additional default commands.""" + for command in defaults.get('commands', []): + if dry_run: + logger.info('Would run %s command', command) + else: + subprocess.check_output(command, shell=True) + + def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, current_version, new_version): commit_files = [f.path for f in files] if config_file_exists: