From 9dfd8da1c152419e0f0c187581b61264b74d4f11 Mon Sep 17 00:00:00 2001
From: Petr "Stone" Hracek <phracek@redhat.com>
Date: Jul 12 2017 12:11:20 +0000
Subject: [PATCH 1/2] use entry point. Delete contrib dir.


Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>

---

diff --git a/contrib/__init__.py b/contrib/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/contrib/__init__.py
+++ /dev/null
diff --git a/modtools b/modtools
index 9bfb6f7..5319e2f 100755
--- a/modtools
+++ b/modtools
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 import sys
-from contrib.modtools import ModtoolsCLIHelper
+from modularity.cli import ModtoolsCLIHelper
 
 
 if __name__ == "__main__":
diff --git a/modularity/cli.py b/modularity/cli.py
new file mode 100644
index 0000000..5b6f6fc
--- /dev/null
+++ b/modularity/cli.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python3
+
+import sys
+import argparse
+
+from modularity.module_generator import ModuleGenerator
+from modularity.oc_template import OpenShiftTemplateGenerator
+
+
+class ModtoolsCLI(object):
+    """ Class for processing data from commandline """
+
+    @staticmethod
+    def build_parser():
+        parser = argparse.ArgumentParser(description="Generates module related files")
+        subparsers = parser.add_subparsers(dest="cmd_name")
+
+        parser_rpm2module = subparsers.add_parser(
+            'rpm2module', help="Generates modulemd file",
+            description="Gets package info and dependencies and creates modulemd file."
+        )
+        parser_rpm2module.add_argument(
+            "pkgs",
+            metavar='PKGS',
+            nargs='+',
+            help="Specify list of packages for module.",
+        )
+
+        parser_docker2openshift = subparsers.add_parser(
+            "docker2openshift", help="Generates openshift template from dockerfile",
+            description="Creates an OpenShift template YAML file.",
+        )
+
+        parser_docker2openshift.add_argument(
+            "image",
+            metavar='IMAGE',
+            help="docker image name (like NAME or docker.io/USER/NAME)",
+        )
+        parser_docker2openshift.add_argument(
+            "--dockerfile",
+            help="Specify Dockerfile name. Default is Dockerfile."
+        )
+
+        return parser
+
+    def __init__(self, args=None):
+        self.parser = ModtoolsCLI.build_parser()
+        self.args = self.parser.parse_args(args)
+
+    def __getattr__(self, name):
+        try:
+            return getattr(self.args, name)
+        except AttributeError:
+            return object.__getattribute__(self, name)
+
+
+class ModtoolsCLIHelper(object):
+
+    @staticmethod
+    def run():
+        try:
+            cli = ModtoolsCLI(sys.argv[1:])
+            if cli.args.cmd_name == 'rpm2module':
+                mg = ModuleGenerator(cli.args.pkgs)
+                mg.run()
+
+            if cli.args.cmd_name == 'docker2openshift':
+                otg = OpenShiftTemplateGenerator(cli.args)
+                otg.run()
+        except KeyboardInterrupt:
+            print('\nInterrupted by user')
+        except Exception as e:
+            print(e)
+            sys.exit(1)
diff --git a/setup.py b/setup.py
index f5fa086..83a1353 100644
--- a/setup.py
+++ b/setup.py
@@ -7,16 +7,21 @@ except ImportError:
     from distutils.core import setup
 
 setup(
-      name='modtools',
-      version='0.0.1',
-      author='Dominika Hodovska',
-      author_email='dhodovsk@redhat.com',
-      description='Utilities for creating and managing modules',
-      long_description='Modtools now provides tools generating openshift templates from module Dockerfiles'
-                       'and creating modulemd files from package names (intended api of module).',
-      license='MIT',
-      keywords='modularization modularity module modulemd openshift template docker',
-      url='https://pagure.io/modularity/modularity-tools',
-      scripts=['modtools'],
-      packages=find_packages(),
+    name='modtools',
+    version='0.0.1',
+    author='Dominika Hodovska',
+    author_email='dhodovsk@redhat.com',
+    description='Utilities for creating and managing modules',
+    long_description='Modtools now provides tools generating openshift templates from module Dockerfiles'
+                   'and creating modulemd files from package names (intended api of module).',
+    license='MIT',
+    keywords='modularization modularity module modulemd openshift template docker',
+    url='https://pagure.io/modularity/modularity-tools',
+    scripts=['modtools'],
+    entry_point={
+        'console_scripts': [
+            'modtools=modularity.cli.ModtoolsCliHelper.run'
+        ]
+    },
+    packages=find_packages(),
 )

From 6f5e4c48925d3fac6017d05de0d8c87ee358b803 Mon Sep 17 00:00:00 2001
From: Petr "Stone" Hracek <phracek@redhat.com>
Date: Jul 12 2017 14:31:52 +0000
Subject: [PATCH 2/2] Remove shebang from the cli.py file.


Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>

---

diff --git a/modularity/cli.py b/modularity/cli.py
index 5b6f6fc..4bcd9a9 100644
--- a/modularity/cli.py
+++ b/modularity/cli.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python3
-
 import sys
 import argparse
 

