Creates a CommandInvocation for given commandItem.
@returns {orion.Promise} A promise resolving to: commandItem with its "invocation" field set, or undefined if we failed
760166
function setInvocation(commandItem) {
			var command = commandItem.command;
			if (!command.visibleWhen || command.visibleWhen(item)) {
				commandItem.invocation = new mCommands.CommandInvocation(item, item, null, command, commandRegistry);
				return new Deferred().resolve(commandItem);
			} else if (typeof alternateItem === "function") {
				if (!alternateItemDeferred) {
					alternateItemDeferred = alternateItem();
				}
				return Deferred.when(alternateItemDeferred, function (newItem) {
					if (newItem && (item === pageItem)) {
						// there is an alternate, and it still applies to the current page target
						if (!command.visibleWhen || command.visibleWhen(newItem)) {
							commandItem.invocation = new mCommands.CommandInvocation(newItem, newItem, null, command, commandRegistry);
							return commandItem;
						}
					}
				});
			}
			return new Deferred().resolve();
		}
680785
function exposeThenNative(Browser, command) {
    var exposed = ['then', ucfirst(command)].join('');

    Browser.prototype[exposed] = function () {
        var args = arguments;
        ensureDriverCommand.call(this, command, 'exposeThenNative');

        this.then(function (next) {
            args = wrapArguments.call(this, args, chainAndErrorCallback, next);
            this._driver[command].apply(this._driver, args);
        });

        return this;
    };
}
1338113
function _createCommandHandler(commands) {
    return function(chatEvent, globalObject) {

        if (!chatEvent.command) {
            return;
        }

        var commandName = chatEvent.command;

        if (!globalObject.config.DubBotBase.areCommandsCaseSensitive) {
            commandName = commandName.toLowerCase();
        }

        for (var i = 0; i < commands.length; i++) {
            var command = commands[i];

            if (command.triggers.indexOf(commandName) >= 0) {
                if (command.minimumRole && chatEvent.userRole.level < command.minimumRole.level) {
                    // user doesn't have sufficient permissions; notify the command module if possible
                    if (command.insufficientPermissionsHandler) {
                        command.insufficientPermissionsHandler.call(command.context, chatEvent, globalObject);
                    }

                    continue;
                }

                command.handler.call(command.context, chatEvent, globalObject);
            }
        }
    };
}
232089
function CommandController(descriptor){

	Object.defineProperties(this, {
		name: {
			get: function(){
				return descriptor.name;
			}
		},
		description: {
			get: function(){
				return descriptor.description;
			}
		},
		CommandError: {
			get: function(){
				return LocalCommandError;
			}
		},
		RuntimeCommandError: {
			get: function (){
				return LocalRuntimeCommandError;
			}
		},
		errorLvl: {
			get: function(){
				return Object.create(CONST.errorLvl);
			}
		}
	});

	function LocalCommandError(message, level){
		CommandError.call(this, message, descriptor.name, level);
	}
	LocalCommandError.prototype = Object.create(CommandError.prototype);

	function LocalRuntimeCommandError(message){
		RuntimeCommandError.call(this, message, descriptor.name);
	}
	LocalRuntimeCommandError.prototype = Object.create(RuntimeCommandError.prototype);
}
1197913
public Object thenApply(InvocationContext ctx, VisitableCommand command,
                                    InvocationSuccessFunction function) {
      return addCallback(ctx, command, function);
   }
662468
function (callback) {
        debug('');

        self.commandDispatcher = new CommandDispatcher(self.tree, self.definitions.command, self.commandBumper);
        self.tree.defineOptions({
            retryOnConcurrencyTimeout: self.options.retryOnConcurrencyTimeout,
            snapshotThreshold: self.options.snapshotThreshold,
            snapshotThresholdMs: self.options.snapshotThresholdMs
          })
          .defineCommand(self.definitions.command)
          .defineEvent(self.definitions.event)
          .idGenerator(self.getNewId)
          .useEventStore(self.eventStore)
          .useAggregateLock(self.aggregateLock);

        if (self.getNewAggregateId) {
          self.tree.aggregateIdGenerator(self.getNewAggregateId);
        }

        callback(null);
      }
