Running 1 command with yargs, for some reason it runs all

When I run 1 cli command (contenthook run ) example script: start. Then it doesn’t execute any command and in my older version of the code without passing the handler to yargs, it executed all commands at once by the command.run(argv) function. I dont know why and cannot find a valid solution. Please help.

my index.js:

#! /usr/bin/env node
/* eslint-disable no-unused-vars */
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

import globalConfig from "./configs/global.js";

const colors = globalConfig.colors;
const cliName = globalConfig.cliName;

async function loadCommands() {
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
  const commandsDir = path.join(__dirname, "commands");
  const files = await fs.promises.readdir(commandsDir);
  const commandModules = await Promise.all(
    files
      .filter((file) => file.endsWith(".js"))
      .map(async (file) => {
        const commandPath = pathToFileURL(path.join(commandsDir, file));
        return import(commandPath);
      }),
  );
  return commandModules.map((module) => module.default);
}

(async () => {
  try {
    const commands = await loadCommands();

    // eslint-disable-next-line no-undef
    const argv = () => yargs(hideBin(process.argv));

    await commands.map((command) => {
      argv().command({
        command: `${cliName.toLowerCase()} ${command.metadata.name}`,
        describe: command.metadata.description,
        handler: (argv)=>{command.run(argv)},
      });
    });

    // eslint-disable-next-line no-undef
    yargs(hideBin(process.argv)).argv;
  } catch (error) {
    console.error(error);
  }
})();

example command code:

/* eslint-disable no-undef */
import fs from "node:fs";
import path from "node:path";
import globalConfig from "../configs/global.js";

// eslint-disable-next-line no-unused-vars
import { spawn } from "child_process";

const metadata = {
  name: "run <command>",
  description: "Execute a command configured in the contenthook config file",
};

// eslint-disable-next-line no-unused-vars
const run = async (argv) => {
  const configFiles = fs
    .readdirSync(process.cwd())
    .filter((file) => file.startsWith("contenthook.config"));
  if (configFiles.length === 0) {
    console.log(
      `${globalConfig.colors.yellow}Configuration file already exists at ${path.join(process.cwd(), configFiles[0])}${globalConfig.colors.clear}`,
    );
    return;
  } else if (configFiles.length > 1) {
    console.log(
      `${globalConfig.colors.yellow}Multiple configuration files found. Please delete the wrong one.${globalConfig.colors.clear}`,
    );
    return;
  }

  const configPath = path.join(process.cwd(), configFiles[0]);
  let configModule;
  try {
    configModule = await import(pathToFileURL(configPath));
  } catch (error) {
    console.error(`Error: Failed to import config file.n${error}`);
    return;
  }

  const config = configModule.default;
  const command = process.argv[process.argv.length - 1];

  const packageJson = require(path.join(process.cwd(), "package.json"));
  const projectName = packageJson.name;
  const projectVersion = packageJson.version;
  const currentDirectoryPath = process.cwd();

  if (!config.scripts || !config.scripts[command]) {
    console.error(
      `Error: No script named "${command}" found in contenthook.config${path.extname(configFiles[0])}.`,
    );
    return;
  }

  const [cmd, ...args] = config.scripts[command].split(" ");

  console.log(
    `n> ${projectName}@${projectVersion} @contenthook/engine-run ${command} ${currentDirectoryPath}`,
  );
  console.log(`> ${config.scripts[command]}nn`);

  const child = spawn(cmd, args);

  child.stdout.on("data", (data) => {
    console.log(`${data}`);
  });

  /*
child.stderr.on('data', (data) => {
    console.error(`stderr: ${data}`);
});
*/

  child.on("error", (error) => {
    console.error(`> @contenthook/engine-run - error: ${error.message}`);
  });

  child.on("close", (code) => {
    console.log(`> @contenthook/engine-run - process exited with code ${code}`);
  });
};

export default {
  metadata,
  run,
};

I tried running my cli (contenthook run start) but for some reason it just returns:

C:UsersJonasFrankeDocumentstest>contenthook run start

C:UsersJonasFrankeDocumentstest>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật