// Error enhancements program .option( '--show-error-stack [json|string]', 'show JavaScript error stacks in the GraphQL result errors (recommended in development)', ) .option( '--extended-errors <string>', "a comma separated list of extended Postgres error fields to display in the GraphQL result. Recommended in development: 'hint,detail,errcode'. Default: none", (option: string) => option.split(',').filter(_ => _), );
it('should fail in action as port is invalid', done => { commander.loadDefinitions(testDefinitions); expect(() => { commander.parse(['node', './CLI.spec.js', '--arg0', 'arg0Value'], { PROGRAM_ARG_0: 'arg0ENVValue', PROGRAM_ARG_1: 'arg1ENVValue', PROGRAM_ARG_2: 'hello', }); }).toThrow('arg2 is invalid'); done(); });
program .usage('<command> [options]') .on('--help', () => { console.log(''); console.log('Use cubejs <command> --help for more information about a command.'); console.log(''); });
program .command('db:migrate') .action(function() { openConfig() var db = configuration.db(configuration) return db.migrate() .then(function () { console.log('The database was migrated') db.close() process.exit(0) }) .catch(handleDbError) })
program .command('generate') .option('-t, --tables <tables>', 'Comma delimited list of tables to generate schema from', list) .description('Generate Cube.js schema from DB tables schema') .action( (options) => generateSchema(options).catch(e => displayError(e.stack || e, { dbType: options.dbType })) ) .on('--help', () => { console.log(''); console.log('Examples:'); console.log(''); console.log(' $ cubejs generate -t orders,customers'); });
program.option("-s, --settings [settings]", "Overrides layout settings for given view types", (settings) => { const res = parseSettings(settings); if (res.error) { exitWithError(res.error); } return res.result; }, {} );
it('should load config from apps', done => { spyOn(console, 'log').and.callFake(() => {}); commander.loadDefinitions(testDefinitions); commander.parse([ 'node', './CLI.spec.js', './spec/configs/CLIConfigApps.json', ]); const options = commander.getOptions(); expect(options.arg1).toBe('my_app'); expect(options.arg2).toBe(8888); expect(options.arg3).toBe('hello'); //config value expect(options.arg4).toBe('/1'); done(); });
it('should load properly definitions from env', done => { commander.loadDefinitions(testDefinitions); commander.parse([], { PROGRAM_ARG_0: 'arg0ENVValue', PROGRAM_ARG_1: 'arg1ENVValue', PROGRAM_ARG_2: '3', }); expect(commander.arg0).toEqual('arg0ENVValue'); expect(commander.arg1).toEqual('arg1ENVValue'); expect(commander.arg2).toEqual(3); expect(commander.arg4).toEqual('arg4Value'); done(); });
export default function({ definitions, help, usage, start }) { program.loadDefinitions(definitions); if (usage) { program.usage(usage); } if (help) { program.on('--help', help); } program.parse(process.argv, process.env); const options = program.getOptions(); start(program, options, function() { logStartupOptions(options); }); }
function addFlag( optionString: string, description: string, parse?: (option: string) => mixed, ): AddFlagFn { program.option(optionString, description, parse); return addFlag; }
program .command('auth <token>') .description('Authenticate access to Cube Cloud') .action( (currentToken) => authenticate(currentToken) .catch(e => displayError(e.stack || e)) ) .on('--help', () => { console.log(''); console.log('Examples:'); console.log(''); console.log(' $ cubejs auth eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXBsb3ltZW50SWQiOiIxIiwidXJsIjoiaHR0cHM6Ly9leGFtcGxlcy5jdWJlY2xvdWQuZGV2IiwiaWF0IjoxNTE2MjM5MDIyfQ.La3MiuqfGigfzADl1wpxZ7jlb6dY60caezgqIOoHt-c'); console.log(' $ cubejs deploy'); });
program .command('deploy') .description('Deploy project to Cube Cloud') .action( (options) => deploy({ directory: process.cwd(), ...options }) .catch(e => displayError(e.stack || e)) ) .on('--help', () => { console.log(''); console.log('Examples:'); console.log(''); console.log(' $ cubejs deploy'); });
it('should fail when passing an invalid arguement', done => { commander.loadDefinitions(testDefinitions); expect(() => { commander.parse([ 'node', './CLI.spec.js', './spec/configs/CLIConfigUnknownArg.json', ]); }).toThrow('error: unknown option myArg'); done(); });
it('should fail when too many apps are set', done => { commander.loadDefinitions(testDefinitions); expect(() => { commander.parse([ 'node', './CLI.spec.js', './spec/configs/CLIConfigFailTooManyApps.json', ]); }).toThrow('Multiple apps are not supported'); done(); });