Jump To

Command: jump-to

Description: Skip ahead in the pipeline to the named label, bypassing any commands in between.

Arguments

Notes

Will jump forward in the command queue to the label specified in the label argument.

http -url:http://domain.com/some/path
# Any error in the above will jump to one of the error labels below...
end

label -name:http-error-401
set -text:"You are not authorized to access this data"
jump-to label:format-error

label -name:http-error
set -text:"An error occured"
jump-to label:format-error

# ..then the two errors will jump forward to share the formatting logic
label -name:format-error
wrap -tag:div -class:error

Execution can only jump forward. It cannot jump backwards.

If the label is not found, it will do nothing and continue execution.

Source Code

function jumpTo(working, command, p) {
  const label = command.getArg("label");
  working.jumpto = label;
  return working.text;
}
jumpTo.title = "Jump To";
jumpTo.description =
  "Skip ahead in the pipeline to the named label, bypassing any commands in between.";
jumpTo.args = [
  {
    name: "label",
    type: "string",
    description: "The name of the label to jump to.",
  },
];
jumpTo.parseValidators = [
  {
    test: (command) => command.hasArg("label"),
    message: "You must provide a label to jump to.",
  },
];
jumpTo.passthrough = true;

export default jumpTo;