|
6 | 6 | import * as vscode from 'vscode' |
7 | 7 | import * as path from 'path' |
8 | 8 | import fs from '../../shared/fs/fs' |
| 9 | +import { ChildProcess, ChildProcessOptions } from './processUtils' |
9 | 10 | import { GitExtension } from '../extensions/git' |
10 | 11 | import { Settings } from '../settings' |
11 | | -import { ChildProcess, ChildProcessOptions } from './processUtils' |
12 | | -import { getLogger } from '..' |
| 12 | +import { getLogger } from '../logger/logger' |
13 | 13 |
|
14 | 14 | /** Full path to VSCode CLI. */ |
15 | 15 | let vscPath: string |
16 | 16 | let sshPath: string |
17 | 17 | let gitPath: string |
18 | 18 | let bashPath: string |
19 | 19 |
|
| 20 | +/** |
| 21 | + * Tries to execute a program at path `p` with the given args and |
| 22 | + * optionally checks the output for `expected`. |
| 23 | + * |
| 24 | + * @param p path to a program to execute |
| 25 | + * @param args program args |
| 26 | + * @param doLog log failures |
| 27 | + * @param expected output must contain this string |
| 28 | + */ |
| 29 | +export async function tryRun( |
| 30 | + p: string, |
| 31 | + args: string[], |
| 32 | + logging: 'yes' | 'no' | 'noresult' = 'yes', |
| 33 | + expected?: string, |
| 34 | + opt?: ChildProcessOptions |
| 35 | +): Promise<boolean> { |
| 36 | + const proc = new ChildProcess(p, args, { logging: 'no' }) |
| 37 | + const r = await proc.run(opt) |
| 38 | + const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected)) |
| 39 | + if (logging === 'noresult') { |
| 40 | + getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc) |
| 41 | + } else if (logging !== 'no') { |
| 42 | + getLogger().info('tryRun: %s: %s %O', ok ? 'ok' : 'failed', proc, proc.result()) |
| 43 | + } |
| 44 | + return ok |
| 45 | +} |
| 46 | + |
20 | 47 | /** |
21 | 48 | * Gets the fullpath to `code` (VSCode CLI), or falls back to "code" (not |
22 | 49 | * absolute) if it works. |
@@ -88,7 +115,7 @@ export async function findTypescriptCompiler(): Promise<string | undefined> { |
88 | 115 | * Gets the configured `ssh` path, or falls back to "ssh" (not absolute), |
89 | 116 | * or tries common locations, or returns undefined. |
90 | 117 | */ |
91 | | -export async function findSshPath(useCache: boolean = true): Promise<string | undefined> { |
| 118 | +export async function findSshPath(useCache: boolean): Promise<string | undefined> { |
92 | 119 | if (useCache && sshPath !== undefined) { |
93 | 120 | return sshPath |
94 | 121 | } |
@@ -153,30 +180,3 @@ export async function findBashPath(): Promise<string | undefined> { |
153 | 180 | } |
154 | 181 | } |
155 | 182 | } |
156 | | - |
157 | | -/** |
158 | | - * Tries to execute a program at path `p` with the given args and |
159 | | - * optionally checks the output for `expected`. |
160 | | - * |
161 | | - * @param p path to a program to execute |
162 | | - * @param args program args |
163 | | - * @param doLog log failures |
164 | | - * @param expected output must contain this string |
165 | | - */ |
166 | | -export async function tryRun( |
167 | | - p: string, |
168 | | - args: string[], |
169 | | - logging: 'yes' | 'no' | 'noresult' = 'yes', |
170 | | - expected?: string, |
171 | | - opt?: ChildProcessOptions |
172 | | -): Promise<boolean> { |
173 | | - const proc = new ChildProcess(p, args, { logging: 'no' }) |
174 | | - const r = await proc.run(opt) |
175 | | - const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected)) |
176 | | - if (logging === 'noresult') { |
177 | | - getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc) |
178 | | - } else if (logging !== 'no') { |
179 | | - getLogger().info('tryRun: %s: %s %O', ok ? 'ok' : 'failed', proc, proc.result()) |
180 | | - } |
181 | | - return ok |
182 | | -} |
0 commit comments