Repository: duckinator/emanate

Issue:
Support `--version`
At the moment only `emanate version` works, not `emanate --version`.

Discussion:

Patch:
diff --git a/.cirrus.yml b/.cirrus.yml
index 9a7d118..b3c3fa6 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -74,31 +74,3 @@ Windows_task:
   script:
     - C:\Python\python.exe --version
     - bork run test
-
-
-# If emanate/version.py is modified on the master branch, make a release.
-Release_task:
-  only_if: "changesInclude('emanate/version.py') && $BRANCH == 'master' && $CIRRUS_CRON == ''"
-  depends_on:
-    - Lint
-    - Linux
-    - macOS
-    - FreeBSD
-    - Windows
-  env:
-    TWINE_USERNAME: "__token__"
-    TWINE_PASSWORD: ENCRYPTED[93940c854f7cb146391fdb3ef75ab7f8e229e83837f49fbcb52472bcf3f1d0265ed8629fd57204152e019af4c6b9354c]
-    BORK_GITHUB_TOKEN: ENCRYPTED[679e9111a081ade5978676e60c885be6d9fd08a1d37c73237686b575bd3a21892c8ca1dc29e99d6ed1e611915d7dc52b]
-  container:
-    image: python:3.8-slim
-  install_script:
-    - apt-get update
-    - apt-get install -y git
-    - pip3 install . .[testing]
-  build_script:
-    - bork clean
-    - bork build
-  test_script:
-    - bork run test
-  release_script:
-    - bork release
diff --git a/emanate/cli.py b/emanate/cli.py
index 97a4a6a..398bcb1 100644
--- a/emanate/cli.py
+++ b/emanate/cli.py
@@ -52,6 +52,12 @@ def _parse_args(args=None):
                            type=Path,
                            help="Configuration file to use.")
 
+    argparser.add_argument("--version",
+                           action="store_true",
+                           default=False,
+                           dest="version",
+                           help="Show version information and exit.")
+
     subcommands = argparser.add_subparsers(dest='command')
     subcommands.add_parser('clean')
     subcommands.add_parser('create')
@@ -74,6 +80,11 @@ def main(args=None):
     - command-line arguments override everything.
     """
     args = _parse_args(args)
+
+    if args.command == "version" or args.version:
+        version()
+        return
+
     if args.config is None:
         if 'source' in args:
             args.config = args.source / "emanate.json"
@@ -90,9 +101,6 @@ def main(args=None):
         execute = emanate.create()
     elif args.command == 'clean':
         execute = emanate.clean()
-    elif args.command == 'version':
-        version()
-        return
     else:
         raise AssertionError("emanate.main: Unknown command")
 


Test patch:
diff --git a/tests/test_version.py b/tests/test_version.py
new file mode 100644
index 0000000..5bffe4a
--- /dev/null
+++ b/tests/test_version.py
@@ -0,0 +1,17 @@
+from emanate import cli, __version__, __author__
+
+
+EXPECTED_VERSION = "Emanate v{} by {}.\n".format(__version__, __author__)
+
+
+def test_version_command(capsys):
+    cli.main(["version"])
+    captured = capsys.readouterr()
+    assert captured.out == EXPECTED_VERSION
+    assert not captured.err
+
+def test_version_flag(capsys):
+    cli.main(["--version"])
+    captured = capsys.readouterr()
+    assert captured.out == EXPECTED_VERSION
+    assert not captured.err