Skip to content

Commit 29997b8

Browse files
committed
Add interactive option to example, fix output
1 parent b82f3c2 commit 29997b8

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

examples/login.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import {Command} from '../src'
2-
2+
import {flags} from '../src'
33
class LoginCommand extends Command {
4+
static flags = {
5+
interactive: flags.boolean({char: 'i', description: 'login with username/password'}),
6+
}
7+
48
async run() {
9+
const {flags} = await this.parse(LoginCommand)
510
this.log('logging in')
6-
await this.heroku.login()
11+
const interactive = (flags.interactive) ? 'interactive' : undefined
12+
await this.heroku.login({method: interactive})
713
}
814
}
915

10-
(LoginCommand.run([]) as any)
16+
(LoginCommand.run(process.argv.slice(2)) as any)
1117
.catch(require('@oclif/core').Errors.handle)

examples/run.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ if [ -z "$1" ]; then
55
exit 1
66
fi
77

8-
if [ ! -f "examples/$1.ts" ]; then
9-
echo "Command '$1' not found in examples directory"
8+
COMMAND=$1
9+
shift
10+
11+
if [ ! -f "examples/$COMMAND.ts" ]; then
12+
echo "Command '$COMMAND' not found in examples directory"
1013
exit 1
1114
fi
1215

13-
./node_modules/.bin/ts-node "examples/$1.ts"
16+
./node_modules/.bin/ts-node "examples/$COMMAND.ts" "$@"

src/flags/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
export {app, remote} from './app'
1+
import {Flags} from '@oclif/core'
22

3+
export {app, remote} from './app'
34
export {org} from './org'
45
export {pipeline} from './pipeline'
56
export {team} from './team'
7+
8+
// Explicitly export oclif flag types using object destructuring, sorted alphabetically
9+
export const {boolean, custom, directory, file, integer, option, string, url} = Flags
10+
611
export {Flags} from '@oclif/core'

src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

2-
// import * as completions from './completions'
3-
42
export {APIClient} from './api-client'
53
export {Command, Command as default} from './command'
6-
4+
export * as completions from './completions'
75
export * as flags from './flags'
86
export {vars} from './vars'

src/login.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {Interfaces, ux} from '@oclif/core'
77
import inquirer, {QuestionCollection} from 'inquirer'
88
import PressToContinuePrompt from 'inquirer-press-to-continue'
99
import Netrc from 'netrc-parser'
10+
import * as os from 'node:os'
1011
import open from 'open'
11-
import * as os from 'os'
1212

1313
import {APIClient, HerokuAPIError} from './api-client'
1414
import {vars} from './vars'
@@ -60,12 +60,17 @@ export class Login {
6060
} else if (process.env.HEROKU_LEGACY_SSO === '1') {
6161
input = 'sso'
6262
} else {
63-
await inquirer.prompt<{ key: KeyDescriptor }>({
63+
const {key} = await inquirer.prompt<{ key: KeyDescriptor }>({
6464
anyKey: true,
6565
name: 'key',
66-
pressToContinueMessage: 'heroku: Press any key to open up the browser to login or q to exit',
66+
pressToContinueMessage: `heroku: Press any key to open up the browser to login or ${color.yellow('q')} to exit`,
6767
type: 'press-to-continue',
6868
})
69+
ux.stdout('')
70+
if (key.value === 'q') {
71+
ux.error('Login cancelled by user')
72+
}
73+
6974
input = 'browser'
7075
}
7176
}
@@ -325,9 +330,8 @@ export class Login {
325330
debug(`opening browser to ${url}`)
326331
ux.stderr(`Opening browser to:\n${url}\n`)
327332
ux.stderr(color.gray(
328-
'If the browser fails to open or you\'re authenticating on a '
329-
+ 'remote machine, please manually open the URL above in your '
330-
+ 'browser.\n',
333+
`If the browser fails to open or you're authenticating on a remote
334+
machine, please manually open the URL above in your browser.\n`,
331335
))
332336
await open(url, {wait: false})
333337

0 commit comments

Comments
 (0)