CLI: Added 'config' plugin.

The 'config' plugin will be used to read, validate, and potentially
write the Mesos CLI configuration file.

This commit adds the skeleton for the plugin as well as a simple
command to show the available plugins.

Review: https://reviews.apache.org/r/57952/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e370b099
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e370b099
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e370b099

Branch: refs/heads/master
Commit: e370b0997d8c20ffa205c8a9f58111051666b6d3
Parents: 8f13ad8
Author: Armand Grillet <[email protected]>
Authored: Thu Apr 13 18:40:00 2017 -0700
Committer: Joseph Wu <[email protected]>
Committed: Thu Apr 13 18:44:46 2017 -0700

----------------------------------------------------------------------
 src/cli_new/bin/settings.py                    |  4 +-
 src/cli_new/lib/cli/plugins/config/__init__.py | 22 +++++++
 src/cli_new/lib/cli/plugins/config/main.py     | 68 +++++++++++++++++++++
 3 files changed, 93 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e370b099/src/cli_new/bin/settings.py
----------------------------------------------------------------------
diff --git a/src/cli_new/bin/settings.py b/src/cli_new/bin/settings.py
index 8dbb160..0ef07cc 100644
--- a/src/cli_new/bin/settings.py
+++ b/src/cli_new/bin/settings.py
@@ -40,7 +40,9 @@ except Exception:
 PROJECT_DIR = os.path.join(os.path.dirname(__file__), os.pardir)
 
 # The builtin plugins.
-PLUGINS = []
+PLUGINS = [
+    os.path.join(PROJECT_DIR, "lib/mesos/plugins", "config")
+]
 
 MESOS_CLI_DEFAULT_CONFIG_PATH = os.path.join(
     os.path.expanduser("~"), ".mesos/config.toml")

http://git-wip-us.apache.org/repos/asf/mesos/blob/e370b099/src/cli_new/lib/cli/plugins/config/__init__.py
----------------------------------------------------------------------
diff --git a/src/cli_new/lib/cli/plugins/config/__init__.py 
b/src/cli_new/lib/cli/plugins/config/__init__.py
new file mode 100644
index 0000000..cf5673d
--- /dev/null
+++ b/src/cli_new/lib/cli/plugins/config/__init__.py
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Config module.
+"""
+
+# pylint: disable=wildcard-import
+from .main import *

http://git-wip-us.apache.org/repos/asf/mesos/blob/e370b099/src/cli_new/lib/cli/plugins/config/main.py
----------------------------------------------------------------------
diff --git a/src/cli_new/lib/cli/plugins/config/main.py 
b/src/cli_new/lib/cli/plugins/config/main.py
new file mode 100644
index 0000000..d95a36f
--- /dev/null
+++ b/src/cli_new/lib/cli/plugins/config/main.py
@@ -0,0 +1,68 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+The config plugin.
+"""
+
+import sys
+
+import settings
+import cli
+
+from cli.plugins import PluginBase
+from cli.util import Table
+
+
+PLUGIN_NAME = "config"
+PLUGIN_CLASS = "Config"
+
+VERSION = "Mesos CLI Config Plugin"
+
+SHORT_HELP = "Interacts with the Mesos CLI configuration file"
+
+
+class Config(PluginBase):
+    """
+    The config plugin.
+    """
+
+    COMMANDS = {
+        "plugins": {
+            "arguments": [],
+            "flags": {},
+            "short_help": "Print the plugins that can be used.",
+            "long_help": "Print the plugins that can be used."
+        }
+    }
+
+    def plugins(self, argv):
+        """
+        Parse and load the builtin plugins and the ones in the configuration
+        file. If this method is called using 'mesos config plugins', it
+        displays the plugins that can be used.
+        """
+        # pylint: disable=unused-argument
+        plugins_table = Table(["NAME", "DESCRIPTION"])
+
+        # Load the plugins
+        loaded_plugins = cli.util.import_modules(settings.PLUGINS, "plugins")
+        for plugin in loaded_plugins:
+            plugins_table.add_row([
+                cli.util.get_module(loaded_plugins, plugin).PLUGIN_NAME,
+                cli.util.get_module(loaded_plugins, plugin).SHORT_HELP
+            ])
+        sys.stdout.write("{}\n".format(plugins_table))

Reply via email to