Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from "node:child_process";
import { execFile } from "node:child_process";
import type { Command } from "commander";
import { getProfile, loadConfig } from "../config/manager";
import type { GlobalOptions } from "../config/types";
Expand Down Expand Up @@ -30,18 +30,22 @@ function buildZephyrUrl(
function openInBrowser(url: string): void {
const platform = process.platform;
let command: string;
let args: string[];

if (platform === "darwin") {
command = `open "${url}"`;
command = "open";
args = [url];
} else if (platform === "linux") {
command = `xdg-open "${url}"`;
command = "xdg-open";
args = [url];
} else if (platform === "win32") {
command = `start "" "${url}"`;
command = "cmd";
args = ["/c", "start", "", url];
} else {
throw new Error(`Unsupported platform: ${platform}. Please open manually:\n${url}`);
}

exec(command, (error) => {
execFile(command, args, (error) => {
if (error) {
logger.error(`Failed to open browser: ${error.message}`);
console.log(`URL: ${url}`);
Expand Down
49 changes: 26 additions & 23 deletions src/play/tui/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from "node:child_process";
import { execFile } from "node:child_process";
import { Box, render, useApp, useInput, useStdout } from "ink";
import { useCallback, useMemo, useRef, useState } from "react";
import type { ZephyrV2Client } from "zephyr-api-client";
Expand Down Expand Up @@ -295,21 +295,24 @@ function App({
const url = `${base}/projects/${projectKey}?selectedItem=com.atlassian.plugins.atlassian-connect-plugin:com.kanoah.test-manager__main-project-page#!/v2/testPlayer/${cycleKey}`;

// Copy test case key to clipboard for pasting into the search box
const clipCmd =
process.platform === "darwin"
? "pbcopy"
: process.platform === "win32"
? "clip"
: "xclip -selection clipboard";
exec(`printf '%s' "${testCaseKey}" | ${clipCmd}`);

const openCmd =
process.platform === "darwin"
? `open "${url}"`
: process.platform === "win32"
? `start "" "${url}"`
: `xdg-open "${url}"`;
exec(openCmd);
if (process.platform === "darwin") {
execFile("pbcopy", [], (err) => err && actions.setError(`Clipboard failed: ${err.message}`))
.stdin?.end(testCaseKey);
} else if (process.platform === "win32") {
execFile("clip", [], (err) => err && actions.setError(`Clipboard failed: ${err.message}`))
.stdin?.end(testCaseKey);
} else {
execFile("xclip", ["-selection", "clipboard"], (err) => err && actions.setError(`Clipboard failed: ${err.message}`))
.stdin?.end(testCaseKey);
}

if (process.platform === "darwin") {
execFile("open", [url]);
} else if (process.platform === "win32") {
execFile("cmd", ["/c", "start", "", url]);
} else {
execFile("xdg-open", [url]);
}

setSyncMessage(`Copied "${testCaseKey}" - paste in Search box`);
if (syncMessageTimerRef.current) clearTimeout(syncMessageTimerRef.current);
Expand All @@ -326,13 +329,13 @@ function App({
const base = jiraBaseUrl.replace(/\/+$/, "");
const testCaseKey = selectedTestCase.testCase.key;
const url = `${base}/projects/${projectKey}?selectedItem=com.atlassian.plugins.atlassian-connect-plugin:com.kanoah.test-manager__main-project-page#!/v2/testCase/${testCaseKey}`;
const openCmd =
process.platform === "darwin"
? `open "${url}"`
: process.platform === "win32"
? `start "" "${url}"`
: `xdg-open "${url}"`;
exec(openCmd);
if (process.platform === "darwin") {
execFile("open", [url]);
} else if (process.platform === "win32") {
execFile("cmd", ["/c", "start", "", url]);
} else {
execFile("xdg-open", [url]);
}
}
return;
}
Expand Down