"use strict"; /** * Copyright (c) 2022 Amorphous * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.createCommandObject = void 0; const split_line_by_spaces_with_quotes_1 = require("./split-line-by-spaces-with-quotes"); const createCommandObject = (line) => { if (!line.startsWith('$')) { throw new Error('$ shorthand must begin with an $ symbol'); } let trimmedCommand = line.substring(1).trim(); const commandParts = (0, split_line_by_spaces_with_quotes_1.splitLineBySpacesWithQuotes)(trimmedCommand).map((arg) => { if (arg.startsWith('"') && arg.endsWith('"')) { return arg.slice(1, arg.length - 1); } if (arg.startsWith("'") && arg.endsWith("'")) { return arg.slice(1, arg.length - 1); } return arg; }); let [command, ...params] = commandParts; return { type: 'command', text: trimmedCommand, name: command, args: params, }; }; exports.createCommandObject = createCommandObject;