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

Sonar => Minimize code duplication

parent 7cdf0f9d
Branches
Tags
1 merge request!10Resolve "Add sonar integration"
Pipeline #29975 failed
...@@ -8,6 +8,9 @@ NodeApp/src/config/Version.ts ...@@ -8,6 +8,9 @@ NodeApp/src/config/Version.ts
dojo_bash_completion.sh dojo_bash_completion.sh
dojo.fish dojo.fish
sonarlint.xml
sonarlint/
############################ MacOS ############################ MacOS
# General # General
.DS_Store .DS_Store
......
...@@ -12,4 +12,7 @@ ...@@ -12,4 +12,7 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="7e31b6fd-1f86-4d26-8c50-c9ab6530f54e" />
</component>
</module> </module>
\ No newline at end of file
...@@ -4,20 +4,16 @@ import ora from 'ora'; ...@@ -4,20 +4,16 @@ import ora from 'ora';
import chalk from 'chalk'; import chalk from 'chalk';
import AssignmentValidator from '../../../sharedByClients/helpers/Dojo/AssignmentValidator'; import AssignmentValidator from '../../../sharedByClients/helpers/Dojo/AssignmentValidator';
import ClientsSharedAssignmentHelper from '../../../sharedByClients/helpers/Dojo/ClientsSharedAssignmentHelper'; import ClientsSharedAssignmentHelper from '../../../sharedByClients/helpers/Dojo/ClientsSharedAssignmentHelper';
import { Option } from 'commander';
import SharedConfig from '../../../shared/config/SharedConfig'; import SharedConfig from '../../../shared/config/SharedConfig';
import GlobalHelper from '../../../helpers/GlobalHelper';
class AssignmentCheckCommand extends CommanderCommand { class AssignmentCheckCommand extends CommanderCommand {
protected commandName: string = 'check'; protected commandName: string = 'check';
protected defineCommand() { protected defineCommand() {
this.command GlobalHelper.runCommandDefinition(this.command)
.description('locally run a check of an assignment') .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)); .action(this.commandAction.bind(this));
} }
......
import CommanderCommand from '../../CommanderCommand'; import CommanderCommand from '../../CommanderCommand';
import Config from '../../../config/Config';
import { Option } from 'commander';
import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper';
import GlobalHelper from '../../../helpers/GlobalHelper';
class AssignmentRunCommand extends CommanderCommand { class AssignmentRunCommand extends CommanderCommand {
protected commandName: string = 'run'; protected commandName: string = 'run';
protected defineCommand() { protected defineCommand() {
// This command is synced with the "exercise run" command GlobalHelper.runCommandDefinition(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('-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));
} }
......
...@@ -5,6 +5,7 @@ import TextStyle from '../../../types/T ...@@ -5,6 +5,7 @@ import TextStyle from '../../../types/T
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import os from 'os'; import os from 'os';
import GlobalHelper from '../../../helpers/GlobalHelper';
class CompletionBashCommand extends CommanderCommand { class CompletionBashCommand extends CommanderCommand {
...@@ -13,10 +14,8 @@ class CompletionBashCommand extends CommanderCommand { ...@@ -13,10 +14,8 @@ class CompletionBashCommand extends CommanderCommand {
private installPath = path.join(os.homedir(), '.bash_completion'); private installPath = path.join(os.homedir(), '.bash_completion');
protected defineCommand() { protected defineCommand() {
this.command GlobalHelper.completionCommandDefinition(this.command)
.description('generate bash completion') .description('generate bash completion')
.option('-f, --file <filename>')
.option('-y, --force', 'don\'t ask for file overwrite confirmation')
.action(this.commandAction.bind(this)); .action(this.commandAction.bind(this));
} }
......
...@@ -5,6 +5,7 @@ import TextStyle from '../../../types/T ...@@ -5,6 +5,7 @@ import TextStyle from '../../../types/T
import path from 'path'; import path from 'path';
import os from 'os'; import os from 'os';
import fs from 'fs-extra'; import fs from 'fs-extra';
import GlobalHelper from '../../../helpers/GlobalHelper';
class CompletionFishCommand extends CommanderCommand { class CompletionFishCommand extends CommanderCommand {
...@@ -13,15 +14,14 @@ class CompletionFishCommand extends CommanderCommand { ...@@ -13,15 +14,14 @@ class CompletionFishCommand extends CommanderCommand {
private installPath = path.join(os.homedir(), '.config/fish/completions/dojo.fish'); private installPath = path.join(os.homedir(), '.config/fish/completions/dojo.fish');
protected defineCommand() { protected defineCommand() {
this.command GlobalHelper.completionCommandDefinition(this.command)
.description('generate fish completion') .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)); .action(this.commandAction.bind(this));
} }
private writeFile(filename: string, showInstructions: boolean) { private writeFile(filename: string, showInstructions: boolean) {
const spinner: ora.Ora = ora(`Writing fish completion in ${ filename }...`).start(); const spinner: ora.Ora = ora(`Writing fish completion in ${ filename }...`).start();
try { try {
fs.mkdirsSync(path.dirname(filename)); fs.mkdirsSync(path.dirname(filename));
...@@ -29,7 +29,6 @@ class CompletionFishCommand extends CommanderCommand { ...@@ -29,7 +29,6 @@ class CompletionFishCommand extends CommanderCommand {
spinner.succeed(`Fish completion successfully written in ${ filename }.`); spinner.succeed(`Fish completion successfully written in ${ filename }.`);
if ( showInstructions ) { if ( showInstructions ) {
console.log(` console.log(`
The easiest way to install the completion is to copy the ${ TextStyle.CODE(filename) } into the ${ TextStyle.CODE('~/.config/fish/completions') } directory. The easiest way to install the completion is to copy the ${ TextStyle.CODE(filename) } into the ${ TextStyle.CODE('~/.config/fish/completions') } directory.
......
...@@ -5,6 +5,7 @@ import TextStyle from '../../../types/T ...@@ -5,6 +5,7 @@ import TextStyle from '../../../types/T
import path from 'path'; import path from 'path';
import { homedir } from 'os'; import { homedir } from 'os';
import fs from 'fs-extra'; import fs from 'fs-extra';
import GlobalHelper from '../../../helpers/GlobalHelper';
class CompletionZshCommand extends CommanderCommand { class CompletionZshCommand extends CommanderCommand {
...@@ -21,10 +22,8 @@ source ${ this.bash_completion } ...@@ -21,10 +22,8 @@ source ${ this.bash_completion }
protected defineCommand() { protected defineCommand() {
this.command GlobalHelper.completionCommandDefinition(this.command)
.description('generate zsh completion, which is derived from the bash completion') .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)); .action(this.commandAction.bind(this));
} }
......
import CommanderCommand from '../../CommanderCommand'; import CommanderCommand from '../../CommanderCommand';
import Config from '../../../config/Config';
import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper'; import ExerciseRunHelper from '../../../helpers/Dojo/ExerciseRunHelper';
import { Option } from 'commander'; import GlobalHelper from '../../../helpers/GlobalHelper';
class ExerciseRunCommand extends CommanderCommand { class ExerciseRunCommand extends CommanderCommand {
protected commandName: string = 'run'; protected commandName: string = 'run';
protected defineCommand() { protected defineCommand() {
// This command is synced with the "assignment run" command GlobalHelper.runCommandDefinition(this.command)
this.command
.description('locally run an exercise') .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)); .action(this.commandAction.bind(this));
} }
......
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
Subproject commit 9e3f29d2f313ef96944a199da0db39f1827c496a Subproject commit 6214acbd799d9eed3f5b6840858f8d5ecda82c86
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment