cloudmonkey: autocompletion for set/option values Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/0981f6c8 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/0981f6c8 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/0981f6c8 Branch: refs/heads/master Commit: 0981f6c82c93e252c2a6c0c44fbec9e8540d2c7f Parents: 3d08196 Author: Rohit Yadav <rohit.ya...@shapeblue.com> Authored: Fri Oct 3 14:03:02 2014 +0200 Committer: Rohit Yadav <rohit.ya...@shapeblue.com> Committed: Fri Oct 3 14:03:02 2014 +0200 ---------------------------------------------------------------------- cloudmonkey/cloudmonkey.py | 20 ++++++++++++++++---- cloudmonkey/config.py | 14 ++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/0981f6c8/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index 886381e..6801cef 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -71,6 +71,7 @@ class CloudMonkeyShell(cmd.Cmd, object): ". Type help or ? to list commands.\n") ruler = "=" config_options = [] + profile_names = [] verbs = [] prompt = "ðµ > " protocol = "http" @@ -446,10 +447,21 @@ class CloudMonkeyShell(cmd.Cmd, object): print def complete_set(self, text, line, begidx, endidx): - mline = line.partition(" ")[2] - offs = len(mline) - len(text) - return [s[offs:] for s in self.config_options - if s.startswith(mline)] + mline = line.partition(" ")[2].lstrip().partition(" ") + option = mline[0].strip() + separator = mline[1] + value = mline[2].lstrip() + if separator == "": + return [s for s in self.config_options if s.startswith(option)] + elif option == "profile": + return [s for s in self.profile_names if s.startswith(value)] + elif option == "display": + return [s for s in ["default", "table", "json"] + if s.startswith(value)] + elif option == "asyncblock" or option == "color": + return [s for s in ["true", "false"] if s.startswith(value)] + + return [] def do_login(self, args): """ http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/0981f6c8/cloudmonkey/config.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/config.py b/cloudmonkey/config.py index 6880c1a..3336274 100644 --- a/cloudmonkey/config.py +++ b/cloudmonkey/config.py @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. -__version__ = "5.2.0" +__version__ = "5.3.0" __description__ = "Command Line Interface for Apache CloudStack" __maintainer__ = "The Apache CloudStack Team" __maintaineremail__ = "d...@cloudstack.apache.org" @@ -69,8 +69,10 @@ default_profile['password'] = 'password' default_profile['apikey'] = '' default_profile['secretkey'] = '' + def write_config(get_attr, config_file): - global config_fields, mandatory_sections, default_profile, default_profile_name + global config_fields, mandatory_sections + global default_profile, default_profile_name config = ConfigParser() if os.path.exists(config_file): try: @@ -128,7 +130,8 @@ def write_config(get_attr, config_file): def read_config(get_attr, set_attr, config_file): - global config_fields, config_dir, mandatory_sections, default_profile, default_profile_name + global config_fields, config_dir, mandatory_sections + global default_profile, default_profile_name if not os.path.exists(config_dir): os.makedirs(config_dir) @@ -155,8 +158,11 @@ def read_config(get_attr, set_attr, config_file): print "Server profile cannot be", profile sys.exit(1) + set_attr("profile_names", filter(lambda x: x != "core" and x != "ui", + config.sections())) + if not config.has_section(profile): - print "Selected profile (%s) does not exit, will use the defaults" % profile + print "Selected profile (%s) does not exist, using defaults" % profile try: config.add_section(profile) except ValueError, e: