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