putout
Version:
🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json
67 lines (63 loc) • 1.33 kB
JavaScript
import yargsParser from 'yargs-parser';
const {isArray} = Array;
const maybeFirst = (a) => isArray(a) ? a.pop() : a;
const maybeArray = (a) => isArray(a) ? a : a.split(',');
export const argvConfig = {
configuration: {
'strip-aliased': true,
'strip-dashed': true,
},
coerce: {
format: maybeFirst,
plugins: maybeArray,
},
boolean: [
'ci',
'cache',
'version',
'help',
'fix',
'fresh',
'raw',
'worker',
'enable-all',
'disable-all',
'flow',
'config',
'staged',
'interactive',
],
number: ['fix-count'],
string: [
'format',
'disable',
'enable',
'rulesdir',
'transform',
'plugins',
'match',
],
alias: {
version: 'v',
help: 'h',
format: 'f',
staged: 's',
transform: 't',
interactive: 'i',
},
default: {
ci: true,
fix: false,
fixCount: 10,
config: true,
cache: true,
fresh: false,
enable: '',
disable: '',
disableAll: false,
enableAll: false,
worker: true,
plugins: [],
},
};
export const parseArgs = (argv) => yargsParser(argv, argvConfig);