diff --git a/.gitignore b/.gitignore index b30f2e1d0b10ca45c92e87f88f9766903d8ff732..5d889f542ad1b6de7093a00bd316a0e421d049f5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ NodeApp/src/config/Version.ts dojo_bash_completion.sh dojo.fish +sonarlint.xml +sonarlint/ + ############################ MacOS # General .DS_Store diff --git a/NodeApp/.idea/DojoCLI.iml b/NodeApp/.idea/DojoCLI.iml index d47865a1c8d932c244bdb1f09d5eb3295d5dc715..dd6c9d867f2ee5279c298de21610d6340db23dd7 100644 --- a/NodeApp/.idea/DojoCLI.iml +++ b/NodeApp/.idea/DojoCLI.iml @@ -12,4 +12,7 @@ <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> </component> + <component name="SonarLintModuleSettings"> + <option name="uniqueId" value="7e31b6fd-1f86-4d26-8c50-c9ab6530f54e" /> + </component> </module> \ No newline at end of file diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentCheckCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentCheckCommand.ts index b818c738ad25d31d38e2c848066018c50ad991ef..c83a3d16aa5900ecd5e1f2a04648f3bdef1abc1f 100644 --- a/NodeApp/src/commander/assignment/subcommands/AssignmentCheckCommand.ts +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentCheckCommand.ts @@ -4,20 +4,16 @@ import ora from 'ora'; import chalk from 'chalk'; import AssignmentValidator from '../../../sharedByClients/helpers/Dojo/AssignmentValidator'; import ClientsSharedAssignmentHelper from '../../../sharedByClients/helpers/Dojo/ClientsSharedAssignmentHelper'; -import { Option } from 'commander'; import SharedConfig from '../../../shared/config/SharedConfig'; +import GlobalHelper from '../../../helpers/GlobalHelper'; class AssignmentCheckCommand extends CommanderCommand { protected commandName: string = 'check'; protected defineCommand() { - this.command + GlobalHelper.runCommandDefinition(this.command) .description('locally run a check of an assignment') - .option('-p, --path <value>', 'assignment path', Config.folders.defaultLocalExercise) - .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)); } diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts index 9a7489f2e9db1792682554f343ebc0b1b62fa2ee..3b44f98a6370b7bd95cd7888897329e8a3021b33 100644 --- a/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentRunCommand.ts @@ -1,20 +1,14 @@ import CommanderCommand from '../../CommanderCommand'; -import Config from '../../../config/Config'; -import { Option } from 'commander'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; +import GlobalHelper from '../../../helpers/GlobalHelper'; class AssignmentRunCommand extends CommanderCommand { protected commandName: string = 'run'; protected defineCommand() { - // This command is synced with the "exercise run" command - this.command + GlobalHelper.runCommandDefinition(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 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)); } diff --git a/NodeApp/src/commander/completion/subcommands/CompletionBashCommand.ts b/NodeApp/src/commander/completion/subcommands/CompletionBashCommand.ts index a10dc0eb4ee8a805154893bbf7f762edf71279e5..0127d7811e210369652f62694f13441a4d27262b 100644 --- a/NodeApp/src/commander/completion/subcommands/CompletionBashCommand.ts +++ b/NodeApp/src/commander/completion/subcommands/CompletionBashCommand.ts @@ -5,6 +5,7 @@ import TextStyle from '../../../types/T import fs from 'fs-extra'; import path from 'path'; import os from 'os'; +import GlobalHelper from '../../../helpers/GlobalHelper'; class CompletionBashCommand extends CommanderCommand { @@ -13,10 +14,8 @@ class CompletionBashCommand extends CommanderCommand { private installPath = path.join(os.homedir(), '.bash_completion'); protected defineCommand() { - this.command + GlobalHelper.completionCommandDefinition(this.command) .description('generate bash completion') - .option('-f, --file <filename>') - .option('-y, --force', 'don\'t ask for file overwrite confirmation') .action(this.commandAction.bind(this)); } @@ -47,20 +46,20 @@ For more details: ${ TextStyle.URL('https://github.com/scop/bash-completion/blob } /* The completion command must do the following: - - if a file is provided: - - if force is not enabled: - - check if the file exists: - - if it exists, prompt the user that it will be erased - - if ok is given write the file and prompt that a backup has been created - - else create the file containing the completion - - else - - if force is not enabled: - - check if the default file exists: - - if it exists, prompt the user that it will be erased: - - if ok is given write the file and prompt that a backup has been created - - else - - create the file containing the completion - */ + - if a file is provided: + - if force is not enabled: + - check if the file exists: + - if it exists, prompt the user that it will be erased + - if ok is given write the file and prompt that a backup has been created + - else create the file containing the completion + - else + - if force is not enabled: + - check if the default file exists: + - if it exists, prompt the user that it will be erased: + - if ok is given write the file and prompt that a backup has been created + - else + - create the file containing the completion + */ protected async commandAction(options: { file: string, force: boolean }): Promise<void> { const filePath = path.resolve(options.file ?? this.installPath); // change that if file is empty const showInstructions = !!options.file; diff --git a/NodeApp/src/commander/completion/subcommands/CompletionFishCommand.ts b/NodeApp/src/commander/completion/subcommands/CompletionFishCommand.ts index 51431a58022023c1566f5092996c0c1cbf2ef219..9395550a4cb3fe240fb45442cbddcf15e32f7150 100644 --- a/NodeApp/src/commander/completion/subcommands/CompletionFishCommand.ts +++ b/NodeApp/src/commander/completion/subcommands/CompletionFishCommand.ts @@ -5,6 +5,7 @@ import TextStyle from '../../../types/T import path from 'path'; import os from 'os'; import fs from 'fs-extra'; +import GlobalHelper from '../../../helpers/GlobalHelper'; class CompletionFishCommand extends CommanderCommand { @@ -13,15 +14,14 @@ class CompletionFishCommand extends CommanderCommand { private installPath = path.join(os.homedir(), '.config/fish/completions/dojo.fish'); protected defineCommand() { - this.command + GlobalHelper.completionCommandDefinition(this.command) .description('generate fish completion') - .option('-f, --file <filename>', `filename where the bash completion will be stored`) - .option('-y, --force', 'don\'t ask for file overwrite confirmation') .action(this.commandAction.bind(this)); } private writeFile(filename: string, showInstructions: boolean) { const spinner: ora.Ora = ora(`Writing fish completion in ${ filename }...`).start(); + try { fs.mkdirsSync(path.dirname(filename)); @@ -29,7 +29,6 @@ class CompletionFishCommand extends CommanderCommand { spinner.succeed(`Fish completion successfully written in ${ filename }.`); if ( showInstructions ) { - console.log(` The easiest way to install the completion is to copy the ${ TextStyle.CODE(filename) } into the ${ TextStyle.CODE('~/.config/fish/completions') } directory. @@ -42,20 +41,20 @@ ${ TextStyle.CODE(` cp -i ${ filename } ~/.config/fish/completions # interactiv /* The completion command must do the following: - - if a file is provided: - - if force is not enabled: - - check if the file exists: - - if it exists, prompt the user that it will be erased - - if ok is given write the file and prompt that a backup has been created - - else create the file containing the completion - - else - - if force is not enabled: - - check if the default file exists: - - if it exists, prompt the user that it will be erased: - - if ok is given write the file and prompt that a backup has been created - - else - - create the file containing the completion - */ + - if a file is provided: + - if force is not enabled: + - check if the file exists: + - if it exists, prompt the user that it will be erased + - if ok is given write the file and prompt that a backup has been created + - else create the file containing the completion + - else + - if force is not enabled: + - check if the default file exists: + - if it exists, prompt the user that it will be erased: + - if ok is given write the file and prompt that a backup has been created + - else + - create the file containing the completion + */ protected async commandAction(options: { file: string, force: boolean }): Promise<void> { const filePath = path.resolve(options.file ?? this.installPath); // change that if file is empty const showInstructions = !!options.file; diff --git a/NodeApp/src/commander/completion/subcommands/CompletionZshCommand.ts b/NodeApp/src/commander/completion/subcommands/CompletionZshCommand.ts index 9e277aa6cb44d77eabf44521beb7786c452f7cc0..1e97b2b7e60f6893b432d89e3fc538f84619ea80 100644 --- a/NodeApp/src/commander/completion/subcommands/CompletionZshCommand.ts +++ b/NodeApp/src/commander/completion/subcommands/CompletionZshCommand.ts @@ -5,6 +5,7 @@ import TextStyle from '../../../types/T import path from 'path'; import { homedir } from 'os'; import fs from 'fs-extra'; +import GlobalHelper from '../../../helpers/GlobalHelper'; class CompletionZshCommand extends CommanderCommand { @@ -21,10 +22,8 @@ source ${ this.bash_completion } protected defineCommand() { - this.command + GlobalHelper.completionCommandDefinition(this.command) .description('generate zsh completion, which is derived from the bash completion') - .option('-f, --file <filename>', 'bash completion filename') - .option('-y, --force', 'don\'t ask for file overwrite confirmation') .action(this.commandAction.bind(this)); } @@ -102,21 +101,21 @@ source ${ filename } } /* The completion command must do the following: - - if a file is provided: - - if force is not enabled: - - check if the bash completion file exists: - - if it exists, prompt the user that it will be overwritten - - if ok is given write the file and prompt that a backup has been created - - else create the file containing the completion - - else - - if force is not enabled: - - check if the default file exists: - - if it exists, prompt the user that it will be erased: - - if ok is given write the file and prompt that a backup has been created - - else - - create the file containing the completion - - create a .zprofile or append the appropriate commands into the .zprofile file - */ + - if a file is provided: + - if force is not enabled: + - check if the bash completion file exists: + - if it exists, prompt the user that it will be overwritten + - if ok is given write the file and prompt that a backup has been created + - else create the file containing the completion + - else + - if force is not enabled: + - check if the default file exists: + - if it exists, prompt the user that it will be erased: + - if ok is given write the file and prompt that a backup has been created + - else + - create the file containing the completion + - create a .zprofile or append the appropriate commands into the .zprofile file + */ protected async commandAction(options: { file: string, force: boolean }): Promise<void> { const filePath = path.resolve(options.file ?? this.bash_completion); // change that if file is empty const showInstructions = !!options.file; diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts index c4d6b2195d767955bafb319875993b8733e77176..75af9463ee742490d62857b8d97f686367516fc6 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseRunCommand.ts @@ -1,20 +1,14 @@ import CommanderCommand from '../../CommanderCommand'; -import Config from '../../../config/Config'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; -import { Option } from 'commander'; +import GlobalHelper from '../../../helpers/GlobalHelper'; class ExerciseRunCommand extends CommanderCommand { protected commandName: string = 'run'; protected defineCommand() { - // This command is synced with the "assignment run" command - this.command + GlobalHelper.runCommandDefinition(this.command) .description('locally run an exercise') - .option('-p, --path <value>', 'exercise path', Config.folders.defaultLocalExercise) - .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)); } diff --git a/NodeApp/src/helpers/GlobalHelper.ts b/NodeApp/src/helpers/GlobalHelper.ts new file mode 100644 index 0000000000000000000000000000000000000000..7f0991cbd6ce17a58c1a7845057a2800f99cd7d4 --- /dev/null +++ b/NodeApp/src/helpers/GlobalHelper.ts @@ -0,0 +1,26 @@ +import { Command, Option } from 'commander'; +import Config from '../config/Config'; + + +class GlobalHelper { + public runCommandDefinition(command: Command) { + command + .option('-p, --path <value>', 'assignment path', Config.folders.defaultLocalExercise) + .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 })); + + return command; + } + + public completionCommandDefinition(command: Command) { + command + .option('-f, --file <filename>') + .option('-y, --force', 'don\'t ask for file overwrite confirmation'); + + return command; + } +} + + +export default new GlobalHelper(); \ No newline at end of file diff --git a/NodeApp/src/shared b/NodeApp/src/shared index 9e3f29d2f313ef96944a199da0db39f1827c496a..6214acbd799d9eed3f5b6840858f8d5ecda82c86 160000 --- a/NodeApp/src/shared +++ b/NodeApp/src/shared @@ -1 +1 @@ -Subproject commit 9e3f29d2f313ef96944a199da0db39f1827c496a +Subproject commit 6214acbd799d9eed3f5b6840858f8d5ecda82c86