495215
protected CommandLine getOrCreateCommandLine() {
        try {
            CommandLine commandLine = (CommandLine) getProperty(COMMAND_LINE);
            if (commandLine == null) {
                commandLine = createCommandLine();
                // The script has a real property (a field or getter) but if we let Script.setProperty handle
                // this then it just gets stuffed into a binding that shadows the property.
                // This is somewhat related to other bugged behavior in Script wrt properties and bindings.
                // See http://jira.codehaus.org/browse/GROOVY-6582 for example.
                // The correct behavior for Script.setProperty would be to check whether
                // the property has a setter before creating a new script binding.
                this.getMetaClass().setProperty(this, COMMAND_LINE, commandLine);
            }
            return commandLine;
        } catch (MissingPropertyException mpe) {
            CommandLine commandLine = createCommandLine();
            // Since no property or binding already exists, we can use plain old setProperty here.
            setProperty(COMMAND_LINE, commandLine);
            return commandLine;
        }
    }
878909
private Object handleTxCommand(TxInvocationContext ctx, TransactionBoundaryCommand command) {
      if (trace) log.tracef("handleTxCommand for command %s, origin %s", command, getOrigin(ctx));
      updateTopologyId(command);

      return invokeNextAndHandle(ctx, command, handleTxReturn);
   }
1368733
function spawn(cmd, args, opts) {
  const spawn = require('child_process').spawn;
  const _ = require('lodash');
  return new Promise((resolve, reject) => {
    const p = spawn(cmd, typeof args === 'string' ? args.split(' ') : args, _.merge({stdio: argv.quiet ? ['ignore', 'pipe', 'pipe'] : ['ignore', 1, 2]}, opts));
    const out = [];
    if (p.stdout) {
      p.stdout.on('data', (chunk) => out.push(chunk));
    }
    if (p.stderr) {
      p.stderr.on('data', (chunk) => out.push(chunk));
    }
    p.on('close', (code, signal) => {
      if (code === 0) {
        console.info(cmd, 'ok status code', code, signal);
        resolve(code);
      } else {
        console.error(cmd, 'status code', code, signal);
        if (args.quiet) {
          // log output what has been captured
          console.log(out.join('\n'));
        }
        reject(`${cmd} failed with status code ${code} ${signal}`);
      }
    });
  });
}
777600
function generateRelatedLinks(serviceRegistry, item, exclusions, commandRegistry, alternateItem) {
		var globalArguments = arguments;
		var contentTypesCache;

		function getContentTypes() {
			if (contentTypesCache) {
				return contentTypesCache;
			}
			var contentTypeService = serviceRegistry.getService("orion.core.contentTypeRegistry"); //$NON-NLS-0$
			// TODO Shouldn't really be making service selection decisions at this level. See bug 337740
			if (!contentTypeService) {
				contentTypeService = new mContentTypes.ContentTypeRegistry(serviceRegistry);
				contentTypeService = serviceRegistry.getService("orion.core.contentTypeRegistry"); //$NON-NLS-0$
			}
			return contentTypeService.getContentTypes().then(function (ct) {
				contentTypesCache = ct;
				return contentTypesCache;
			});
		}
		function getServiceProperties(serviceReference) {
			var info = {}, keys = serviceReference.getPropertyKeys(), key;
			for (var i=0; i < keys.length; i++) {
				key = keys[i];
				info[key] = serviceReference.getProperty(key);
			}
			return info;
		}
		function getNavCommandRef(navCommandsRefs, id) {
			var commandRef = null;
			navCommandsRefs.some(function(ref) {
				if (id === ref.getProperty("id")) { //$NON-NLS-0$
					return !!(commandRef = ref);
				}
				return false;
			});
			return commandRef;
		}
		var alternateItemDeferred;
		/**
		 * Creates a CommandInvocation for given commandItem.
		 * @returns {orion.Promise} A promise resolving to: commandItem with its "invocation" field set, or undefined if we failed
		 */
		function setInvocation(commandItem) {
			var command = commandItem.command;
			if (!command.visibleWhen || command.visibleWhen(item)) {
				commandItem.invocation = new mCommands.CommandInvocation(item, item, null, command, commandRegistry);
				return new Deferred().resolve(commandItem);
			} else if (typeof alternateItem === "function") {
				if (!alternateItemDeferred) {
					alternateItemDeferred = alternateItem();
				}
				return Deferred.when(alternateItemDeferred, function (newItem) {
					if (newItem && (item === pageItem)) {
						// there is an alternate, and it still applies to the current page target
						if (!command.visibleWhen || command.visibleWhen(newItem)) {
							commandItem.invocation = new mCommands.CommandInvocation(newItem, newItem, null, command, commandRegistry);
							return commandItem;
						}
					}
				});
			}
			return new Deferred().resolve();
		}
		/**
		 * @returns {orion.Promise} resolving to a commandItem { relatedLink: Object, command: Command}
		*/
		function commandItem(relatedLink, commandOptionsPromise, command) {
			if (command) {
				return new Deferred().resolve({ relatedLink: relatedLink, command: command});
			}
			return commandOptionsPromise.then(function(commandOptions) {
				return { relatedLink: relatedLink, command: new mCommands.Command(commandOptions) };
			});
		}

		var contributedLinks = serviceRegistry && serviceRegistry.getServiceReferences("orion.page.link.related"); //$NON-NLS-0$
		if (!contributedLinks || contributedLinks.length === 0) {
			return;
		}

		var thisGlobalCommands = this;
		Deferred.when(getContentTypes(), function () {
			if (!customGlobalCommands.beforeGenerateRelatedLinks.apply(thisGlobalCommands, globalArguments)) {
				return;
			}

			// assemble the related links.
			var navCommands = serviceRegistry.getServiceReferences("orion.navigate.command"); //$NON-NLS-0$
			var deferredCommandItems = [];
			contributedLinks.forEach(function(contribution) {
				var info = getServiceProperties(contribution);
				if (!info.id) {
					return; // skip
				}
				// First see if we have a uriTemplate and name, which is enough to build a command internally.
				var commandOptionsPromise;
				if (((info.nls && info.nameKey) || info.name) && info.uriTemplate) {
					commandOptionsPromise = mExtensionCommands._createCommandOptions(info, contribution, serviceRegistry, contentTypesCache, true);
					deferredCommandItems.push(commandItem(info, commandOptionsPromise, null));
					return;
				}
				// Otherwise, check if this related link references an orion.navigate.command contribution
				var navRef = getNavCommandRef(navCommands, info.id);
				if (!navRef)
					return; // skip: no nav command

				// Build relatedLink info by merging the 2 contributions. info has "id", "category"; navInfo has everything else
				var navInfo = getServiceProperties(navRef), relatedLink = {};
				objects.mixin(relatedLink, navInfo, info); // {} <- navInfo <- info
				var command;
				if ((command = commandRegistry.findCommand(info.id))) {
					// A Command exists already, use it
					deferredCommandItems.push(commandItem(relatedLink, null, command));
				} else {
					// Create a new Command for the nav contribution
					commandOptionsPromise = mExtensionCommands._createCommandOptions(navInfo, navRef, serviceRegistry, contentTypesCache, true);
					deferredCommandItems.push(commandItem(relatedLink, commandOptionsPromise, null));
				}
			});

			function continueOnError(error) {
				return error;
			}

			Deferred.all(deferredCommandItems, continueOnError).then(function(commandItems) {
				commandItems.sort(function(a, b) {
					return a.command.name.localeCompare(b.command.name);
				});
				return Deferred.all(commandItems.map(setInvocation), continueOnError).then(function(invoked) {
					var nonInvoked = [];
					// Filter out any holes caused by setInvocation() failing
					invoked = invoked.filter(function(item, i) {
						if (item) {
							return true;
						}
						nonInvoked.push(commandItems[i]);
						return false;
					});
					// Finally pass the relatedLinks data to customGlobalCommands
					customGlobalCommands.addRelatedLinkCommands.call(thisGlobalCommands, commandRegistry, invoked, nonInvoked, exclusions);
					customGlobalCommands.afterGenerateRelatedLinks.apply(thisGlobalCommands, globalArguments);
				});
			});
		});
	}
354828
function execPromise (cmd) {
  if (isTest) {
    return Promise.resolve(cmd)
  }
  return new Promise((resolve, reject) => {
    exec(cmd, (err, stdout, stderr) => {
      if (err || stderr) reject(err || stderr)
      else resolve(stdout)
    })
  })
}
710581
function spawnObservable(command, args) {
  return Observable.create(observer => {
    const cmd = spawn(command, args);
    observer.next(''); // hack to kick things off, not every command will have a stdout
    cmd.stdout.on('data', (data) => { observer.next(data.toString('utf8')); });
    cmd.stderr.on('data', (data) => { observer.error(data.toString('utf8')); });
    cmd.on('close', (data) => { observer.complete(); });
  });
}
4431
def make_cmd_invocation(invocation, args, kwargs):
    
    if not invocation.endswith('/'):
        invocation += '/'
    if not invocation.startswith('/'):
        invocation = '/' + invocation

    cmd = invocation

    for arg in args:
        cmd += str(arg) + "/"

    rendered_kwargs = []
    for k, v in kwargs.items():
        rendered_kwargs.append("--%s=%s" % (k,v))
    
    return ['./giotto-cmd', cmd] + rendered_kwargs
1007192
function(C) {
        if (!ES.IsCallable(C)) {
          throw new TypeError('bad promise constructor');
        }
        var capability = this;
        var resolver = function(resolve, reject) {
          capability.resolve = resolve;
          capability.reject = reject;
        };
        capability.promise = ES.Construct(C, [resolver]);
        // see https://bugs.ecmascript.org/show_bug.cgi?id=2478
        if (!capability.promise._es6construct) {
          throw new TypeError('bad promise constructor');
        }
        if (!(ES.IsCallable(capability.resolve) &&
              ES.IsCallable(capability.reject))) {
          throw new TypeError('bad promise constructor');
        }
      }
1054759
function(eventType, commandClass)
	{
		if (!eventType) throw new Error('eventType cannot be undefined');
		if (!commandClass) throw new Error('commandClass for '+eventType+' cannot be undefined');
		
		if (this.__commands[eventType] && this.__commands[eventType].indexOf(commandClass) != -1)
		{
			return this;
		}
		
		this.__commands[eventType] = this.__commands[eventType] || [];
		this.__commands[eventType].push(commandClass);
		
		return this;
	}
1340347
function CommandCursor(cursor) {
    this.toArray = function (callback) {
      if (typeof callback !== 'function') {
        return new Promise(function(resolve,reject) {
          callback = function(err, items) {
            if (err) {
              return reject(err);
            }
            resolve(items);
          }
          cursor.toArray(getListCollectionsHandler(self, params, callback));
        });       
      }

      cursor.toArray(getListCollectionsHandler(self, params, callback));
    };
  }
1143514
function createObservable (cfg) {
    const {dir, taskSet, tasksToRun, watchMode, spawn, env, log} = cfg;

    const tasks = tasksToRun.map(taskName => {
        const commandList = taskSet[taskName];
        if (!commandList)
            throw new Error (`No such task name: ${taskName} was configured`);
        return commandList;
    });

    return createParallellCommandsExecutor (
        tasks,
        dir,
        env,
        watchMode,
        {spawn, log});
}