/** * Copyright (c) 2026, Salesforce, Inc., * All rights reserved. * For full license text, see the LICENSE.txt file */ /** * Split a command line into tokens, honoring single and double quotes. * A quote only opens a quoted span at a token boundary (when `current` is * empty); a quote char mid-token is kept literally. Shared by the CLI * `chain` command and the MCP `sf_gql_raw` parser. */ export function tokenizeCommand(input: string): string[] { const tokens: string[] = []; let current = ""; let inSingle = false; let inDouble = false; for (const ch of input) { if (ch === "'" && !inDouble) { if (!inSingle && current.length > 0) { current += ch; } else { inSingle = !inSingle; } } else if (ch === '"' && !inSingle) { if (!inDouble && current.length > 0) { current += ch; } else { inDouble = !inDouble; } } else if (ch === " " && !inSingle && !inDouble) { if (current) { tokens.push(current); current = ""; } } else { current += ch; } } if (current) tokens.push(current); return tokens; }