Merge pull request #115 from crazy-max/input-comment-opt

util: comment opt for getInputList
This commit is contained in:
CrazyMax 2023-06-13 10:31:11 +02:00 committed by GitHub
commit 495c96b050
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -73,6 +73,18 @@ describe('getInputList', () => {
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('multiline and ignoring comment correctly', async () => {
setInput('labels', 'foo=bar\nbar=qux#baz');
const res = Util.getInputList('labels');
expect(res).toEqual(['foo=bar', 'bar=qux#baz']);
});
it('multiline with comment', async () => {
setInput('labels', 'foo=bar\nbar=qux#baz');
const res = Util.getInputList('labels', {comment: '#'});
expect(res).toEqual(['foo=bar', 'bar=qux']);
});
it('different new lines and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
const res = Util.getInputList('cache-from', {ignoreComma: true});

View File

@ -21,6 +21,7 @@ import {parse} from 'csv-parse/sync';
export interface InputListOpts {
ignoreComma?: boolean;
comment?: string;
quote?: string | boolean | Buffer | null;
}
@ -36,7 +37,7 @@ export class Util {
const records = parse(items, {
columns: false,
relaxQuotes: true,
comment: '#',
comment: opts?.comment,
relaxColumnCount: true,
skipEmptyLines: true,
quote: opts?.quote