Browse Source

Prompt for login if no credentials defined (#795)

* Prompt for login if no credentials defined

* Sub commands should lead to login as well

* Show a message

* Fixed syntax

* Even more syntax fixed
master
Leo Lamprecht 8 years ago
committed by GitHub
parent
commit
dd4db2427f
  1. 43
      src/get-welcome.js
  2. 20
      src/now.js
  3. 7
      src/providers/sh/commands/alias.js
  4. 7
      src/providers/sh/commands/billing.js
  5. 7
      src/providers/sh/commands/certs.js
  6. 24
      src/providers/sh/commands/deploy.js
  7. 7
      src/providers/sh/commands/dns.js
  8. 7
      src/providers/sh/commands/domains.js
  9. 7
      src/providers/sh/commands/list.js
  10. 7
      src/providers/sh/commands/logs.js
  11. 7
      src/providers/sh/commands/remove.js
  12. 7
      src/providers/sh/commands/scale.js
  13. 7
      src/providers/sh/commands/secrets.js
  14. 7
      src/providers/sh/commands/teams.js
  15. 7
      src/providers/sh/commands/upgrade.js
  16. 7
      src/providers/sh/commands/whoami.js

43
src/get-welcome.js

@ -1,43 +0,0 @@
// Packages
const { gray, bold } = require('chalk')
// Utilities
const cmd = require('./util/output/cmd')
const li = require('./util/output/list-item')
const link = require('./util/output/link')
// prettier-disable
const getWelcome = (currentProvider, providers) =>
`
Welcome to ${bold('Now')}!
Our tool makes serverless deployment universal and instant,
with just one command: ${cmd('now')}.
To setup deployments with ${link('https://now.sh')} run:
${cmd('now login')}
The following providers are also supported
${Object.keys(providers)
.map(name =>
li(
`${bold(name)}\t ${providers[name]
.title}\t\t\t\t\t${currentProvider === name
? gray('(default)')
: ' '}`
)
)
.join('\n ')}
To set up AWS, for example, run ${cmd('now aws login')}.
Many can be configured simultaneously!
Hope you enjoy Now! Check out these other resources:
${li(`Run ${cmd('now help')} for more info and examples`)}
${li(link('https://github.com/zeit/now-cli'))}
`
module.exports = getWelcome

20
src/now.js

@ -15,7 +15,6 @@ const chalk = require('chalk')
const error = require('./util/output/error')
const param = require('./util/output/param')
const info = require('./util/output/info')
const getWelcome = require('./get-welcome')
const getNowDir = require('./get-now-dir')
const getDefaultCfg = require('./get-default-cfg')
const getDefaultAuthCfg = require('./get-default-auth-cfg')
@ -358,17 +357,24 @@ const main = async (argv_) => {
subcommand = 'deploy'
}
if (subcommand === 'deploy' && !authConfig.credentials.length) {
debug('subcommand is deploy, but user has no credentials')
console.log(getWelcome(provider, providers))
return 0
}
if (subcommand === 'help') {
subcommand = argv._[3] || 'deploy'
ctx.argv.push('-h')
}
// If no credentials are set at all, prompt for
// login to the .sh provider
if (!authConfig.credentials.length && !ctx.argv.includes('-h')) {
console.log(info(`No existing credentials found. Please log in:`))
subcommand = 'login'
ctx.argv[2] = 'login'
// Ensure that sub commands lead to login as well, if
// no credentials are defined
ctx.argv = ctx.argv.splice(0, 3)
}
try {
await provider[subcommand](ctx)
} catch (err) {

7
src/providers/sh/commands/alias.js

@ -20,8 +20,6 @@ const exit = require('../../../util/exit')
const info = require('../../../util/output/info')
const logo = require('../../../util/output/logo')
const promptBool = require('../../../util/input/prompt-bool')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const grayWidth = 10
const underlineWidth = 11
@ -128,11 +126,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
subcommand = argv._[0]

7
src/providers/sh/commands/billing.js

@ -15,8 +15,6 @@ const promptBool = require('../../../util/input/prompt-bool')
const info = require('../../../util/output/info')
const logo = require('../../../util/output/logo')
const addBilling = require('./billing/add')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -81,11 +79,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
debug = argv.debug

7
src/providers/sh/commands/certs.js

@ -18,8 +18,6 @@ const { handleError, error } = require('../util/error')
const NowCerts = require('../util/certs')
const exit = require('../../../util/exit')
const logo = require('../../../util/output/logo')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -88,11 +86,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
apiUrl = argv.url || 'https://api.zeit.co'

24
src/providers/sh/commands/deploy.js

@ -33,7 +33,7 @@ const promptOptions = require('../util/prompt-options')
const note = require('../../../util/output/note')
const mriOpts = {
string: ['config', 'token', 'name', 'alias', 'session-affinity'],
string: ['token', 'name', 'alias', 'session-affinity'],
boolean: [
'help',
'version',
@ -51,7 +51,6 @@ const mriOpts = {
env: 'e',
dotenv: 'E',
help: 'h',
config: 'c',
debug: 'd',
version: 'v',
force: 'f',
@ -263,31 +262,18 @@ async function main(ctx) {
apiUrl = argv.url || 'https://api.zeit.co'
isTTY = process.stdout.isTTY
quiet = !isTTY
if (argv.h || argv.help) {
help()
return 0
}
let { token } =
ctx.authConfig.credentials.find(c => c.provider === 'sh') || {}
if (!token) {
// node file sh [...]
const sh = argv[2] === 'sh'
const _cmd = `now ${sh ? 'sh ' : ''}login`
console.log(error(`You're not logged in! Please run ${cmd(_cmd)}`))
return 1
}
const config = ctx.config.sh
const { authConfig: { credentials }, config: { sh } } = ctx
const { token } = argv.token || credentials.find(item => item.provider === 'sh')
const config = sh
alwaysForwardNpm = config.forwardNpm
if (argv.config) {
// TODO enable this
// cfg.setConfigFile(argv.config)
}
try {
return sync({ token, config })
} catch (err) {

7
src/providers/sh/commands/dns.js

@ -13,8 +13,6 @@ const strlen = require('../util/strlen')
const { handleError, error } = require('../util/error')
const exit = require('../../../util/exit')
const logo = require('../../../util/output/logo')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -77,11 +75,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
debug = argv.debug

7
src/providers/sh/commands/domains.js

@ -16,8 +16,6 @@ const strlen = require('../util/strlen')
const toHost = require('../util/to-host')
const { handleError, error } = require('../util/error')
const buy = require('./domains/buy')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -137,11 +135,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
debug = argv.debug

7
src/providers/sh/commands/list.js

@ -13,8 +13,6 @@ const Now = require('../util')
const { handleError, error } = require('../util/error')
const logo = require('../../../util/output/logo')
const sort = require('../util/sort-deployments')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -62,11 +60,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
app = argv._[0]

7
src/providers/sh/commands/logs.js

@ -15,8 +15,6 @@ const { handleError, error } = require('../util/error')
const logo = require('../../../util/output/logo')
const { compare, deserialize } = require('../util/logs')
const { maybeURL, normalizeURL, parseInstanceURL } = require('../../../util/url')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -82,11 +80,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
deploymentIdOrURL = argv._[0]

7
src/providers/sh/commands/remove.js

@ -11,8 +11,6 @@ const Now = require('../util')
const { handleError, error } = require('../util/error')
const logo = require('../../../util/output/logo')
const { normalizeURL } = require('../../../util/url')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -75,11 +73,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
debug = argv.debug

7
src/providers/sh/commands/scale.js

@ -17,8 +17,6 @@ const logo = require('../../../util/output/logo')
const info = require('../util/scale-info')
const sort = require('../util/sort-deployments')
const success = require('../../../util/output/success')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -84,11 +82,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
id = argv._[0]

7
src/providers/sh/commands/secrets.js

@ -12,8 +12,6 @@ const { handleError, error } = require('../util/error')
const NowSecrets = require('../util/secrets')
const exit = require('../../../util/exit')
const logo = require('../../../util/output/logo')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -85,11 +83,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
debug = argv.debug

7
src/providers/sh/commands/teams.js

@ -14,8 +14,6 @@ const list = require('./teams/list')
const add = require('./teams/add')
const change = require('./teams/switch')
const invite = require('./teams/invite')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -84,11 +82,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
debug = argv.debug
apiUrl = argv.url || 'https://api.zeit.co'

7
src/providers/sh/commands/upgrade.js

@ -15,8 +15,6 @@ const success = require('../../../util/output/success')
const cmd = require('../../../util/output/cmd')
const logo = require('../../../util/output/logo')
const { handleError } = require('../util/error')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const { bold } = chalk
@ -76,11 +74,6 @@ const main = async ctx => {
}
})
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
argv._ = argv._.slice(1)
debug = argv.debug

7
src/providers/sh/commands/whoami.js

@ -7,8 +7,6 @@ const chalk = require('chalk')
// Utilities
const logo = require('../../../util/output/logo')
const { handleError } = require('../util/error')
const getWelcome = require('../../../get-welcome')
const providers = require('../../')
const help = () => {
console.log(`
@ -49,11 +47,6 @@ const main = async ctx => {
argv._ = argv._.slice(1)
if (!ctx.authConfig.credentials.length) {
console.log(getWelcome('sh', providers))
return 0
}
if (argv.help || argv._[0] === 'help') {
help()
process.exit(0)

Loading…
Cancel
Save