mirror of
https://github.com/onyx-and-iris/meld-cli.git
synced 2025-07-12 02:11:46 +00:00
use if else blocks to avoid nested switch.
This commit is contained in:
parent
730cf77707
commit
af64508ca5
42
index.js
42
index.js
@ -21,8 +21,7 @@ socket.onopen = function() {
|
||||
let channel;
|
||||
(() => {
|
||||
try {
|
||||
switch (input[0]) {
|
||||
case "scene":
|
||||
if (input[0] === "scene") {
|
||||
if (flags.help) {
|
||||
console.log(sceneHelp);
|
||||
socket.close();
|
||||
@ -35,14 +34,10 @@ socket.onopen = function() {
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
sceneList(channel)
|
||||
.then((scenes) => {
|
||||
if (scenes.length === 0) {
|
||||
console.log("No scenes found.");
|
||||
} else {
|
||||
console.log("Available scenes:");
|
||||
scenes.forEach(scene => {
|
||||
console.log(`- ${scene.name} (ID: ${scene.id})`);
|
||||
});
|
||||
}
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
})
|
||||
@ -72,7 +67,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "current":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
sceneCurrent(channel)
|
||||
@ -91,14 +86,13 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
console.log(sceneHelp);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
case "audio":
|
||||
} else if (input[0] === "audio") {
|
||||
if (flags.help) {
|
||||
console.log(audioHelp);
|
||||
socket.close();
|
||||
@ -127,7 +121,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "unmute":
|
||||
if (!audioName) {
|
||||
console.error("Error: Audio name is required for the mute command.");
|
||||
@ -146,7 +140,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "toggle":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
audioToggle(channel, audioName)
|
||||
@ -161,7 +155,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "status":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
audioStatus(channel, audioName)
|
||||
@ -176,14 +170,13 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
console.log(audioHelp);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
case "stream":
|
||||
} else if (input[0] === "stream") {
|
||||
if (flags.help) {
|
||||
console.log(streamHelp);
|
||||
socket.close();
|
||||
@ -206,7 +199,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "stop":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
streamStop(channel)
|
||||
@ -236,14 +229,13 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
console.log(streamHelp);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
case "record":
|
||||
} else if (input[0] === "record") {
|
||||
if (flags.help) {
|
||||
console.log(recordHelp);
|
||||
socket.close();
|
||||
@ -266,7 +258,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "stop":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
recordStop(channel)
|
||||
@ -281,7 +273,7 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
case "status":
|
||||
channel = new QWebChannel(socket, function (channel) {
|
||||
recordStatus(channel)
|
||||
@ -296,12 +288,16 @@ socket.onopen = function() {
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
console.log(recordHelp);
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
} else {
|
||||
console.log("Unknown command. Use --help for available commands.");
|
||||
socket.close();
|
||||
process.exit(0);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error handling CLI flags:", error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user