Skip to content

Commit b3dffd9

Browse files
committed
feat: add filterItems option and missing bin commands
1 parent ac1a948 commit b3dffd9

5 files changed

Lines changed: 28 additions & 17 deletions

File tree

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
"prepublishOnly": "echo This package is meant to be published by semantic-release from the dist build directory. && exit 1"
1111
},
1212
"bin": {
13-
"select-ec2-instance": "./dist/selectEC2Instance.js",
14-
"select-ebs-snapshot": "./dist/selectEBSSnapshot.js",
13+
"select-cloud-formation-stack": "./dist/selectCloudFormationStack.js",
14+
"select-cloudwatch-log-event": "./dist/selectCloudWatchLogEvent.js",
1515
"select-cloudwatch-log-group": "./dist/selectCloudWatchLogGroup.js",
1616
"select-cloudwatch-log-stream": "./dist/selectCloudWatchLogStream.js",
17-
"select-cloudwatch-log-event": "./dist/selectCloudWatchLogEvent.js"
17+
"select-ebs-snapshot": "./dist/selectEBSSnapshot.js",
18+
"select-ec2-instance": "./dist/selectEC2Instance.js",
19+
"select-route-53-hosted-zone": "./dist/selectRoute53HostedZone.js",
20+
"select-route-53-record-set": "./dist/selectRoute53RecordSet.js"
1821
},
1922
"repository": {
2023
"type": "git",

src/makeSelector.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export function makeSelector<OtherOptions, Client, Page, Item, Id>({
146146
stdout = process.stderr,
147147
style,
148148
clearFirst,
149+
filterItems = () => true,
149150
...rest
150151
}: {
151152
client?: Client
@@ -156,6 +157,7 @@ export function makeSelector<OtherOptions, Client, Page, Item, Id>({
156157
clearFirst?: boolean
157158
stdin?: Readable
158159
stdout?: Writable
160+
filterItems?: (item: Item) => boolean
159161
} & OtherOptions = {} as any
160162
): Promise<Item> => {
161163
const region = await (client as any).config.region()
@@ -186,7 +188,7 @@ export function makeSelector<OtherOptions, Client, Page, Item, Id>({
186188
cancelationToken: CancelationToken,
187189
yieldChoices: (choices: Choices<Item>) => void
188190
): Promise<Choices<Item> | void> => {
189-
const choices: Choices<Item> = []
191+
let choices: Choices<Item> = []
190192

191193
if (!search && useRecents) {
192194
choices.push(
@@ -227,6 +229,7 @@ export function makeSelector<OtherOptions, Client, Page, Item, Id>({
227229
title: createTitle(item),
228230
})
229231
}
232+
choices = choices.filter((c) => filterItems(c.value))
230233
if (!choices.length) {
231234
choices.push({
232235
title: chalk.gray(`No matching ${things} found`),

src/recents.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os from 'os'
22
import path from 'path'
33
import fs from 'fs-extra'
4-
import { InstanceForChoice } from './selectEC2Instance'
54

65
/* eslint-disable @typescript-eslint/no-explicit-any */
76
const RECENTS_FILE = path.join(
@@ -47,7 +46,7 @@ export async function addRecent<T>(
4746
const key = JSON.stringify(category)
4847
await fs.mkdirs(path.dirname(RECENTS_FILE))
4948
const original = await fs.readJson(RECENTS_FILE).catch(() => ({}))
50-
const list: InstanceForChoice[] = (original?.[key] || []).filter(
49+
const list: object[] = (original?.[key] || []).filter(
5150
(c: any) => getId(c) !== getId(newRecent)
5251
)
5352
list.unshift(newRecent as any)

src/selectCloudFormationStack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ if (require.main === module) {
6363
await cli({
6464
select: () => selectCloudFormationStack(),
6565
queries: {
66+
stackId: 'StackId',
6667
stackName: 'StackName',
6768
},
6869
})

src/selectCloudWatchLogEvent.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default async function selectCloudWatchLogEvent({
5555
logs = new CloudWatchLogsClient(),
5656
logGroupName,
5757
logGroupIdentifier,
58-
logStreamName,
58+
logStreamName: _logStreamName,
5959
startTime,
6060
message,
6161
useRecents = true,
@@ -91,16 +91,21 @@ export default async function selectCloudWatchLogEvent({
9191
}))
9292
}
9393

94+
const logStreamName =
95+
_logStreamName ||
96+
(
97+
await selectCloudWatchLogStream({
98+
logs,
99+
logGroupName,
100+
logGroupIdentifier,
101+
stdin,
102+
stdout,
103+
useRecents,
104+
...autocompleteOpts,
105+
})
106+
).logStreamName
94107
if (!logStreamName) {
95-
;({ logStreamName } = await selectCloudWatchLogStream({
96-
logs,
97-
logGroupName,
98-
logGroupIdentifier,
99-
stdin,
100-
stdout,
101-
useRecents,
102-
...autocompleteOpts,
103-
}))
108+
throw new Error(`failed to get logStreamName`)
104109
}
105110

106111
if (startTime == null) {
@@ -190,7 +195,7 @@ export default async function selectCloudWatchLogEvent({
190195
stopOnSameToken: true,
191196
},
192197
{
193-
logStreamNames: [logStreamName!],
198+
logStreamNames: [logStreamName],
194199
filterPattern,
195200
logGroupIdentifier,
196201
logGroupName,

0 commit comments

Comments
 (0)