- initial changes to data shapes

- ls command needs fixing
This commit is contained in:
2026-09-03 11:15:05 +02:00
parent 2e9227f6d8
commit 8a349330b0
12 changed files with 42 additions and 127 deletions
+1 -52
View File
@@ -6,13 +6,7 @@ interface UnclosedQuoteError {
timestamp: number;
}
interface ParsedCommand {
command: string;
flags: string[];
args: string[];
}
function tokenize(input: string): string[] {
export function tokenize(input: string): string[] {
enum State {
Normal,
SingleQuote,
@@ -98,48 +92,3 @@ function tokenize(input: string): string[] {
flushBuffer();
return tokens;
}
export function parseCommand(input: string): ParsedCommand {
const tokens = tokenize(input);
const command = tokens[0] ?? "";
const flags: string[] = [];
const args: string[] = [];
let pastEndOfOptions = false;
for (let i = 1; i < tokens.length; i++) {
const token = tokens[i]!;
if (pastEndOfOptions) {
args.push(token);
continue;
}
if (token === "--") {
pastEndOfOptions = true;
continue;
}
if (token.startsWith("--")) {
flags.push(token.slice(2));
continue;
} else if (token.startsWith("-")) {
if (token.includes("=")) {
flags.push(token.slice(1));
continue;
}
for (const char of token.slice(1)) {
flags.push(char);
}
continue;
} else {
args.push(token);
continue;
}
}
return {
command,
flags,
args,
};
}