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'); });
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('jobs') .description('List all completed jobs') .option('--completed', 'Show completed jobs') .option('--failed', 'Show failed jobs') .option('-l, --limit [limit]', 'Limit how many jobs to show') .action(function (options) { openConfig() return listJobs(queue, options.failed, options.completed, options.limit) .then(function() { queue.close() process.exit(0) }) .catch(handleDbError) })
program .command('shift') .description('Run the next job in the queue') .action(function (url) { openConfig() var maxTries = configuration.queue.generationMaxTries var retryStrategy = configuration.queue.generationRetryStrategy return queue.getNext(retryStrategy, maxTries) .then(function (next) { if (!next) { queue.close() process.exit(0) } return processJob(next, configuration) }) .catch(handleDbError) })
program .command('purge') .description('Will remove all completed jobs') .option('--failed', 'Remove all failed jobs') .option('--new', 'Remove all new jobs') .action(function (options) { openConfig() return queue.purge(options.failed, options.new) .then(function () { queue.close() console.log('The queue was purged.') process.exit(0) }) .catch(handleDbError) })
program .command('token') .option('-e, --expiry [expiry]', 'Token expiry. Set to 0 for no expiry', defaultExpiry) .option('-s, --secret [secret]', 'Cube.js app secret. Also can be set via environment variable CUBEJS_API_SECRET') .option('-p, --payload [values]', 'Payload. Example: -p foo=bar', collect, []) .description('Create JWT token') .action( (options) => token(options) .catch(e => displayError(e.stack || e)) ) .on('--help', () => { console.log(''); console.log('Examples:'); console.log(''); console.log(' $ cubejs token -e "1 day" -p foo=bar -p cool=true'); });
program .command('api') .description('Start the API') .action(function (options) { // We delay initiation of queue. This is because the API will load the DB in memory as // copy A. When we make changes through the CLI this creates copy B. But next time the // user pushes to the queue using the API copy A will be persisted again. var initiateQueue = openConfig(true) var apiOptions = configuration.api var port = apiOptions.port createApi(initiateQueue, { port: port, postPushCommand: apiOptions.postPushCommand, token: apiOptions.token }).listen(port, function() { debug('Listening to port %d', port) }) })
program .command('ping:retry-failed') .action(function() { openConfig() var maxTries = configuration.queue.webhookMaxTries var retryStrategy = configuration.queue.webhookRetryStrategy queue.getNextWithoutSuccessfulPing(retryStrategy, maxTries) .then(function (next) { if (!next) { queue.close() process.exit(0) } return ping(next, configuration.webhook).then(function (response) { queue.close() if (response.error) { process.exit(1) } else { process.exit(0) } }) }) .catch(handleDbError) })
program .command('push [url]') .description('Push new job to the queue') .option('-m, --meta [meta]', 'JSON string with meta data. Default: \'{}\'') .action(function (url, options) { openConfig() return queue .addToQueue({ url: url, meta: JSON.parse(options.meta || '{}') }) .then(function (response) { queue.close() if (error.isError(response)) { console.error('Could not push to queue: %s', response.message) process.exit(1) } else { console.log('The job was created with ID ' + response.id) process.exit(0) } }) .catch(handleDbError) })
cli .command('listen') .alias('l') .description('start the server and listen for requests') .option('-H, --host <host>', 'host') .option('-p, --port <port>', 'port number', Polly.Defaults.port) .option( '-n, --api-namespace <namespace>', 'api namespace', Polly.Defaults.apiNamespace ) .option( '-d, --recordings-dir <path>', 'recordings directory', Polly.Defaults.recordingsDir ) .option( '-s, --recording-size-limit <limit>', 'recording size limit', Polly.Defaults.recordingSizeLimit ) .option('-q, --quiet', 'disable the logging') .action(function(options) { new Polly.Server(options).listen(); });
program .command('ping [jobID]') .description('Attempt to ping webhook for job') .action(function (jobId, options) { openConfig() return queue.getById(jobId) .then(function (job) { if (!job) { queue.close() console.log('Job not found.') return; } return ping(job, configuration.webhook).then(response => { queue.close() if (response.error) { process.exit(1) } else { 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 .command('generate [jobID]') .description('Generate PDF for job') .action(function (jobId, options){ openConfig() return queue.getById(jobId) .then(function (job) { if (!job) { console.error('Job not found') queue.close() process.exit(1) } return processJob(job, configuration) }) .catch(handleDbError) })
program .command('create <name>') .option( '-d, --db-type <db-type>', 'Preconfigure for selected database.\n\t\t\t ' + 'Options: postgres, mysql, mongobi, athena, redshift, bigquery, mssql, clickhouse, snowflake, presto' ) .option('-t, --template <template>', 'App template. Options: express (default), serverless.') .description('Create new Cube.js app') .action( (projectName, options) => createApp(projectName, options) .catch(e => displayError(e.stack || e, { projectName, dbType: options.dbType })) ) .on('--help', () => { console.log(''); console.log('Examples:'); console.log(''); console.log(' $ cubejs create hello-world -d postgres'); });
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'); });