UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

71 lines (70 loc) 3.27 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const dev_project_1 = require("../../lib/dev-project"); const dev_ticket_1 = require("../../lib/dev-ticket"); /** * `lt ticket switch <id>` — show a ticket worktree's path and open it in your * editor (best-effort). A CLI cannot change the parent shell's directory, so it * also prints the `cd` line to copy. `--no-open` only prints. */ const SwitchCommand = { alias: ['sw', 'open'], description: 'Show a ticket worktree path + open it in your editor', name: 'switch', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { var _a; const { filesystem, parameters, print: { colors, error, info, success }, } = toolbox; const id = String((_a = parameters.first) !== null && _a !== void 0 ? _a : '').trim(); if (!id) { error('Usage: lt ticket switch <id>'); if (!parameters.options.fromGluegunMenu) process.exit(1); return 'ticket switch: missing id'; } const layout = (0, dev_project_1.resolveLayout)(filesystem.cwd(), filesystem); let mainRepoRoot; try { mainRepoRoot = (0, dev_ticket_1.gitMainRepoRoot)(layout.root); } catch (_b) { error('Not inside a git repository.'); if (!parameters.options.fromGluegunMenu) process.exit(1); return 'ticket switch: not a git repo'; } const wt = (0, dev_ticket_1.listWorktrees)(mainRepoRoot).find((w) => w.ticket === id); if (!wt) { error(`No ticket worktree "${id}" found. See \`lt ticket list\`.`); if (!parameters.options.fromGluegunMenu) process.exit(1); return 'ticket switch: not found'; } info(''); info(`Ticket "${id}" → ${wt.path}`); info(colors.dim(` cd ${wt.path}`)); if (parameters.options.open !== false) { const editor = process.env.LT_EDITOR || 'code'; try { (0, child_process_1.execFileSync)(editor, [wt.path], { stdio: 'ignore' }); success(`Opened in ${editor}.`); } catch (_c) { info(colors.dim(` (could not run \`${editor}\` — open the folder manually, or set LT_EDITOR)`)); } } if (!parameters.options.fromGluegunMenu) process.exit(); return `ticket switch: ${id}`; }), }; module.exports = SwitchCommand;