Skip to content
Snippets Groups Projects
Commit 9ebad0a0 authored by michael.minelli's avatar michael.minelli
Browse files

RunCommand => Add two levels of verbose

parent 5a3e240d
Branches
No related tags found
No related merge requests found
Pipeline #28481 passed
import CommanderCommand from '../../CommanderCommand'; import CommanderCommand from '../../CommanderCommand';
import Config from '../../../config/Config'; import Config from '../../../config/Config';
import { Option } from 'commander';
import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper';
...@@ -11,11 +12,13 @@ class AssignmentRunCommand extends CommanderCommand { ...@@ -11,11 +12,13 @@ class AssignmentRunCommand extends CommanderCommand {
this.command this.command
.description('locally run the assignment as an exercise') .description('locally run the assignment as an exercise')
.option('-p, --path <value>', 'exercise path', Config.folders.defaultLocalExercise) .option('-p, --path <value>', 'exercise path', Config.folders.defaultLocalExercise)
.option('-v, --verbose', 'verbose mode (display docker compose logs in live)') .option('-v, --verbose', 'verbose mode - display principal container output in live')
.addOption(new Option('-w, --super-verbose', 'verbose mode - display all docker compose logs (build included) in live').conflicts('verbose'))
.addOption(new Option('--verbose-ssj2').hideHelp().implies({ superVerbose: true }))
.action(this.commandAction.bind(this)); .action(this.commandAction.bind(this));
} }
protected async commandAction(options: { path: string, verbose: boolean }): Promise<void> { protected async commandAction(options: { path: string, verbose: boolean, superVerbose: boolean }): Promise<void> {
await ExerciseRunHelper.run(options); await ExerciseRunHelper.run(options);
} }
} }
......
import CommanderCommand from '../../CommanderCommand'; import CommanderCommand from '../../CommanderCommand';
import Config from '../../../config/Config'; import Config from '../../../config/Config';
import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper';
import { Option } from 'commander';
class ExerciseRunCommand extends CommanderCommand { class ExerciseRunCommand extends CommanderCommand {
...@@ -11,11 +12,13 @@ class ExerciseRunCommand extends CommanderCommand { ...@@ -11,11 +12,13 @@ class ExerciseRunCommand extends CommanderCommand {
this.command this.command
.description('locally run an exercise') .description('locally run an exercise')
.option('-p, --path <value>', 'exercise path', Config.folders.defaultLocalExercise) .option('-p, --path <value>', 'exercise path', Config.folders.defaultLocalExercise)
.option('-v, --verbose', 'verbose mode (display docker compose logs in live)') .option('-v, --verbose', 'verbose mode - display principal container output in live')
.addOption(new Option('-w, --super-verbose', 'verbose mode - display all docker compose logs (build included) in live').conflicts('verbose'))
.addOption(new Option('--verbose-ssj2').hideHelp().implies({ superVerbose: true }))
.action(this.commandAction.bind(this)); .action(this.commandAction.bind(this));
} }
protected async commandAction(options: { path: string, verbose: boolean }): Promise<void> { protected async commandAction(options: { path: string, verbose: boolean, superVerbose: boolean }): Promise<void> {
await ExerciseRunHelper.run(options); await ExerciseRunHelper.run(options);
} }
} }
......
...@@ -36,7 +36,9 @@ class ExerciseRunHelper { ...@@ -36,7 +36,9 @@ class ExerciseRunHelper {
}).start().info(); }).start().info();
} }
async run(options: { path: string, verbose: boolean }): Promise<void> { async run(options: { path: string, verbose: boolean, superVerbose: boolean }): Promise<void> {
const verbose: boolean = options.verbose || options.superVerbose;
const localExercisePath: string = options.path ?? Config.folders.defaultLocalExercise; const localExercisePath: string = options.path ?? Config.folders.defaultLocalExercise;
let assignmentFile: AssignmentFile; let assignmentFile: AssignmentFile;
...@@ -136,10 +138,17 @@ class ExerciseRunHelper { ...@@ -136,10 +138,17 @@ class ExerciseRunHelper {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
let spinner: ora.Ora; let spinner: ora.Ora;
if ( options.verbose ) { if ( verbose ) {
exerciseDockerCompose.events.on('logs', (log: string, _error: boolean, displayable: boolean) => { let buildPhase: boolean = true;
if ( displayable ) { exerciseDockerCompose.events.on('logs', (log: string, _error: boolean, displayable: boolean, currentStep: string) => {
console.log(log); for ( const line of log.split('\n') ) {
if ( currentStep == 'COMPOSE_RUN' && buildPhase && line != '' && !line.startsWith('#') ) {
buildPhase = false;
}
if ( displayable && (options.superVerbose || !buildPhase) ) {
console.log(line);
}
} }
}); });
} }
...@@ -150,14 +159,14 @@ class ExerciseRunHelper { ...@@ -150,14 +159,14 @@ class ExerciseRunHelper {
indent: 4 indent: 4
}).start(); }).start();
if ( options.verbose && name == 'COMPOSE_RUN' ) { if ( verbose && name == 'COMPOSE_RUN' ) {
spinner.info(); spinner.info();
} }
}); });
exerciseDockerCompose.events.on('endStep', (stepName: string, message: string, error: boolean) => { exerciseDockerCompose.events.on('endStep', (stepName: string, message: string, error: boolean) => {
if ( error ) { if ( error ) {
if ( options.verbose && stepName == 'COMPOSE_RUN' ) { if ( verbose && stepName == 'COMPOSE_RUN' ) {
ora({ ora({
text : message, text : message,
indent: 4 indent: 4
...@@ -166,7 +175,7 @@ class ExerciseRunHelper { ...@@ -166,7 +175,7 @@ class ExerciseRunHelper {
spinner.fail(message); spinner.fail(message);
} }
} else { } else {
if ( options.verbose && stepName == 'COMPOSE_RUN' ) { if ( verbose && stepName == 'COMPOSE_RUN' ) {
ora({ ora({
text : message, text : message,
indent: 4 indent: 4
......
Subproject commit 06f4fcdc53a384d6a9c85e68b7debf10dfbe25a8 Subproject commit e8114e0562f00fc95144ec451dc8365f8cc8f22c
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment