UNPKG

chrome-cmd

Version:

Control Chrome from the command line - List tabs, execute JavaScript, and more

49 lines (48 loc) 1.8 kB
import { Command } from "commander"; import { logger } from "../../../shared/utils/helpers/logger.js"; import { PathHelper } from "../../../shared/utils/helpers/path.helper.js"; import { detectShell } from "../../../shared/utils/helpers/shell-utils.js"; import { CommandNames, SubCommandNames } from "../../schemas/definitions.js"; import { createSubCommandFromSchema } from "../../schemas/utils.js"; import { installBashCompletion, installZshCompletion } from "./utils.js"; function createCompletionInstallCommand() { return createSubCommandFromSchema(CommandNames.COMPLETION, SubCommandNames.COMPLETION_INSTALL, async () => { if (PathHelper.isWindows()) { logger.newline(); logger.warning("\u26A0\uFE0F Shell completion is not supported on Windows"); logger.newline(); logger.info("\u{1F4A1} Completion is only available on Linux and macOS with bash/zsh"); logger.newline(); process.exit(1); } const shell = detectShell(); if (!shell) { logger.error("\u274C Could not detect shell"); logger.newline(); logger.info("\u{1F41A} Supported shells: bash, zsh"); logger.info("\u{1F4A1} Set SHELL environment variable or run from bash/zsh"); process.exit(1); } try { switch (shell) { case "zsh": await installZshCompletion(); break; case "bash": await installBashCompletion(); break; default: logger.error(`\u274C Unsupported shell: ${shell}`); logger.newline(); logger.info("\u{1F41A} Supported shells: bash, zsh"); process.exit(1); } } catch (error) { logger.error(`Failed to install completion: ${error}`); process.exit(1); } }); } export { createCompletionInstallCommand };