UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

26 lines 1.11 kB
export const kebabCase = str => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').replace(/[_\s]+/g, '-').replace(/-+/g, '-').replace(/^-/, '').toLowerCase(); const createCliOptionEntries = options => Object.entries(options).flatMap(([key, value]) => { if (value === false || value === undefined || value === null) { return []; } const optionName = `--${kebabCase(key)}`; if (value === true) { return [[optionName]]; } if (Array.isArray(value)) { return value.map(entry => [optionName, String(entry)]); } return [[optionName, String(value)]]; }); const quoteCliValue = value => { const stringValue = String(value); if (stringValue.length === 0) { return '""'; } if (!/[\s"']/u.test(stringValue)) { return stringValue; } return `"${stringValue.replace(/"/g, '\\"')}"`; }; export const serializeCliOptionsToArgs = options => createCliOptionEntries(options).flatMap(entry => entry); export const serializeCliOptions = options => createCliOptionEntries(options).map(([optionName, value]) => value === undefined ? optionName : `${optionName} ${quoteCliValue(value)}`).join(' ');