Skip to content

Commit dd45811

Browse files
authored
feat: support single quote flags (#289)
1 parent 0ea1476 commit dd45811

File tree

2 files changed

+70
-31
lines changed

2 files changed

+70
-31
lines changed

src/deploy-cloudrun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export function setActionOutputs(outputs: DeployCloudRunOutputs): void {
238238
}
239239

240240
export function parseFlags(flags: string): RegExpMatchArray {
241-
return flags.match(/(".*?"|[^"\s=]+)+(?=\s*|\s*$)/g)!; // Split on space or "=" if not in quotes
241+
return flags.match(/(".*?"|'.*?'|[^"\s=]+)+(?=\s*|\s*$)/g)!; // Split on space or "=" if not in quotes
242242
}
243243

244244
// eslint-disable-next-line @typescript-eslint/no-explicit-any

tests/unit/deploy-cloudrun.test.ts

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -157,36 +157,75 @@ describe('#deploy-cloudrun', function () {
157157
});
158158
});
159159

160-
describe('#parseFlags', function () {
161-
it('parses flags using equals', async function () {
162-
const input = '--concurrency=2 --memory=2Gi';
163-
const results = parseFlags(input);
164-
expect(results).to.eql(['--concurrency', '2', '--memory', '2Gi']);
165-
});
166-
it('parses flags using spaces', async function () {
167-
const input = '--concurrency 2 --memory 2Gi';
168-
const results = parseFlags(input);
169-
expect(results).to.eql(['--concurrency', '2', '--memory', '2Gi']);
170-
});
171-
it('parses flags using combo', async function () {
172-
const input = '--concurrency 2 --memory=2Gi';
173-
const results = parseFlags(input);
174-
expect(results).to.eql(['--concurrency', '2', '--memory', '2Gi']);
175-
});
176-
it('parses flags using space and quotes combo', async function () {
177-
const input = '--concurrency 2 --memory="2 Gi"';
178-
const results = parseFlags(input);
179-
expect(results).to.eql(['--concurrency', '2', '--memory', '"2 Gi"']);
180-
});
181-
it('parses flags using space and quotes', async function () {
182-
const input = '--entry-point "node index.js"';
183-
const results = parseFlags(input);
184-
expect(results).to.eql(['--entry-point', '"node index.js"']);
185-
});
186-
it('parses flags using equals and quotes', async function () {
187-
const input = '--entry-point="node index.js"';
188-
const results = parseFlags(input);
189-
expect(results).to.eql(['--entry-point', '"node index.js"']);
160+
describe('#parseFlags', () => {
161+
const cases = [
162+
{
163+
name: `with equals`,
164+
input: `--concurrency=2 --memory=2Gi`,
165+
exp: [`--concurrency`, `2`, `--memory`, `2Gi`],
166+
},
167+
{
168+
name: `with spaces`,
169+
input: `--concurrency 2 --memory 2Gi`,
170+
exp: [`--concurrency`, `2`, `--memory`, `2Gi`],
171+
},
172+
{
173+
name: `with equals and spaces`,
174+
input: `--concurrency 2 --memory=2Gi`,
175+
exp: [`--concurrency`, `2`, `--memory`, `2Gi`],
176+
},
177+
{
178+
name: `with equals and double quotes`,
179+
input: `--memory="2Gi"`,
180+
exp: [`--memory`, `"2Gi"`],
181+
},
182+
{
183+
name: `with space and double quotes`,
184+
input: `--memory "2Gi"`,
185+
exp: [`--memory`, `"2Gi"`],
186+
},
187+
{
188+
name: `with equals and space and double quotes`,
189+
input: `--memory="2Gi" --concurrency "2"`,
190+
exp: [`--memory`, `"2Gi"`, `--concurrency`, `"2"`],
191+
},
192+
{
193+
name: `with equals and space and some double quotes`,
194+
input: `--memory="2Gi" --concurrency 2`,
195+
exp: [`--memory`, `"2Gi"`, `--concurrency`, `2`],
196+
},
197+
{
198+
name: `with equals and single quotes`,
199+
input: `--memory='2Gi'`,
200+
exp: [`--memory`, `'2Gi'`],
201+
},
202+
{
203+
name: `with space and single quotes`,
204+
input: `--memory '2Gi'`,
205+
exp: [`--memory`, `'2Gi'`],
206+
},
207+
{
208+
name: `with equals and space and single quotes`,
209+
input: `--memory='2Gi' --concurrency '2'`,
210+
exp: [`--memory`, `'2Gi'`, `--concurrency`, `'2'`],
211+
},
212+
{
213+
name: `with equals and space and some single quotes`,
214+
input: `--memory='2Gi' --concurrency 2`,
215+
exp: [`--memory`, `'2Gi'`, `--concurrency`, `2`],
216+
},
217+
{
218+
name: `with double and single quotes`,
219+
input: `--memory='2Gi' --concurrency="2"`,
220+
exp: [`--memory`, `'2Gi'`, `--concurrency`, `"2"`],
221+
},
222+
];
223+
224+
cases.forEach((tc) => {
225+
it(tc.name, () => {
226+
const result = parseFlags(tc.input);
227+
expect(result).to.eql(tc.exp);
228+
});
190229
});
191230
});
192231
});

0 commit comments

Comments
 (0)