ipld-schema-validator
Version:
IPLD Schema Validator
44 lines (39 loc) • 1.05 kB
JavaScript
import { toJS } from './to-js.mjs'
import Yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
const yargs = Yargs(hideBin(process.argv))
.scriptName('ipld-schema-validator')
.usage('$0 <cmd> [args]')
.command('to-js',
'Accepts .ipldsch files (from file or stdin) and prints a JavaScript module exporting validators for the types',
(yargs) => {
return yargs.option('type', {
default: 'module',
choices: ['module', 'script'],
type: 'string',
describe: 'export using "module" or "script" module exports style'
})
})
.showHelpOnFail(true)
.demandCommand(1, 'must provide a valid command')
.help()
/**
* @param {(files: string[], options: {})=>Promise<void>} fn
*/
function runCommand (fn) {
// @ts-ignore
const args = yargs.argv._.slice(1)
fn(args, yargs.argv).catch((err) => {
console.error(err)
process.exit(1)
})
}
// @ts-ignore
switch (yargs.argv._[0]) {
case 'to-js':
runCommand(toJS)
break
default:
yargs.showHelp()
}