mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 11:09:34 +00:00
31 lines
857 B
JavaScript
31 lines
857 B
JavaScript
"use strict";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
const { parseArgs } = require("util");
|
|
|
|
const TRUE_VALUES = new Set(["1", "true", "yes", "on"]);
|
|
|
|
function isEnabled(value) {
|
|
return typeof value === "string" && TRUE_VALUES.has(value.trim().toLowerCase());
|
|
}
|
|
|
|
function parseLaunchOptions(args = process.argv.slice(2), env = process.env) {
|
|
const { values: cliArgs } = parseArgs({
|
|
args,
|
|
options: {
|
|
port: { type: "string", short: "p" },
|
|
hostname: { type: "string", short: "H" },
|
|
"no-open": { type: "boolean" },
|
|
},
|
|
strict: false,
|
|
});
|
|
|
|
return {
|
|
port: cliArgs.port ?? env.PORT ?? "30141",
|
|
hostname: cliArgs.hostname ?? env.PI_WEB_HOSTNAME ?? "127.0.0.1",
|
|
openBrowser: !cliArgs["no-open"] && !isEnabled(env.PI_WEB_NO_OPEN),
|
|
};
|
|
}
|
|
|
|
module.exports = { parseLaunchOptions };
|