fix: improve git args parsing

This commit is contained in:
Federico Grandi
2021-03-30 12:16:23 +02:00
parent 138434bf13
commit f4b07e6873
3 changed files with 30 additions and 9 deletions

View File

@@ -29,6 +29,19 @@ export function log(err: any | Error, data?: any) {
if (err) core.error(err)
}
/**
* Matches the different pathspecs and arguments by removing spaces that are not inside quotes
* @example
* ```js
* matchGitArgs(' first second "third" \'fourth\'') => [ 'first', 'second', '"third"', "'fourth'" ]
* matchGitArgs(' ') => [ ]
* ```
* @returns An array, if there's no match it'll be empty
*/
export function matchGitArgs(string: string) {
return string.match(/(?:[^\s"]+|"[^"]*")+/g) || []
}
export function parseBool(value: any) {
try {
const parsed = JSON.parse(value)