Skip to content

Commit 6cd5e75

Browse files
authored
use a list of sites to chose from rather than entering the name manually (#335)
* use a list of sites to chose from rather than entering the name manually * make tests pass by removing error
1 parent 0361916 commit 6cd5e75

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

src/utils/link/link-by-prompt.js

+16-35
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const { track } = require('../telemetry')
88
module.exports = async function linkPrompts(context) {
99
const { api, state } = context.netlify
1010

11-
const SITE_NAME_PROMPT = 'Site Name'
12-
const SITE_ID_PROMPT = 'Site ID'
11+
const SITE_NAME_PROMPT = 'Choose from a list of your sites'
12+
const SITE_ID_PROMPT = `Use a site ID`
1313

14-
let GIT_REMOTE_PROMPT = `Use current git remote URL`
14+
let GIT_REMOTE_PROMPT = `Use a current git remote URL`
1515
let site
1616
// Get git remote data if exists
1717
const repoInfo = await getRepoData()
@@ -110,47 +110,28 @@ Run ${chalk.cyanBright('`git remote -v`')} to see a list of your git remotes.`)
110110
}
111111
case SITE_NAME_PROMPT: {
112112
kind = 'byName'
113-
const { siteName } = await inquirer.prompt([
114-
{
115-
type: 'input',
116-
name: 'siteName',
117-
message: 'What is the name of the site?'
118-
}
119-
])
113+
120114
let sites
121115
try {
122-
sites = await api.listSites({
123-
name: siteName,
124-
filter: 'all'
125-
})
116+
sites = await api.listSites()
126117
} catch (e) {
127-
if (e.status === 404) {
128-
context.error(`${siteName} not found`)
129-
} else {
130-
context.error(e)
131-
}
118+
context.error(e)
132119
}
133120

134121
if (sites.length === 0) {
135-
context.error(`No sites found named ${siteName}`)
122+
context.error(`You don't have any sites. Use netlify 'sites:create' to create a site.`)
136123
}
137124

138-
if (sites.length > 1) {
139-
const { selectedSite } = await inquirer.prompt([
140-
{
141-
type: 'list',
142-
name: 'selectedSite',
143-
paginated: true,
144-
choices: sites.map(site => ({ name: site.name, value: site }))
145-
}
146-
])
147-
if (!selectedSite) {
148-
context.error('No site selected')
125+
const siteSelection = await inquirer.prompt([
126+
{
127+
type: 'list',
128+
name: 'siteName',
129+
message: 'What is the name of the site?',
130+
paginated: true,
131+
choices: sites.map(site => ({ name: site.name, value: site }))
149132
}
150-
site = selectedSite
151-
} else {
152-
site = sites[0]
153-
}
133+
])
134+
site = siteSelection.siteName
154135
break
155136
}
156137
case SITE_ID_PROMPT: {

0 commit comments

Comments
 (0)