From ffd7fcfeae274023070c5afabcedce2eee1aa28a Mon Sep 17 00:00:00 2001 From: Simon de Haan Date: Fri, 24 Oct 2014 08:26:40 +0200 Subject: [PATCH] simple versioning tool --- elasticgit/commands/tests/test_version.py | 23 ++++++++++++++ elasticgit/commands/version.py | 37 +++++++++++++++++++++++ elasticgit/tools.py | 2 ++ 3 files changed, 62 insertions(+) create mode 100644 elasticgit/commands/tests/test_version.py create mode 100644 elasticgit/commands/version.py diff --git a/elasticgit/commands/tests/test_version.py b/elasticgit/commands/tests/test_version.py new file mode 100644 index 0000000..e1dfe81 --- /dev/null +++ b/elasticgit/commands/tests/test_version.py @@ -0,0 +1,23 @@ +from StringIO import StringIO +import json + +from elasticgit import version_info +from elasticgit.tests.base import ToolBaseTest +from elasticgit.commands.version import VersionTool + + +class TestVersionTool(ToolBaseTest): + + def test_dump_version_info(self): + tool = VersionTool() + tool.stdout = StringIO() + tool.run('the name', 'the license', 'the author', 'the author url') + self.assertEqual( + json.loads(tool.stdout.getvalue()), + { + 'name': 'the name', + 'license': 'the license', + 'author': 'the author', + 'author_url': 'the author url', + 'version_info': version_info + }) diff --git a/elasticgit/commands/version.py b/elasticgit/commands/version.py new file mode 100644 index 0000000..1e405d4 --- /dev/null +++ b/elasticgit/commands/version.py @@ -0,0 +1,37 @@ +import sys +import json + +from elasticgit import version_info +from elasticgit.commands.base import ToolCommand, CommandArgument + + +class VersionTool(ToolCommand): + + command_name = 'version' + command_help_text = ('Tools for versioning & version checking ' + 'a content repository') + command_arguments = ( + CommandArgument( + '-n', '--name', + help='The name to give this repository', required=True), + CommandArgument( + '-l', '--license', + help='The license the publish this content under.', required=True), + CommandArgument( + '-a', '--author', + help='The author', required=True), + CommandArgument( + '-au', '--author-url', + help='The url where to find more information about the author'), + ) + + stdout = sys.stdout + + def run(self, name, license, author, author_url=None): + json.dump({ + 'name': name, + 'license': license, + 'author': author, + 'author_url': author_url, + 'version_info': version_info, + }, fp=self.stdout, indent=2) diff --git a/elasticgit/tools.py b/elasticgit/tools.py index 9c34146..5edf740 100644 --- a/elasticgit/tools.py +++ b/elasticgit/tools.py @@ -3,6 +3,7 @@ from elasticgit.commands.avro import SchemaDumper, SchemaLoader from elasticgit.commands.gitmodel import MigrateGitModelRepo from elasticgit.commands.shell import EGShell +from elasticgit.commands.version import VersionTool def add_command(subparsers, dispatcher_class): # pragma: no cover @@ -23,6 +24,7 @@ def get_parser(): # pragma: no cover add_command(subparsers, SchemaLoader) add_command(subparsers, MigrateGitModelRepo) add_command(subparsers, EGShell) + add_command(subparsers, VersionTool) return parser