diff --git a/NodeApp/src/commander/settings/SettingsCommand.ts b/NodeApp/src/commander/settings/SettingsCommand.ts index 6fbcb6e7a5cb0b79c7432975a9b2d12fa6a2db98..8d856a8be28f3a74bf7f63f86476baa6fea20649 100644 --- a/NodeApp/src/commander/settings/SettingsCommand.ts +++ b/NodeApp/src/commander/settings/SettingsCommand.ts @@ -1,5 +1,6 @@ -import CommanderCommand from '../CommanderCommand.js'; -import SettingsApiCommand from './subcommands/SettingsApiCommand'; +import CommanderCommand from '../CommanderCommand.js'; +import SettingsApiCommand from './subcommands/SettingsApiCommand'; +import SettingsInteractiveModeCommand from './subcommands/SettingsInteractiveModeCommand'; class SettingsCommand extends CommanderCommand { @@ -12,6 +13,7 @@ class SettingsCommand extends CommanderCommand { protected defineSubCommands() { SettingsApiCommand.registerOnCommand(this.command); + SettingsInteractiveModeCommand.registerOnCommand(this.command); } protected async commandAction(): Promise<void> { diff --git a/NodeApp/src/commander/settings/subcommands/SettingsInteractiveModeCommand.ts b/NodeApp/src/commander/settings/subcommands/SettingsInteractiveModeCommand.ts new file mode 100644 index 0000000000000000000000000000000000000000..80bcfcc18cedc492d1d63c863215b7539be25cc1 --- /dev/null +++ b/NodeApp/src/commander/settings/subcommands/SettingsInteractiveModeCommand.ts @@ -0,0 +1,31 @@ +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