Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Executes the command and ensures request.done is called on the request in
* case it's not marked to be done already or async.
*/
function execute() {
command.exec(env, request.args, request);
// If the request isn't asnync and isn't done, then make it done.
if (!request.isAsync && !request.isDone) {
request.done();
}
}
if (request.getStatus() == Status.INVALID) {
console.error("Canon.exec: Invalid parameter(s) passed to " +
command.name);
return false;
}
// If the request isn't complete yet, try to complete it.
else if (request.getStatus() == Status.INCOMPLETE) {
// Check if the sender has a ArgsProvider, otherwise use the default
// build in one.
var argsProvider;
var senderObj = env[sender];
if (!senderObj || !senderObj.getArgsProvider ||
!(argsProvider = senderObj.getArgsProvider()))
{
argsProvider = defaultArgsProvider;
}
this.isUpdating = true;
var input = {
typed: this.element.value,
cursor: {
start: dom.getSelectionStart(this.element),
end: dom.getSelectionEnd(this.element.selectionEnd)
}
};
this.cli.update(input);
var display = this.cli.getAssignmentAt(input.cursor.start).getHint();
// 1. Update the completer with prompt/error marker/TAB info
dom.removeCssClass(this.completer, Status.VALID.toString());
dom.removeCssClass(this.completer, Status.INCOMPLETE.toString());
dom.removeCssClass(this.completer, Status.INVALID.toString());
var completion = '<span class="cptPrompt">></span> ';
if (this.element.value.length > 0) {
var scores = this.cli.getInputStatusMarkup();
completion += this.markupStatusScore(scores);
}
// Display the "-> prediction" at the end of the completer
if (this.element.value.length > 0 &&
display.predictions && display.predictions.length > 0) {
var tab = display.predictions[0];
completion += ' ⇥ ' + (tab.name ? tab.name : tab);
}
this.completer.innerHTML = completion;
dom.addCssClass(this.completer, this.cli.getWorstHint().status.toString());
names.forEach(function(name) {
var assignment = this.getAssignment(name);
if (args.length === 0) {
// No more values
assignment.setValue(undefined); // i.e. default
}
else {
var arg = args[0];
args.splice(0, 1);
assignment.setArgument(arg);
}
}, this);
if (args.length > 0) {
var remaining = Argument.merge(args);
this._hints.push(new Hint(Status.INVALID,
'Input \'' + remaining.text + '\' makes no sense.',
remaining));
}
};
return Status.VALID;
} else {
return Status.INCOMPLETE;
}
}
// Check if the parameter value is valid.
var reply,
// The passed in value when parsing a type is a string.
argsValue = args[param.name].toString();
// Type.parse can throw errors.
try {
reply = param.type.parse(argsValue);
} catch (e) {
return Status.INVALID;
}
if (reply.status != Status.VALID) {
return reply.status;
}
}
// Check if the param is marked as required.
else if (param.defaultValue === undefined) {
// The parameter is not set on the args object but it's required,
// which means, things are invalid.
return Status.INCOMPLETE;
}
return Status.VALID;
}
var predictions;
// Non-valid conversions will have useful information to pass on
if (this.conversion) {
status = this.conversion.status;
if (this.conversion.message) {
message += this.conversion.message;
}
predictions = this.conversion.predictions;
}
// Hint if the param is required, but not provided
var argProvided = this.arg && this.arg.text !== '';
var dataProvided = this.value !== undefined || argProvided;
if (this.param.defaultValue === undefined && !dataProvided) {
status = Status.INVALID;
message += '<strong>Required<\strong>';
}
return new Hint(status, message, start, end, predictions);
},
</strong>
var predictions;
// Non-valid conversions will have useful information to pass on
if (this.conversion) {
status = this.conversion.status;
if (this.conversion.message) {
message += this.conversion.message;
}
predictions = this.conversion.predictions;
}
// Hint if the param is required, but not provided
var argProvided = this.arg && this.arg.text !== '';
var dataProvided = this.value !== undefined || argProvided;
if (this.param.defaultValue === undefined && !dataProvided) {
status = Status.INVALID;
message += '<strong>Required<\strong>';
}
return new Hint(status, message, start, end, predictions);
},
</strong>
this.isUpdating = true;
var input = {
typed: this.element.value,
cursor: {
start: this.element.selectionStart,
end: this.element.selectionEnd
}
};
this.cli.update(input);
var display = this.cli.getAssignmentAt(input.cursor.start).getHint();
// 1. Update the completer with prompt/error marker/TAB info
this.completer.classList.remove(Status.VALID.toString());
this.completer.classList.remove(Status.INCOMPLETE.toString());
this.completer.classList.remove(Status.INVALID.toString());
// TODO: borked implementation? This is modern browser only. Fix
// dom.removeCssClass(completer, Status.VALID.toString());
// dom.removeCssClass(completer, Status.INCOMPLETE.toString());
// dom.removeCssClass(completer, Status.INVALID.toString());
var completion = '<span class="cptPrompt">></span> ';
if (this.element.value.length > 0) {
var scores = this.cli.getInputStatusMarkup();
completion += this.markupStatusScore(scores);
}
// Display the "-> prediction" at the end of the completer
if (this.element.value.length > 0 &&
display.predictions && display.predictions.length > 0) {
var tab = display.predictions[0];
completion += ' ⇥ ' + (tab.name ? tab.name : tab);
CliRequisition.prototype._assign = function(args) {
if (args.length === 0) {
this.setDefaultValues();
return;
}
// Create an error if the command does not take parameters, but we have
// been given them ...
if (this.assignmentCount === 0) {
// TODO: previously we were doing some extra work to avoid this if
// we determined that we had args that were all whitespace, but
// probably given our tighter tokenize() this won't be an issue?
this._hints.push(new Hint(Status.INVALID,
this.commandAssignment.value.name +
' does not take any parameters',
Argument.merge(args)));
return;
}
// Special case: if there is only 1 parameter, and that's of type
// text we put all the params into the first param
if (this.assignmentCount === 1) {
var assignment = this.getAssignment(0);
if (assignment.param.type.name === 'text') {
assignment.setArgument(Argument.merge(args));
return;
}
}
this._hints.forEach(function(hint) {
var startInHint = c.start >= hint.start && c.start <= hint.end;
var endInHint = c.end >= hint.start && c.end <= hint.end;
var inHint = startInHint || endInHint;
if (!inHint && hint.status === Status.INCOMPLETE) {
hint.status = Status.INVALID;
}
}, this);
this._hints.forEach(function(hint) {
var startInHint = c.start >= hint.start && c.start <= hint.end;
var endInHint = c.end >= hint.start && c.end <= hint.end;
var inHint = startInHint || endInHint;
if (!inHint && hint.status === Status.INCOMPLETE) {
hint.status = Status.INVALID;
}
}, this);