Skip to content

Commit

Permalink
fix: use new inquirer (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc authored Jan 8, 2024
1 parent 744820a commit bb1864b
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 21 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@inquirer/input": "^1.2.14",
"@oclif/core": "^3.16.0",
"@salesforce/core": "^6.4.2",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^5.0.13",
"@salesforce/sf-plugins-core": "^7.0.0",
"got": "^13.0.0",
"marked": "^4.3.0",
"marked-terminal": "^4.2.0",
Expand Down
10 changes: 2 additions & 8 deletions src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import { EOL } from 'node:os';
import { resolve as pathResolve, join } from 'node:path';
import { spawn } from 'node:child_process';

import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SfError } from '@salesforce/core';
import open from 'open';
import got from 'got';
import { ProxyAgent } from 'proxy-agent';
import { Doctor as SFDoctor, SfDoctor, SfDoctorDiagnosis } from '../doctor.js';
import { DiagnosticStatus } from '../diagnostics.js';
import { prompts } from '../shared/prompts.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-info', 'doctor');
Expand Down Expand Up @@ -123,13 +123,7 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
agent: { https: new ProxyAgent() },
});

const title = (
await this.prompt({
type: 'input',
name: 'title',
message: 'Enter a title for your new issue',
})
).title as string;
const title = await prompts.titleInput();

