Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add now whoami subcommand #587

Merged
merged 1 commit into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions bin/now-whoami.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env node

// Packages
const minimist = require('minimist')
const chalk = require('chalk')

// Ours
const cfg = require('../lib/cfg')
const exit = require('../lib/utils/exit')
const cmd = require('../lib/utils/output/cmd')
const logo = require('../lib/utils/output/logo')

const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'debug', 'all'],
alias: {
help: 'h',
config: 'c',
debug: 'd',
token: 't'
}
})

const help = () => {
console.log(`
${chalk.bold(`${logo} now whoami`)}

${chalk.dim('Options:')}

-h, --help Output usage information
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} Config file
-d, --debug Debug mode [off]
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} Login token

${chalk.dim('Examples:')}

${chalk.gray('–')} Show the current team context

${chalk.cyan('$ now whoami')}
`)
}

if (argv.help) {
help()
process.exit(0)
}

if (argv.config) {
cfg.setConfigFile(argv.config)
}

async function whoami() {
const config = await cfg.read({ token: argv.token })
if (!config || !config.token) {
console.log(
`> Not currently logged in! Please run ${cmd('now --login')}.\n`
)
return exit(1)
}

if (process.stdout.isTTY) {
process.stdout.write('> ')
}

const { currentTeam, user } = config
const name = (currentTeam && currentTeam.slug) || user.username || user.email
console.log(name)
}

whoami()
3 changes: 2 additions & 1 deletion bin/now.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const commands = new Set([
'log',
'logs',
'scale',
'logout'
'logout',
'whoami'
])

const aliases = new Map([
Expand Down