, completion: function(){ var tab = require('tabtab'); return tab.complete('twei', function(err, data){ if(err || !data) return; var words = Object.keys(cmdMap).concat(Object.keys(aliases)).sort(); if(words.indexOf(data.prev) == -1 || data.prev == 'help'){ tab.log(words, data) }else if(data.last.indexOf('-') === 0){ //TODO: show options } }); }
var _completion = function(){ tabtab.complete('fhc', function(err, data) { if (err || !data){ return; } /* // TODO: we can extend tab completion here as needed - add our flags like this: if(/^--\w?/.test(data.last)) return tabtab.log(['help', 'version'], data, '--'); ..even out subcommands can go here */ var cmdList = _.filter(_.keys(fhc), function(key){ return key[0] !== '_'; }); tabtab.log(cmdList, data); }); }
return (function () { var tabtab = require("tabtab"); var completeCallback = function (err, data) { if (err || !data) { return; } var commands = _this.$injector.getRegisteredCommandsNames(false); var splittedLine = data.line.split(/[ ]+/); var line = _.filter(splittedLine, function (w) { return w !== ""; }); var commandName = (line[line.length - 2]); var childrenCommands = _this.$injector.getChildrenCommandsNames(commandName); if (data.last && _.startsWith(data.last, "--")) { return tabtab.log(_.keys(_this.$options.options), data, "--"); } if (data.last && _.startsWith(data.last, "-")) { return tabtab.log(_this.$options.shorthands, data, "-"); } if (data.words === 1) { var allCommands = _this.allCommands({ includeDevCommands: false }); if (_.startsWith(data.last, _this.$commandsServiceProvider.dynamicCommandsPrefix)) { allCommands = allCommands.concat(_this.$commandsServiceProvider.getDynamicCommands().wait()); } return tabtab.log(allCommands, data); } if (data.words >= 2) { if (data.words !== line.length) { commandName = line[data.words - 2] + "|" + line[data.words - 1]; } else { commandName = "" + line[line.length - 1]; } } var command = _this.$injector.resolveCommand(commandName); if (command) { var completionData = command.completionData; if (completionData) { return tabtab.log(completionData, data); } else { return _this.logChildrenCommandsNames(commandName, commands, tabtab, data); } } else if (childrenCommands) { var nonDefaultSubCommands = _.reject(childrenCommands, function (children) { return children[0] === '*'; }); var sanitizedChildrenCommands = []; if (data.words !== line.length) { sanitizedChildrenCommands = nonDefaultSubCommands.map(function (commandToMap) { var pipePosition = commandToMap.indexOf("|"); return commandToMap.substring(0, pipePosition !== -1 ? pipePosition : commandToMap.length); }); } else { nonDefaultSubCommands = nonDefaultSubCommands.filter(function (commandNameToFilter) { return commandNameToFilter.indexOf("|") !== -1; }); sanitizedChildrenCommands = nonDefaultSubCommands.map(function (commandToMap) { var pipePosition = commandToMap.lastIndexOf("|"); return commandToMap.substring(pipePosition !== -1 ? pipePosition + 1 : 0, commandToMap.length); }); } return tabtab.log(sanitizedChildrenCommands, data); } else { return _this.logChildrenCommandsNames(commandName, commands, tabtab, data); } }; tabtab.complete(_this.$staticConfig.CLIENT_NAME.toLowerCase(), completeCallback); if (_this.$staticConfig.CLIENT_NAME_ALIAS) { tabtab.complete(_this.$staticConfig.CLIENT_NAME_ALIAS.toLowerCase(), completeCallback); } return true; }).future()();