From 9ebad0a01d281078da83300c7b38f98dfe207a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me> Date: Sun, 14 Jan 2024 22:08:21 +0100 Subject: [PATCH] RunCommand => Add two levels of verbose --- .../subcommands/AssignmentRunCommand.ts | 7 ++++-- .../subcommands/ExerciseRunCommand.ts | 7 ++++-- NodeApp/src/helpers/Dojo/ExerciseRunHelper.ts | 25 +++++++++++++------ NodeApp/src/sharedByClients | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts index e33c755..9a7489f 100644 --- a/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts @@ -1,5 +1,6 @@ import CommanderCommand from '../../CommanderCommand'; import Config from '../../../config/Config'; +import { Option } from 'commander'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; @@ -11,11 +12,13 @@ class AssignmentRunCommand extends CommanderCommand { this.command .description('locally run the assignment as an exercise') .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)); } - 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); } } diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts index 90282b7..c4d6b21 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts @@ -1,6 +1,7 @@ import CommanderCommand from '../../CommanderCommand'; import Config from '../../../config/Config'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; +import { Option } from 'commander'; class ExerciseRunCommand extends CommanderCommand { @@ -11,11 +12,13 @@ class ExerciseRunCommand extends CommanderCommand { this.command .description('locally run an exercise') .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)); } - 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); } } diff --git a/NodeApp/src/helpers/Dojo/ExerciseRunHelper.ts b/NodeApp/src/helpers/Dojo/ExerciseRunHelper.ts index 27113aa..49635d0 100644 --- a/NodeApp/src/helpers/Dojo/ExerciseRunHelper.ts +++ b/NodeApp/src/helpers/Dojo/ExerciseRunHelper.ts @@ -36,7 +36,9 @@ class ExerciseRunHelper { }).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; let assignmentFile: AssignmentFile; @@ -136,10 +138,17 @@ class ExerciseRunHelper { await new Promise<void>((resolve, reject) => { let spinner: ora.Ora; - if ( options.verbose ) { - exerciseDockerCompose.events.on('logs', (log: string, _error: boolean, displayable: boolean) => { - if ( displayable ) { - console.log(log); + if ( verbose ) { + let buildPhase: boolean = true; + exerciseDockerCompose.events.on('logs', (log: string, _error: boolean, displayable: boolean, currentStep: string) => { + 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 { indent: 4 }).start(); - if ( options.verbose && name == 'COMPOSE_RUN' ) { + if ( verbose && name == 'COMPOSE_RUN' ) { spinner.info(); } }); exerciseDockerCompose.events.on('endStep', (stepName: string, message: string, error: boolean) => { if ( error ) { - if ( options.verbose && stepName == 'COMPOSE_RUN' ) { + if ( verbose && stepName == 'COMPOSE_RUN' ) { ora({ text : message, indent: 4 @@ -166,7 +175,7 @@ class ExerciseRunHelper { spinner.fail(message); } } else { - if ( options.verbose && stepName == 'COMPOSE_RUN' ) { + if ( verbose && stepName == 'COMPOSE_RUN' ) { ora({ text : message, indent: 4 diff --git a/NodeApp/src/sharedByClients b/NodeApp/src/sharedByClients index 06f4fcd..e8114e0 160000 --- a/NodeApp/src/sharedByClients +++ b/NodeApp/src/sharedByClients @@ -1 +1 @@ -Subproject commit 06f4fcdc53a384d6a9c85e68b7debf10dfbe25a8 +Subproject commit e8114e0562f00fc95144ec451dc8365f8cc8f22c -- GitLab