def _complete_command(self): retval = [] if self.current_word == self.command_name: # here means only cmd give operation is None _operations = set() apiOperations = self.openApiDataHandler.getApiOperations(self.command_name, self.version) import commandConfigure _configure = commandConfigure.commandConfigure() extensionOperations = _configure.getExtensionOperations(self.command_name) for item in apiOperations: _operations.add(item) if extensionOperations is not None: for item in extensionOperations: _operations.add(item) if self.openApiDataHandler.getApiOperations(self.command_name, self.version): retval = self._documented(_operations) # retval = self._documented(self.openApiDataHandler.getApiOperations(self.command_name, self.version)) elif self.current_word.startswith('-'): # this is complete the key and values retval = self._find_possible_options() else: # here means cmd give we need complete the operation # See if they have entered a partial command name _operations = set() apiOperations = self.openApiDataHandler.getApiOperations(self.command_name, self.version) import commandConfigure _configure = commandConfigure.commandConfigure() extensionOperations = _configure.getExtensionOperations(self.command_name) for item in apiOperations: _operations.add(item) if extensionOperations is not None: for item in extensionOperations: _operations.add(item) if self.openApiDataHandler.getApiOperations(self.command_name, self.version): retval = self._documented(_operations, startswith=self.current_word) # retval = self._documented(self.openApiDataHandler.getApiOperations(self.command_name, self.version), # startswith=self.current_word) return retval
def _find_possible_options(self): all_options = copy.copy(self.main_options) # here give all attribute list # where code run here , self.version should be decide before # self.subcommand_name = self.operation # cmdInstance = self.openApiDataHandler.getInstanceByCmd(self.command_name, self.operation, self.version) cmdInstance, mclassname = self.openApiDataHandler.getInstanceByCmdOperation(self.command_name, self.operation, self.version) # old_arg_list = self.openApiDataHandler.getAttrList(cmdInstance) old_arg_list = list() if cmdInstance is None: import commandConfigure _configure = commandConfigure.commandConfigure() old_arg_list = _configure.getExtensionOptions(self.command_name, self.operation) else: old_arg_list = self.openApiDataHandler.getAttrList(mclassname) new_arg_list = set() if not old_arg_list is None: for item in old_arg_list: if not item.startswith('_'): new_arg_list.add(item) all_options = all_options + self._documented(new_arg_list) for opt in self.options: # Look thru list of options on cmdline. If there are # options that have already been specified and they are # not the current word, remove them from list of possibles. if opt != self.current_word: stripped_opt = opt.lstrip('-') if stripped_opt in all_options: all_options.remove(stripped_opt) cw = self.current_word.lstrip('-') possibles = ['--' + n for n in all_options if n.startswith(cw)] if len(possibles) == 1 and possibles[0] == self.current_word: return self._complete_option(possibles[0]) return possibles
def main(self): # fetch command cmd = self.parser.getCliCmd() extensionCmdList = self.extensionHandler.getAllExtensionCommands() if cmd in extensionCmdList: self.handlerExtensionCmd(cmd) return # fetch operation operation = self.parser.getCliOperation() # fetch paramlist keyValues = self.parser._getKeyValues() outPutFormat = self.parser.getOutPutFormat(keyValues) if outPutFormat is None or len(outPutFormat) == 0: outPutFormat = self.extensionHandler.getUserFormat() if outPutFormat is None or outPutFormat == "": outPutFormat = 'json' else: outPutFormat = outPutFormat[0] if self.handler.isEndPointOperation(operation): keyValues = self.parser.getOpenApiKeyValues(keyValues) self.handler.handleEndPointOperation(cmd, operation, keyValues) return if self.handler.isAvailableCmd(cmd): # fetch getversion if self.handler.isNonStandardSdkCmd(cmd): self.handler.nonStandardSdkCmdHandle(cmd) return version = self.handler.getSdkVersion(cmd, keyValues) if version is None: return # here handler the openapi cmd if self.handler.isAvailableOperation( cmd, operation, version): # cmd and operation both are right instanceAndClassName = self.handler.getInstanceByCmdOperation( cmd, operation, version) if instanceAndClassName is not None and len( instanceAndClassName) == 2: cmdInstance = instanceAndClassName[0] className = instanceAndClassName[1] if cmdInstance is not None and className is not None: if self.showInstanceAttribute(cmd, operation, className): return # here should handle the keyValues first keyValues = self.parser.getOpenApiKeyValues(keyValues) if self.handler.needSetDefaultRegion( cmdInstance, keyValues): keyValues["RegionId"] = [ self.extensionHandler.getUserRegion() ] #check necessaryArgs as:accesskeyid accesskeysecret regionId if not self.handler.hasNecessaryArgs(keyValues): print 'accesskeyid/accesskeysecret/regionId is absence' return try: result = self.handler.getResponse( cmd, operation, className, cmdInstance, keyValues) if result is None: return self.handler.responseOptimize( result, cmd, operation) if ("Code" in result): response.display_response( "error", result, "json") # print("failed") # print(result["Code"]) # print(result["Message"]) # print("Please check your parameters first.") else: #print(result) response.display_response( operation, result, outPutFormat, keyValues) except Exception as e: print(e) else: print 'aliyuncli internal error, please contact: xixi.xxx' elif self.handler.isAvailableExtensionOperation(cmd, operation): if self.args.__len__() >= 3 and self.args[2] == 'help': import commandConfigure configure = commandConfigure.commandConfigure() configure.showExtensionOperationHelp(cmd, operation) else: self.extensionHandler.handlerExtensionOperation( cmd, operation, version) # self.extensionHandler.handlerExtensionOperation(cmd,operation,version) else: # cmd is right but operation is not right self.helper.showOperationError(cmd, operation) else: self.helper.showCmdError(cmd)
def main(self): # fetch command cmd = self.parser.getCliCmd() extensionCmdList = self.extensionHandler.getAllExtensionCommands() if cmd in extensionCmdList: self.handlerExtensionCmd(cmd) return # fetch operation operation = self.parser.getCliOperation() # fetch paramlist keyValues = self.parser._getKeyValues() outPutFormat = self.parser.getOutPutFormat(keyValues) if outPutFormat is None or len(outPutFormat) == 0: outPutFormat = self.extensionHandler.getUserFormat() if outPutFormat is None or outPutFormat == "": outPutFormat = 'json' else: outPutFormat = outPutFormat[0] if self.handler.isAvailableCmd(cmd): # fetch getversion version=self.handler.getSdkVersion(cmd,keyValues) if version is None: return # here handler the openapi cmd if self.handler.isAvailableOperation(cmd, operation,version): # cmd and operation both are right instanceAndClassName=self.handler.getInstanceByCmdOperation(cmd, operation,version) if instanceAndClassName is not None and len(instanceAndClassName)==2: cmdInstance = instanceAndClassName[0] className = instanceAndClassName[1] if cmdInstance is not None and className is not None: if self.showInstanceAttribute(cmd, operation, className): return # here should handle the keyValues first keyValues = self.parser.getOpenApiKeyValues(keyValues) if self.handler.needSetDefaultRegion(cmdInstance, keyValues): keyValues["RegionId"] = [self.extensionHandler.getUserRegion()] #check necessaryArgs as:accesskeyid accesskeysecret regionId if not self.handler.hasNecessaryArgs(keyValues): print 'accesskeyid/accesskeysecret/regionId is absence' return try: result = self.handler.getResponse(cmd,operation,className,cmdInstance,keyValues) if result is None: return if("Code" in result): response.display_response("error", result, "json") # print("failed") # print(result["Code"]) # print(result["Message"]) # print("Please check your parameters first.") else: #print(result) response.display_response(operation, result, outPutFormat,keyValues) except Exception as e: print(e) else: print 'aliyuncli internal error, please contact: xixi.xxx' elif self.handler.isAvailableExtensionOperation(cmd, operation): if self.args.__len__() >= 3 and self.args[2] == 'help': import commandConfigure configure = commandConfigure.commandConfigure() configure.showExtensionOperationHelp(cmd, operation) else: self.extensionHandler.handlerExtensionOperation(cmd,operation,version) # self.extensionHandler.handlerExtensionOperation(cmd,operation,version) else: # cmd is right but operation is not right self.helper.showOperationError(cmd, operation) else: self.helper.showCmdError(cmd)