🛠️ Simplify argument parsing and validation logic by removing redundant type annotations and relocating target validation
This commit is contained in:
@@ -29,16 +29,6 @@ const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// Configuration
|
||||
/**
|
||||
* @typedef {Object} SSHHostConfig
|
||||
* @property {string} host
|
||||
* @property {number} port
|
||||
* @property {string} username
|
||||
* @property {string} privateKeyPath
|
||||
* @property {string} password
|
||||
*/
|
||||
|
||||
/** @type {Record<'internal'|'external', SSHHostConfig>} */
|
||||
const SSH_HOSTS = {
|
||||
internal: {
|
||||
host: '10.0.0.81',
|
||||
@@ -65,12 +55,8 @@ const DIST_DIR = path.join(SOURCE_DIR, 'dist');
|
||||
* Parse command line arguments
|
||||
* @returns {Object} Parsed arguments
|
||||
*/
|
||||
/**
|
||||
* @returns {{ target: keyof typeof SSH_HOSTS, port: number, sslPort: number|null }}
|
||||
*/
|
||||
function parseArgs() {
|
||||
const args = process.argv.slice(2);
|
||||
/** @type {{ target: keyof typeof SSH_HOSTS, port: number, sslPort: number|null }} */
|
||||
const config = {
|
||||
target: 'internal',
|
||||
port: 8080,
|
||||
@@ -79,15 +65,7 @@ function parseArgs() {
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--target' && args[i + 1]) {
|
||||
/** @type {any} */
|
||||
const t = args[i + 1];
|
||||
if (t === 'internal' || t === 'external') {
|
||||
config.target = t;
|
||||
} else {
|
||||
throw new Error(
|
||||
`Invalid target: ${t}. Must be 'internal' or 'external'.`
|
||||
);
|
||||
}
|
||||
config.target = args[i + 1];
|
||||
i++;
|
||||
} else if (args[i] === '--port' && args[i + 1]) {
|
||||
config.port = parseInt(args[i + 1], 10);
|
||||
@@ -98,6 +76,13 @@ function parseArgs() {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate target
|
||||
if (!SSH_HOSTS[config.target]) {
|
||||
throw new Error(
|
||||
`Invalid target: ${config.target}. Must be 'internal' or 'external'.`
|
||||
);
|
||||
}
|
||||
|
||||
// Validate port
|
||||
if (isNaN(config.port) || config.port < 1 || config.port > 65535) {
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user