From 004c73dc9961baa52719e7a6f9bcd584b67a583d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <git@minelli.swiss>
Date: Tue, 25 Mar 2025 19:31:15 +0100
Subject: [PATCH] Settings => Add command to enable / disable interactive mode

---
 .../src/commander/settings/SettingsCommand.ts |  6 ++--
 .../SettingsInteractiveModeCommand.ts         | 31 +++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 NodeApp/src/commander/settings/subcommands/SettingsInteractiveModeCommand.ts

diff --git a/NodeApp/src/commander/settings/SettingsCommand.ts b/NodeApp/src/commander/settings/SettingsCommand.ts
index 6fbcb6e..8d856a8 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 0000000..80bcfcc
--- /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
-- 
GitLab