Skip to content

Commit 97fb6a0

Browse files
author
Richard
authored
feat: add support for long argument strings (#25)
* feat: Added basic support for long argument strings * refactored long argument parsing * Further refactoring of input parsing
1 parent 4914b78 commit 97fb6a0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/api/evalCommand.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { dispatchEvent, TerminalEvent } from '../helpers/events'
33

44
const evalCommand = (cmd: string, instance: TerminalInstance) => {
55
const { print } = instance
6-
const splitCommand = cmd.split(' ')
7-
const command = splitCommand[0]
8-
const commandArguments = splitCommand.slice(1)
9-
6+
const [command, ...args] = cmd.split(' ')
7+
const argMatches = args.join(' ').match(/('[^']+'|"[^"]+"|[^\s'"]+)/g)
8+
const commandArguments = argMatches === null
9+
? []
10+
: argMatches
11+
.map(element => element.replace(/(^['"]|['"]$)/g, ''))
1012
const commandInstance = instance.settings.commands[command]
1113

1214
if (commandInstance) {

0 commit comments

Comments
 (0)