-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgoogle-cloud-sql-instance.ts
More file actions
31 lines (27 loc) · 972 Bytes
/
google-cloud-sql-instance.ts
File metadata and controls
31 lines (27 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import _ from 'lodash'
import {
fetchGoogleCloudSqlInstances,
GoogleCloudSqlInstance,
} from '../../../lib/gcloud/sql-instances.js'
import { ConfigurationCreateAnswers } from '../../../lib/types.js'
import { searchByKey } from '../../../lib/util/search.js'
import { tryCatch } from '../../../lib/util/error.js'
const formatInstance = (instance: GoogleCloudSqlInstance) => {
const { name, region } = instance
return {
name: `${name} (${region})`,
short: name,
value: _.pick(instance, 'connectionName', 'port'),
}
}
const source = tryCatch((answers: ConfigurationCreateAnswers, input?: string) => {
const instances = fetchGoogleCloudSqlInstances(answers.googleCloudProject)
const filtered = searchByKey(instances, 'connectionName', input)
return filtered.map(formatInstance)
})
export const googleCloudSqlInstancePrompt = {
type: 'autocomplete',
name: 'googleCloudSqlInstance',
message: 'Choose Google Cloud SQL instance:',
source,
}