node_modules/snyk/dist/cli/293.index.js
/**
 * Parse CLI --tags options into an internal data structure.
 *
 * If this returns undefined, it means "do not touch the existing tags on the project".
 *
 * Anything else means "replace existing tags on the project with this list" even if empty.
 *
 * @param options CLI options
 * @returns List of parsed tags or undefined if they are to be left untouched.
 */
Parse CLI --tags options into an internal data structure.
If this returns undefined, it means "do not touch the existing tags on the project".

Anything else means "replace existing tags on the project with this list" even if empty.

@param options CLI options
@returns List of parsed tags or undefined if they are to be left untouched.
Parse CLI -- tags options into an internal data structure . If this returns undefined it means " do not touch the existing tags on the project " . Anything else means " replace existing tags on the project with this list " even if empty . @param options CLI options @returns List of parsed tags or undefined if they are to be left untouched .
function generateTags(options) {
    if (options['project-tags'] === undefined && options['tags'] === undefined) {
        return undefined;
    }
    if (options['project-tags'] !== undefined && options['tags'] !== undefined) {
        throw new errors_1.ValidationError('Only one of --tags or --project-tags may be specified, not both');
    }
    const rawTags = options['tags'] === undefined ? options['project-tags'] : options['tags'];
    if (rawTags === '') {
        return [];
    }
    if (rawTags === true) {
        throw new errors_1.ValidationError(`--project-tags must contain an '=' with a comma-separated list of pairs (also separated with an '='). To clear all existing values, pass no values i.e. --project-tags=`);
    }
    const keyEqualsValuePairs = rawTags.split(',');
    const tags = [];
    for (const keyEqualsValue of keyEqualsValuePairs) {
        const parts = keyEqualsValue.split('=');
        if (parts.length !== 2) {
            throw new errors_1.ValidationError(`The tag "${keyEqualsValue}" does not have an "=" separating the key and value. For example: --project-tag=KEY=VALUE`);
        }
        tags.push({
            key: parts[0],
            value: parts[1],
        });
    }
    return tags;
}
function generateTags ( options ) { if ( options [ 'project-tags' ] === undefined && options [ 'tags' ] === undefined ) { return undefined ; } if ( options [ 'project-tags' ] !== undefined && options [ 'tags' ] !== undefined ) { throw new errors_1 . ValidationError ( 'Only one of --tags or --project-tags may be specified, not both' ) ; } const rawTags = options [ 'tags' ] === undefined ? options [ 'project-tags' ] : options [ 'tags' ] ; if ( rawTags === '' ) { return [ ] ; } if ( rawTags === true ) { throw new errors_1 . ValidationError ( ` ` ) ; } const keyEqualsValuePairs = rawTags . split ( ',' ) ; const tags = [ ] ; for ( const keyEqualsValue of keyEqualsValuePairs ) { const parts = keyEqualsValue . split ( '=' ) ; if ( parts . length !== 2 ) { throw new errors_1 . ValidationError ( ` ${ keyEqualsValue } ` ) ; } tags . push ( { key : parts [ 0 ] , value : parts [ 1 ] , } ) ; } return tags ; }
Parse CLI --tags options into an internal data structure.
Parse CLI -- tags options into an internal data structure .
// When it's specified without the =, we raise an explicit error to avoid // accidentally clearing the existing tags;