-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc57195
commit 9857448
Showing
38 changed files
with
558 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { CommandRunner } from 'nest-commander'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases'; | ||
import ora from 'ora'; | ||
|
||
@Injectable() | ||
export abstract class BaseCommand extends CommandRunner { | ||
constructor(readonly cortexUseCases: CortexUsecases) { | ||
super(); | ||
} | ||
protected abstract runCommand( | ||
passedParam: string[], | ||
options?: Record<string, any>, | ||
): Promise<void>; | ||
|
||
async run( | ||
passedParam: string[], | ||
options?: Record<string, any>, | ||
): Promise<void> { | ||
const checkingSpinner = ora('Checking API server online...').start(); | ||
const result = await this.cortexUseCases.isAPIServerOnline(); | ||
if (!result) { | ||
checkingSpinner.fail('API server is offline'); | ||
process.exit(1); | ||
} | ||
checkingSpinner.succeed('API server is online'); | ||
await this.runCommand(passedParam, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
cortex-js/src/infrastructure/commanders/configs.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import { CommandRunner, SubCommand } from 'nest-commander'; | ||
import { SubCommand } from 'nest-commander'; | ||
import { SetCommandContext } from './decorators/CommandContext'; | ||
import { ContextService } from '@/infrastructure/services/context/context.service'; | ||
import { ConfigsGetCommand } from './configs/configs-get.command'; | ||
import { ConfigsListCommand } from './configs/configs-list.command'; | ||
import { ConfigsSetCommand } from './configs/configs-set.command'; | ||
import { BaseCommand } from './base.command'; | ||
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases'; | ||
|
||
@SubCommand({ | ||
name: 'configs', | ||
description: 'Get cortex configurations', | ||
subCommands: [ConfigsGetCommand, ConfigsListCommand, ConfigsSetCommand], | ||
}) | ||
@SetCommandContext() | ||
export class ConfigsCommand extends CommandRunner { | ||
constructor(readonly contextService: ContextService) { | ||
super(); | ||
export class ConfigsCommand extends BaseCommand { | ||
constructor( | ||
readonly contextService: ContextService, | ||
readonly cortexUseCases: CortexUsecases, | ||
) { | ||
super(cortexUseCases); | ||
} | ||
|
||
async run(): Promise<void> { | ||
async runCommand(): Promise<void> { | ||
this.command?.help(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
cortex-js/src/infrastructure/commanders/configs/configs-list.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import { CommandRunner, SubCommand } from 'nest-commander'; | ||
import { SubCommand } from 'nest-commander'; | ||
import { SetCommandContext } from '../decorators/CommandContext'; | ||
import { ContextService } from '@/infrastructure/services/context/context.service'; | ||
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase'; | ||
import { BaseCommand } from '../base.command'; | ||
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases'; | ||
|
||
@SubCommand({ | ||
name: 'list', | ||
description: 'Get all cortex configurations', | ||
}) | ||
@SetCommandContext() | ||
export class ConfigsListCommand extends CommandRunner { | ||
export class ConfigsListCommand extends BaseCommand { | ||
constructor( | ||
private readonly configsUsecases: ConfigsUsecases, | ||
readonly contextService: ContextService, | ||
readonly cortexUsecases: CortexUsecases, | ||
) { | ||
super(); | ||
super(cortexUsecases); | ||
} | ||
|
||
async run(): Promise<void> { | ||
async runCommand(): Promise<void> { | ||
return this.configsUsecases.getConfigs().then(console.table); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.