const url = encodeURI(
`https://github.com/forcedotcom/cli/issues/new?title=${title}&body=${this.generateIssueMarkdown(
Expand Down
16 changes: 16 additions & 0 deletions src/shared/prompts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import input from '@inquirer/input';

// a wrapper object to make inquirer prompts stubbable by sinon
export const prompts = {
titleInput: async (): Promise<string> =>
input({
message: 'Enter a title for your new issue',
}),
};
5 changes: 3 additions & 2 deletions test/commands/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { SfCommand } from '@salesforce/sf-plugins-core';
import DoctorCmd from '../../src/commands/doctor.js';
import { Diagnostics, DiagnosticStatus, Doctor, SfDoctorDiagnosis } from '../../src/index.js';
import { formatPlugins } from '../../src/doctor.js';
import { prompts } from '../../src/shared/prompts.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-info', 'doctor');

let oclifConfig: Config;
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('Doctor Command', () => {
const runDoctorCmd = async (params: string[]) => {
const cmd = new TestDoctor(params, oclifConfig);
uxLogStub = stubMethod(sandbox, SfCommand.prototype, 'log');
promptStub = stubMethod(sandbox, SfCommand.prototype, 'prompt').resolves({ title: 'my new and crazy issue' });
promptStub = sandbox.stub(prompts, 'titleInput').resolves('my new and crazy issue');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
openStub = sandbox.stub(cmd, 'openUrl').resolves();
Expand Down
115 changes: 105 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,59 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz#e5211452df060fa8522b55c7b3c0c4d1981cb044"
integrity sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==

"@inquirer/confirm@^2.0.15":
version "2.0.15"
resolved "https://registry.yarnpkg.com/@inquirer/confirm/-/confirm-2.0.15.tgz#b5512ed190efd8c5b96e0969115756b48546ab36"
integrity sha512-hj8Q/z7sQXsF0DSpLQZVDhWYGN6KLM/gNjjqGkpKwBzljbQofGjn0ueHADy4HUY+OqDHmXuwk/bY+tZyIuuB0w==
dependencies:
"@inquirer/core" "^5.1.1"
"@inquirer/type" "^1.1.5"
chalk "^4.1.2"

"@inquirer/core@^5.1.1":
version "5.1.1"
resolved "https://registry.yarnpkg.com/@inquirer/core/-/core-5.1.1.tgz#849d4846aea68371c133df6ec9059f5e5bd30d30"
integrity sha512-IuJyZQUg75+L5AmopgnzxYrgcU6PJKL0hoIs332G1Gv55CnmZrhG6BzNOeZ5sOsTi1YCGOopw4rYICv74ejMFg==
dependencies:
"@inquirer/type" "^1.1.5"
"@types/mute-stream" "^0.0.4"
"@types/node" "^20.9.0"
"@types/wrap-ansi" "^3.0.0"
ansi-escapes "^4.3.2"
chalk "^4.1.2"
cli-spinners "^2.9.1"
cli-width "^4.1.0"
figures "^3.2.0"
mute-stream "^1.0.0"
run-async "^3.0.0"
signal-exit "^4.1.0"
strip-ansi "^6.0.1"
wrap-ansi "^6.2.0"

"@inquirer/input@^1.2.14":
version "1.2.14"
resolved "https://registry.yarnpkg.com/@inquirer/input/-/input-1.2.14.tgz#8951867618bb5cd16dd096e02404eec225a92207"
integrity sha512-tISLGpUKXixIQue7jypNEShrdzJoLvEvZOJ4QRsw5XTfrIYfoWFqAjMQLerGs9CzR86yAI89JR6snHmKwnNddw==
dependencies:
"@inquirer/core" "^5.1.1"
"@inquirer/type" "^1.1.5"
chalk "^4.1.2"

"@inquirer/password@^1.1.14":
version "1.1.14"
resolved "https://registry.yarnpkg.com/@inquirer/password/-/password-1.1.14.tgz#c1fc139efe84a38986870a1bcf80718050f82bbf"
integrity sha512-vL2BFxfMo8EvuGuZYlryiyAB3XsgtbxOcFs4H9WI9szAS/VZCAwdVqs8rqEeaAf/GV/eZOghIOYxvD91IsRWSg==
dependencies:
"@inquirer/input" "^1.2.14"
"@inquirer/type" "^1.1.5"
ansi-escapes "^4.3.2"
chalk "^4.1.2"

"@inquirer/type@^1.1.5":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@inquirer/type/-/type-1.1.5.tgz#b8c171f755859c8159b10e41e1e3a88f0ca99d7f"
integrity sha512-wmwHvHozpPo4IZkkNtbYenem/0wnfI6hvOcGKmPEa0DwuaH5XUQzFqy6OpEpjEegZMhYIk8HDYITI16BPLtrRA==

"@isaacs/cliui@^8.0.2":
version "8.0.2"
resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"
Expand Down Expand Up @@ -1086,6 +1139,19 @@
chalk "^4"
inquirer "^8.2.5"

"@salesforce/sf-plugins-core@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@salesforce/sf-plugins-core/-/sf-plugins-core-7.0.0.tgz#56cb4eaafcd04a183938d86c5e93323e037b15ab"
integrity sha512-vl53Ee0/eg9wgvtWro6kX82/943s28Hph/o3lTQk6URorfqMC+zH0RGKJj1X0VKeLhDSOCRYXqIu54jE8AZ/3g==
dependencies:
"@inquirer/confirm" "^2.0.15"
"@inquirer/password" "^1.1.14"
"@oclif/core" "^3.16.0"
"@salesforce/core" "^6.4.2"
"@salesforce/kit" "^3.0.15"
"@salesforce/ts-types" "^2.0.9"
chalk "^5.3.0"

"@salesforce/ts-sinon@^1.4.19":
version "1.4.19"
resolved "https://registry.yarnpkg.com/@salesforce/ts-sinon/-/ts-sinon-1.4.19.tgz#64157b6c8cf4a3c637867e2ddd90c2d058c334f7"
Expand Down Expand Up @@ -1370,10 +1436,19 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.6.tgz#818551d39113081048bdddbef96701b4e8bb9d1b"
integrity sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==

"@types/node@*":
version "20.5.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.5.4.tgz#4666fb40f9974d60c53c4ff554315860ba4feab8"
integrity sha512-Y9vbIAoM31djQZrPYjpTLo0XlaSwOIsrlfE3LpulZeRblttsLQRFRlBAppW0LOxyT3ALj2M5vU1ucQQayQH3jA==
"@types/mute-stream@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@types/mute-stream/-/mute-stream-0.0.4.tgz#77208e56a08767af6c5e1237be8888e2f255c478"
integrity sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==
dependencies:
"@types/node" "*"

"@types/node@*", "@types/node@^20.9.0":
version "20.10.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.6.tgz#a3ec84c22965802bf763da55b2394424f22bfbb5"
integrity sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==
dependencies:
undici-types "~5.26.4"

"@types/[email protected]":
version "20.5.1"
Expand Down Expand Up @@ -1462,6 +1537,11 @@
"@types/expect" "^1.20.4"
"@types/node" "*"

"@types/wrap-ansi@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd"
integrity sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==

"@typescript-eslint/eslint-plugin@^6.10.0":
version "6.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.11.0.tgz#52aae65174ff526576351f9ccd41cea01001463f"
Expand Down Expand Up @@ -2407,10 +2487,10 @@ cli-progress@^3.12.0:
dependencies:
string-width "^4.2.3"

cli-spinners@^2.5.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.9.0.tgz#5881d0ad96381e117bbe07ad91f2008fe6ffd8db"
integrity sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==
cli-spinners@^2.5.0, cli-spinners@^2.9.1:
version "2.9.2"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.9.2.tgz#1773a8f4b9c4d6ac31563df53b3fc1d79462fe41"
integrity sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==

cli-table3@^0.6.0:
version "0.6.3"
Expand All @@ -2433,6 +2513,11 @@ cli-width@^3.0.0:
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6"
integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==

cli-width@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-4.1.0.tgz#42daac41d3c254ef38ad8ac037672130173691c5"
integrity sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==

cliui@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1"
Expand Down Expand Up @@ -3520,7 +3605,7 @@ faye@^1.4.0:
tough-cookie "*"
tunnel-agent "*"

figures@^3.0.0:
figures@^3.0.0, figures@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af"
integrity sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==
Expand Down Expand Up @@ -5688,6 +5773,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

mute-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e"
integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==

[email protected]:
version "3.3.3"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25"
Expand Down Expand Up @@ -7025,6 +7115,11 @@ run-async@^2.0.0, run-async@^2.4.0:
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==

run-async@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-3.0.0.tgz#42a432f6d76c689522058984384df28be379daad"
integrity sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==

run-parallel@^1.1.9:
version "1.2.0"
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
Expand Down Expand Up @@ -7235,7 +7330,7 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==

signal-exit@^4.0.1:
signal-exit@^4.0.1, signal-exit@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04"
integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==
Expand Down

0 comments on commit bb1864b

Please sign in to comment.