This commit is contained in:
2026-07-23 18:19:29 +02:00
parent a67d060fc6
commit 4cd70eda33
2 changed files with 19 additions and 38 deletions
+19 -15
View File
@@ -107,25 +107,29 @@ export function parseCommand(input: string): ParsedCommand {
let pastEndOfOptions = false; let pastEndOfOptions = false;
tokens.shift(); for (let i = 1; i < tokens.length; i++) {
const token = tokens[i]!;
for (const token of tokens) {
if (token === "--") pastEndOfOptions = true;
if (pastEndOfOptions) { if (pastEndOfOptions) {
args.push(token); args.push(token);
} else { continue;
if (token.startsWith("--")) { }
flags.push(token.slice(2)); if (token === "--") {
} else if (token.startsWith("-")) { pastEndOfOptions = true;
const newToken = token.slice(1); continue;
const chars = newToken.split(""); }
for (const flag of chars) {
flags.push(flag); if (token.startsWith("--")) {
} flags.push(token.slice(2));
} else { continue;
args.push(token); } else if (token.startsWith("-")) {
for (const char of token.slice(1)) {
flags.push(char);
} }
continue;
} else {
args.push(token);
continue;
} }
} }
-23
View File
@@ -1,25 +1,2 @@
import { parseCommand } from "@core/util/parser";
const message: string = "Hello, World!"; const message: string = "Hello, World!";
console.log(message); console.log(message);
// prettier-ignore
{
//console.log(parseCommand('ls'))
//console.log(parseCommand('ls /tmp'))
//console.log(parseCommand('ls -l'))
//console.log(parseCommand('ls -la'))
//console.log(parseCommand('ls -la /tmp'))
//console.log(parseCommand('ls -l -a'))
//console.log(parseCommand('grep --color=auto'))
//console.log(parseCommand('grep --color=auto -r'))
console.log(parseCommand('echo -- --version'))
console.log(parseCommand('echo -- -f'))
console.log(parseCommand('echo --'))
console.log(parseCommand("echo 'hello world'"))
console.log(parseCommand(`echo \\"hello world\\"`))
console.log(parseCommand(`echo 'it\\'s a test'`))
console.log(parseCommand("echo \"it's a \\\"test\\\"\""))
console.log(parseCommand("ls -la -- --tmp"))
console.log(parseCommand("rm -rf --no-preserve-root /"))
}