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

Add setting for interactive mode by default

parent 8782c8ff
Branches
No related tags found
No related merge requests found
...@@ -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 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