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

Merge branch 'interactive-mode-preference' into v6.0.0

parents eff45069 004c73dc
Branches
No related tags found
No related merge requests found
Pipeline #38761 passed
...@@ -46,7 +46,6 @@ class CommanderApp { ...@@ -46,7 +46,6 @@ class CommanderApp {
sortSubcommands : true sortSubcommands : true
}) })
.option('-H, --host <string>', 'override the Dojo API endpoint', ClientsSharedConfig.apiURL) .option('-H, --host <string>', 'override the Dojo API endpoint', ClientsSharedConfig.apiURL)
.option('-I, --interactive', 'show interactive interface when available', Config.interactiveMode)
.addOption(new Option('--debug').hideHelp()) .addOption(new Option('--debug').hideHelp())
.hook('preAction', (_thisCommand: Command, actionCommand: Command) => { .hook('preAction', (_thisCommand: Command, actionCommand: Command) => {
if ( this.hasToExecuteHook(actionCommand) ) { if ( this.hasToExecuteHook(actionCommand) ) {
...@@ -59,12 +58,25 @@ class CommanderApp { ...@@ -59,12 +58,25 @@ class CommanderApp {
} }
}); });
const interactiveModeOption = new Option('-I, --interactive', 'show interactive interface when available');
const noInteractiveModeOption = new Option('-N, --no_interactive', 'hide interactive interface when available').conflicts('interactive'); // WARNING: Due to a bug in commander.js, the conflicts method doesn't work as expected if the command is named no-interactive
if ( Config.interactiveMode ) {
interactiveModeOption.hideHelp();
} else {
noInteractiveModeOption.hideHelp();
}
this.program.addOption(interactiveModeOption).addOption(noInteractiveModeOption);
this.program.on('option:host', () => { this.program.on('option:host', () => {
ClientsSharedConfig.apiURL = this.program.opts().host; ClientsSharedConfig.apiURL = this.program.opts().host;
}); });
this.program.on('option:no_interactive', () => {
Config.interactiveMode = false;
});
this.program.on('option:interactive', () => { this.program.on('option:interactive', () => {
Config.interactiveMode = this.program.opts().interactive; Config.interactiveMode = true;
}); });
this.program.on('option:debug', () => { this.program.on('option:debug', () => {
......
import CommanderCommand from '../CommanderCommand.js'; import CommanderCommand from '../CommanderCommand.js';
import SettingsApiCommand from './subcommands/SettingsApiCommand'; import SettingsApiCommand from './subcommands/SettingsApiCommand';
import SettingsInteractiveModeCommand from './subcommands/SettingsInteractiveModeCommand';
class SettingsCommand extends CommanderCommand { class SettingsCommand extends CommanderCommand {
...@@ -12,6 +13,7 @@ class SettingsCommand extends CommanderCommand { ...@@ -12,6 +13,7 @@ class SettingsCommand extends CommanderCommand {
protected defineSubCommands() { protected defineSubCommands() {
SettingsApiCommand.registerOnCommand(this.command); SettingsApiCommand.registerOnCommand(this.command);
SettingsInteractiveModeCommand.registerOnCommand(this.command);
} }
protected async commandAction(): Promise<void> { protected async commandAction(): Promise<void> {
......
import CommanderCommand from '../../CommanderCommand.js'; import CommanderCommand from '../../CommanderCommand.js';
import DojoBackendManager from '../../../managers/DojoBackendManager'; import DojoBackendManager from '../../../managers/DojoBackendManager';
import { Option } from 'commander'; import { Option } from 'commander';
import Config from '../../../config/Config';
class SettingsApiCommand extends CommanderCommand { class SettingsApiCommand extends CommanderCommand {
...@@ -19,8 +20,10 @@ class SettingsApiCommand extends CommanderCommand { ...@@ -19,8 +20,10 @@ class SettingsApiCommand extends CommanderCommand {
await DojoBackendManager.cleanApiUrl(); await DojoBackendManager.cleanApiUrl();
} else if ( options.url ) { } else if ( options.url ) {
await DojoBackendManager.setApiUrl(options.url); await DojoBackendManager.setApiUrl(options.url);
} else { } else if ( Config.interactiveMode ) {
await DojoBackendManager.askApiUrl(true); await DojoBackendManager.askApiUrl(true);
} else {
this.command.help();
} }
} }
} }
......
import CommanderCommand from '../../CommanderCommand.js';
import { Option } from 'commander';
import Config from '../../../config/Config';
class SettingsInteractiveModeCommand extends CommanderCommand {
protected commandName: string = 'interactive-mode';
protected defineCommand() {
this.command
.description('enable / disable interactive mode by default')
.addOption(new Option('-i, --interactive', 'ENABLE interactive mode by default'))
.addOption(new Option('-n, --no_interactive', 'DISABLE interactive mode by default').conflicts('interactive')) // WARNING: Due to a bug in commander.js, the conflicts method doesn't work as expected if the command is named no-interactive
.action(this.commandAction.bind(this));
}
protected async commandAction(options: { interactive: boolean, no_interactive: boolean }): Promise<void> {
if ( options.interactive ) {
Config.setInteractiveMode(true);
} else if ( options.no_interactive ) {
Config.setInteractiveMode(false);
} else if ( Config.interactiveMode ) {
await Config.askInteractiveMode();
} else {
this.command.help();
}
}
}
export default new SettingsInteractiveModeCommand();
\ No newline at end of file
import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig';
import GitlabManager from '../managers/GitlabManager'; import GitlabManager from '../managers/GitlabManager';
import ConfigFiles from './ConfigFiles';
import inquirer from 'inquirer';
class Config { class Config {
readonly INTERACTIVE_MODE_CONFIG_KEY = 'interactiveMode';
public gitlabManager!: GitlabManager; public gitlabManager!: GitlabManager;
public versionUpdateInformationPeriodHours!: number; public versionUpdateInformationPeriodHours!: number;
...@@ -67,7 +71,25 @@ class Config { ...@@ -67,7 +71,25 @@ class Config {
neededFiles: JSON.parse(getEnvVar('EXERCISE_NEEDED_FILES', '[]')) neededFiles: JSON.parse(getEnvVar('EXERCISE_NEEDED_FILES', '[]'))
}; };
this.interactiveMode = getEnvVar('INTERACTIVE_MODE', 'false') === 'true'; const interactiveMode: boolean | null = ConfigFiles.stateConfigFile.getParam(this.INTERACTIVE_MODE_CONFIG_KEY) as boolean | null;
this.interactiveMode = interactiveMode == null ? await this.askInteractiveMode() : interactiveMode;
}
setInteractiveMode(state: boolean) {
ConfigFiles.stateConfigFile.setParam(this.INTERACTIVE_MODE_CONFIG_KEY, state);
}
async askInteractiveMode(): Promise<boolean> {
const state: boolean = (await inquirer.prompt({
name : 'state',
message: 'An interactive mode is available. Do you want to enable it by default ?',
type : 'confirm',
default: true
})).state;
this.setInteractiveMode(state);
return state;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment