Skip to content

Commit 0b9290b

Browse files
committed
adjust tryRun to take full options
1 parent c3ef6e1 commit 0b9290b

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

packages/core/src/awsService/ec2/sshKeyPair.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ToolkitError } from '../../shared/errors'
88
import { tryRun } from '../../shared/utilities/pathFind'
99
import { Timeout } from '../../shared/utilities/timeoutUtils'
1010
import { findAsync } from '../../shared/utilities/collectionUtils'
11+
import { RunParameterContext } from '../../shared/utilities/childProcess'
1112

1213
type sshKeyType = 'rsa' | 'ed25519'
1314

@@ -46,16 +47,12 @@ export class SshKeyPair {
4647
* @param keyType type of key to generate.
4748
*/
4849
public static async tryKeyGen(keyPath: string, keyType: sshKeyType): Promise<boolean> {
49-
const overrideKeys = async (proc: any, _t: string) => {
50-
await proc.send('yes')
50+
const overrideKeys = async (_t: string, context: RunParameterContext) => {
51+
await context.send('yes')
5152
}
52-
return !(await tryRun(
53-
'ssh-keygen',
54-
['-t', keyType, '-N', '', '-q', '-f', keyPath],
55-
'yes',
56-
'unknown key type',
57-
overrideKeys
58-
))
53+
return !(await tryRun('ssh-keygen', ['-t', keyType, '-N', '', '-q', '-f', keyPath], 'yes', 'unknown key type', {
54+
onStdout: overrideKeys,
55+
}))
5956
}
6057

6158
public static async tryKeyTypes(keyPath: string, keyTypes: sshKeyType[]): Promise<boolean> {

packages/core/src/shared/utilities/childProcess.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import * as crossSpawn from 'cross-spawn'
88
import * as logger from '../logger'
99
import { Timeout, CancellationError, waitUntil } from './timeoutUtils'
1010

11-
interface RunParameterContext {
11+
export interface RunParameterContext {
1212
/** Reports an error parsed from the stdin/stdout streams. */
1313
reportError(err: string | Error): void
1414
/** Attempts to stop the running process. See {@link ChildProcess.stop}. */
1515
stop(force?: boolean, signal?: string): void
16+
/** Send string to stdin */
17+
send(text: string): Promise<void>
1618
/** The active `Timeout` object (if applicable). */
1719
readonly timeout?: Timeout
1820
/** The logger being used by the process. */
@@ -160,6 +162,7 @@ export class ChildProcess {
160162
timeout,
161163
logger: this.#log,
162164
stop: this.stop.bind(this),
165+
send: this.send.bind(this),
163166
reportError: (err) => errorHandler(err instanceof Error ? err : new Error(err)),
164167
}
165168

packages/core/src/shared/utilities/pathFind.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as vscode from 'vscode'
77
import * as path from 'path'
88
import fs from '../../shared/fs/fs'
9-
import { ChildProcess } from './childProcess'
9+
import { ChildProcess, ChildProcessOptions } from './childProcess'
1010
import { GitExtension } from '../extensions/git'
1111
import { Settings } from '../settings'
1212
import { getLogger } from '../logger/logger'
@@ -31,11 +31,10 @@ export async function tryRun(
3131
args: string[],
3232
logging: 'yes' | 'no' | 'noresult' = 'yes',
3333
expected?: string,
34-
onStdout?: (proc: ChildProcess, text: string) => void
34+
opt?: ChildProcessOptions
3535
): Promise<boolean> {
3636
const proc = new ChildProcess(p, args, { logging: 'no' })
37-
const options = onStdout ? { onStdout: (text: string) => onStdout(proc, text) } : {}
38-
const r = await proc.run(options)
37+
const r = await proc.run(opt)
3938
const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected))
4039
if (logging === 'noresult') {
4140
getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc)

0 commit comments

Comments
 (0)