-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use `shell-quote` package instead of approximating behaviour with .split(" ") and .join(" ") * wrap shell-quote.parse to match our needs: - return string[], not including objects - passthrough glob patterns - throw when using non-simple commands * fix tests with incorrect CLI args formatting * fix linting * fix linting in c3
- Loading branch information
Showing
14 changed files
with
139 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import shellquote from "shell-quote"; | ||
|
||
export const quote = shellquote.quote; | ||
|
||
export function parse(cmd: string, env?: Record<string, string>): string[] { | ||
const entries = shellquote.parse(cmd, env); | ||
const argv: string[] = []; | ||
|
||
for (const entry of entries) { | ||
// use string entries, as is | ||
if (typeof entry === "string") { | ||
argv.push(entry); | ||
continue; | ||
} | ||
|
||
// ignore comments | ||
if ("comment" in entry) { | ||
continue; | ||
} | ||
|
||
// we don't want to resolve globs, passthrough the pattern unexpanded | ||
if (entry.op === "glob") { | ||
argv.push(entry.pattern); | ||
continue; | ||
} | ||
|
||
// any other entry.op is a ControlOperator (e.g. && or ||) we don't want to support | ||
throw new Error( | ||
`Only simple commands are supported, please don't use the "${entry.op}" operator in "${cmd}".` | ||
); | ||
} | ||
|
||
return argv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import shellquote from "shell-quote"; | ||
|
||
export const quote = shellquote.quote; | ||
|
||
export function parse(cmd: string, env?: Record<string, string>): string[] { | ||
const entries = shellquote.parse(cmd, env); | ||
const argv: string[] = []; | ||
|
||
for (const entry of entries) { | ||
// use string entries, as is | ||
if (typeof entry === "string") { | ||
argv.push(entry); | ||
continue; | ||
} | ||
|
||
// ignore comments | ||
if ("comment" in entry) { | ||
continue; | ||
} | ||
|
||
// we don't want to resolve globs, passthrough the pattern unexpanded | ||
if (entry.op === "glob") { | ||
argv.push(entry.pattern); | ||
continue; | ||
} | ||
|
||
// any other entry.op is a ControlOperator (e.g. && or ||) we don't want to support | ||
throw new Error( | ||
`Only simple commands are supported, please don't use the "${entry.op}" operator in "${cmd}".` | ||
); | ||
} | ||
|
||
return argv; | ||
} |
Oops, something went wrong.