...
This commit is contained in:
+14
-10
@@ -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 === "--") {
|
||||||
|
pastEndOfOptions = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (token.startsWith("--")) {
|
if (token.startsWith("--")) {
|
||||||
flags.push(token.slice(2));
|
flags.push(token.slice(2));
|
||||||
|
continue;
|
||||||
} else if (token.startsWith("-")) {
|
} else if (token.startsWith("-")) {
|
||||||
const newToken = token.slice(1);
|
for (const char of token.slice(1)) {
|
||||||
const chars = newToken.split("");
|
flags.push(char);
|
||||||
for (const flag of chars) {
|
|
||||||
flags.push(flag);
|
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
args.push(token);
|
args.push(token);
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 /"))
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user