-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not logged in: ``` $ now whoami > Not currently logged in! Please run `now --login`. ``` Logged in, stdout is a TTY: ``` $ now whoami > tootallnate $ now switch zeit $ now whoami > zeit ``` Stdout is NOT a TTY: ``` $ echo "Logged in to Now as $(now whoami)" Logged in to Now as tootallnate ``` Closes #585.
- Loading branch information
1 parent
20d93f3
commit 44f5b9f
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters