Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/config/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ViewConfigCommand {
@Command('config:view {namespace}', {
desc: 'Command to view config for a given namespace',
})
async handle(_cli: ConsoleIO): Promise<void> {
async handle(_cli: ConsoleIO): Promise<boolean> {
const namespace = _cli.argument<string>('namespace');
const config = this.config.get(namespace);
if (!config) {
Expand All @@ -31,6 +31,6 @@ export class ViewConfigCommand {
// eslint-disable-next-line no-console
console.log(printRows.join('\n'));

process.exit();
return true;
}
}
9 changes: 5 additions & 4 deletions lib/console/commands/listCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CommandMeta } from '../metadata';
@Injectable()
@Command('list', { desc: 'Command to list all the commands' })
export class ListCommands {
public async handle(): Promise<void> {
public async handle(): Promise<boolean> {
const commands = CommandMeta.getAllCommands();

const list = [];
Expand All @@ -29,7 +29,9 @@ export class ListCommands {
const formattedRows = columnify(list, { padStart: 2 });
const groups = {};
for (const row of formattedRows) {
const group = Str.before(row[0], ':').trim();
const group = Str.contains(row[0], ':')
? Str.before(row[0], ':').trim()
: '#';
if (groups[group]) {
groups[group].push(row);
} else {
Expand Down Expand Up @@ -60,8 +62,7 @@ export class ListCommands {
);
console.log();
console.log(printRows.join('\n'));
console.log();

process.exit();
return true;
}
}
2 changes: 1 addition & 1 deletion lib/console/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface CommandMetaOptions {
}

export interface CommandObject extends ArgumentParserOutput {
target: (cli: ConsoleIO) => Promise<void>;
target: (cli: ConsoleIO) => Promise<void | boolean>;
expression: string;
meta: CommandMetaOptions;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/console/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class CommandRunner {
console.log(_cli);
}

await command.target(_cli);
const returnFromCommand = await command.target(_cli);
returnFromCommand && process.exit(1);

return;
}

Expand Down
30 changes: 15 additions & 15 deletions lib/database/commands/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class DbOperationsCommand {
@Command('migrate:status {--connection==}', {
desc: 'Command to show the status of all migrations',
})
async migrateStatus(_cli: ConsoleIO): Promise<void> {
async migrateStatus(_cli: ConsoleIO): Promise<void | boolean> {
const options = ObjectionService.config;

const conn = _cli.option<string>('connection') || options.default;
Expand All @@ -31,13 +31,13 @@ export class DbOperationsCommand {
}

_cli.table(['Migration', 'Status'], statusList);
process.exit();
return true;
}

@Command('migrate {--connection==}', {
desc: 'Command to run the pending migrations',
})
async migrationUp(_cli: ConsoleIO): Promise<void> {
async migrationUp(_cli: ConsoleIO): Promise<void | boolean> {
const options = ObjectionService.config;
const conn = _cli.option<string>('connection') || options.default;
const knex = ObjectionService.connection(conn);
Expand All @@ -49,21 +49,21 @@ export class DbOperationsCommand {

if (migrations.length === 0) {
_cli.info('No migrations to run');
process.exit();
return true;
}

_cli.info(`Batch Number: ${batch}`);
for (const migration of migrations) {
_cli.success(migration);
}

process.exit();
return true;
}

@Command('migrate:rollback {--connection==}', {
desc: 'Command to rollback the previous batch of migrations',
})
async migrateRollback(_cli: ConsoleIO) {
async migrateRollback(_cli: ConsoleIO): Promise<void | boolean> {
const options = ObjectionService.config;
const conn = _cli.option<string>('connection') || options.default;
const knex = ObjectionService.connection(conn);
Expand All @@ -75,21 +75,21 @@ export class DbOperationsCommand {

if (migrations.length === 0) {
_cli.info('No migrations to rollback. Already at the base migration');
process.exit();
return true;
}

_cli.info(`Reverted Batch: ${batch}`);
for (const migration of migrations) {
_cli.success(migration);
}

process.exit();
return true;
}

@Command('migrate:reset {--connection==}', {
desc: 'Command to reset the migration',
})
async migrateReset(_cli: ConsoleIO) {
async migrateReset(_cli: ConsoleIO): Promise<boolean> {
const options = ObjectionService.config;
const conn = _cli.option<string>('connection') || options.default;
const knex = ObjectionService.connection(conn);
Expand All @@ -101,7 +101,7 @@ export class DbOperationsCommand {

if (!confirm) {
_cli.info('Thank you! Exiting...');
process.exit();
return true;
}

const password = await _cli.password(
Expand All @@ -112,7 +112,7 @@ export class DbOperationsCommand {
const conPassword = connConfig.connection?.['password'];
if (conPassword && password !== conPassword) {
_cli.error(' Wrong Password. Exiting... ');
process.exit();
return true;
}
}

Expand All @@ -122,21 +122,21 @@ export class DbOperationsCommand {

if (migrations.length === 0) {
_cli.info('No migrations to rollback. Already at the base migration');
process.exit();
return true;
}

_cli.info('Rollback of following migrations are done:');
for (const migration of migrations) {
_cli.success(migration);
}

process.exit();
return true;
}

@Command('make:migration {name} {--connection=}', {
desc: 'Command to create a new migration',
})
async makeMigration(_cli: ConsoleIO) {
async makeMigration(_cli: ConsoleIO): Promise<boolean> {
const options = ObjectionService.config;
const name = _cli.argument<string>('name');
const conn = _cli.option<string>('connection') || options.default;
Expand All @@ -150,6 +150,6 @@ export class DbOperationsCommand {

const paths = res.split('/');
_cli.success(paths[paths.length - 1]);
process.exit();
return true;
}
}
2 changes: 1 addition & 1 deletion lib/dev-server/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getTime, Package } from '../utils';
import pc from 'picocolors';

@Command(
`server:build
`build
{--c|config : Path to the .intentrc file.}
{--t|tsconfig : Path to tsconfig file.}
{--d|debug : Run in debug mode (with --inspect flag).}
Expand Down
2 changes: 1 addition & 1 deletion lib/dev-server/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, ConsoleIO } from '../console';
import { Package } from '../utils';

@Command(
`server:dev
`dev
{--config : Path to intent.config.json file}
{--debug : Start debug mode in the server}
`,
Expand Down
Loading