Skip to content

Commit f7219f9

Browse files
committed
WIP add logic for first pass on recommend command
1 parent c3f5548 commit f7219f9

1 file changed

Lines changed: 24 additions & 107 deletions

File tree

Lines changed: 24 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,42 @@
11
import color from '@heroku-cli/color'
22
import {Command, flags} from '@heroku-cli/command'
33
import * as Heroku from '@heroku-cli/schema'
4-
import {ux} from '@oclif/core'
4+
import {Args, ux} from '@oclif/core'
55
import * as lodash from 'lodash'
66
const clipboard = require('copy-paste')
77
const {exec} = require('child_process')
88
const {promisify} = require('util')
99
const execAsync = promisify(exec)
1010

11-
const getLocalNodeVersion = async () => {
12-
const {stdout} = await execAsync('node -v')
13-
return stdout
14-
}
15-
16-
const getInstallMethod = () => {
17-
return 'brew'
18-
}
19-
20-
const getInstallLocation = async () => {
21-
const {stdout} = await execAsync('which heroku')
22-
const formattedOutput = stdout.replace(/\n/g, '')
23-
return formattedOutput
24-
}
25-
26-
const getLocalProxySettings = async (unmasked = false) => {
27-
const command = `httpsProxy=$(scutil --proxy | awk -F': ' '/HTTPSProxy/ {print $2}')
28-
29-
# Check if HTTPSProxy has a value
30-
if [ -n "$httpsProxy" ]; then
31-
echo "$httpsProxy"
32-
else
33-
echo "no proxy set"
34-
fi`
35-
36-
const {stdout} = await execAsync(command)
37-
const hasProxySet = !stdout.includes('no proxy set')
38-
39-
if (unmasked) {
40-
return stdout
41-
}
42-
43-
return hasProxySet ? 'xxxxx\n' : stdout
44-
}
45-
46-
const getInstalledPLugins = async () => {
47-
const {stdout} = await execAsync('heroku plugins')
48-
return stdout
49-
}
50-
51-
const getHerokuStatus = async () => {
52-
const {stdout} = await execAsync('heroku status')
53-
return stdout
54-
}
55-
56-
const copyToClipboard = async (value: any) => {
57-
clipboard.copy(value)
58-
}
59-
60-
export default class DoctorVitals extends Command {
61-
static description = 'list local user setup for debugging'
11+
export default class DoctorRecommend extends Command {
12+
static description = 'recieve the latest tips, general playbooks, and resources when encountering cli issues'
6213
static topic = 'doctor'
14+
static examples = [
15+
'$ heroku doctor:recommend <command>',
16+
'$ heroku doctor:recommend --type command "Command will not show output"',
17+
'$ heroku doctor:recommend --type install "Cli is erroring during install"',
18+
'$ heroku doctor:recommend --type error "I get an error when running..."',
19+
'$ heroku doctor:recommend --type network "I can not push my latest release"',
20+
'$ heroku doctor:recommend --type permissions "I cannot get access to..."',
21+
]
22+
23+
static args = {
24+
statement: Args.string({description: 'statement of problem user is enountering', required: true}),
25+
}
6326

6427
static flags = {
65-
unmask: flags.boolean({description: 'unmasks fields heroku has deemed potentially sensitive', required: false}),
28+
type: flags.string({description: 'type of help required', required: false}),
6629
'copy-results': flags.boolean({description: 'copies results to clipboard', required: false}),
67-
json: flags.boolean({description: 'display as json', required: false}),
6830
}
6931

7032
async run() {
71-
const {flags} = await this.parse(DoctorVitals)
72-
const copyResults = flags['copy-results']
73-
const time = new Date()
74-
const dateChecked = time.toISOString().split('T')[0]
75-
const cliInstallMethod = getInstallMethod()
76-
const cliInstallLocation = await getInstallLocation()
77-
const os = this.config.platform
78-
const cliVersion = `v${this.config.version}`
79-
const nodeVersion = await getLocalNodeVersion()
80-
const networkConfig = {
81-
httpsProxy: await getLocalProxySettings(flags.unmask),
82-
}
83-
const installedPlugins = await getInstalledPLugins()
84-
const herokuStatus = await getHerokuStatus()
85-
86-
const isHerokuUp = true
87-
let copiedResults = ''
88-
89-
ux.styledHeader(`${color.heroku('Heroku CLI Doctor')} · ${color.cyan(`User Local Setup on ${dateChecked}`)}`)
90-
ux.log(`${color.cyan('CLI Install Method:')} ${cliInstallMethod}`)
91-
ux.log(`${color.cyan('CLI Install Location:')} ${cliInstallLocation}`)
92-
ux.log(`${color.cyan('OS:')} ${os}`)
93-
ux.log(`${color.cyan('Heroku CLI Version:')} ${cliVersion}`)
94-
ux.log(`${color.cyan('Node Version:')} ${nodeVersion}`)
95-
96-
ux.log(`${color.cyan('Network Config')}`)
97-
ux.log(`HTTPSProxy: ${networkConfig.httpsProxy}`)
98-
99-
ux.log(`${color.cyan('Installed Plugins')}`)
100-
ux.log(`${installedPlugins}`)
101-
102-
ux.log(`${color.bold(color.heroku('Heroku Status'))}`)
103-
ux.log(`${color.bold(color.heroku('----------------------------------------'))}`)
104-
ux.log(isHerokuUp ? color.green(herokuStatus) : color.red(herokuStatus))
105-
106-
if (copyResults) {
107-
// copy results to clipboard here
108-
copiedResults += `Heroku CLI Doctor · User Local Setup on ${dateChecked}\n`
109-
copiedResults += `CLI Install Method: ${cliInstallMethod}\n`
110-
copiedResults += `CLI Install Location: ${cliInstallLocation}\n`
111-
copiedResults += `OS: ${os}\n`
112-
copiedResults += `Heroku CLI Version: ${cliVersion}\n`
113-
copiedResults += `Node Version: ${nodeVersion}\n`
114-
copiedResults += 'Network Config\n'
115-
copiedResults += `HTTPSProxy: ${networkConfig.httpsProxy}\n`
116-
copiedResults += 'Installed Plugins\n'
117-
copiedResults += `${installedPlugins}\n`
118-
copiedResults += 'Heroku Status\n'
119-
copiedResults += '----------------------------------------\n'
120-
copiedResults += herokuStatus
121-
}
122-
123-
await copyToClipboard(copiedResults)
33+
const {flags} = await this.parse(DoctorRecommend)
34+
ux.log(`${color.bold(`${color.heroku('Recommendations')}`)}`)
35+
ux.log(`${color.bold(`${color.heroku('-------------------------------------------')}`)}`)
36+
ux.log(`- Visit ${color.cyan('"https://devcenter.heroku.com/articles/heroku-cli"')} for more install information`)
37+
ux.log('- Try reinstalling the heroku cli')
38+
ux.log(`- Try running ${color.cyan('"$ heroku doctor:diagnose"')}`)
39+
ux.log(`- Try running ${color.cyan('"$ heroku doctor:ask"')}`)
40+
ux.log('- Check which version of the heroku cli your are running')
12441
}
12542
}

0 commit comments

Comments
 (0)