Browse Source

Add basic config command (#33)

* add basic config command

* Add a success message

* Grammar

* Remove extra spaces
master
Naoyuki Kanezawa 8 years ago
committed by Matheus Fernandes
parent
commit
817184951d
  1. 17
      Readme.md
  2. 25
      src/config/help.js
  3. 11
      src/config/index.js
  4. 38
      src/config/set.js
  5. 32
      src/now.js

17
Readme.md

@ -56,9 +56,13 @@ produce the [pkg](https://github.com/zeit/pkg) binaries.
## Setup
Configuration of one or more providers via `login` command is necessary. If no logins are active and `now`
Configuration of one or more providers via `login` command is necessary.
Global configuration is stored as `~/.now/config.json`. Your default provider will be the first one you log in to.
Global configuration is stored as `~/.now/config.json`. Your default provider will be the first one you log in to. If you are logged into multiple providers and want to set default provider, run:
```
now config set defaultProvider gcp
```
### Now.sh
@ -85,7 +89,7 @@ to synchronize your credentials.
Serverless deployments are provisioned by using:
- Lambda functions λ
- A proxy is automatically used to bridge the API between
- A proxy is automatically used to bridge the API between
HTTP and lambda functions and retain a consistent interface
- Certificate Manager
- API Gateway
@ -136,7 +140,7 @@ The v1 release of `now.json` includes the following specification:
- `env` (optional). One of
- `Object` a dictionary mapping the name of the environmental variable
to expose to the deployment and its value.
If the value begins with `@`, it's considered a
If the value begins with `@`, it's considered a
- `Array` a list of suggested environmental variables that the project
_might_ require to be deployed and function correctly
- `regions` - `Array` of `String`
@ -234,13 +238,13 @@ or framework are present, attempt to provide sane defaults.
Examples of this is the presence of `Dockerfile` or `package.json`. When
publishing a project it's recommended that the [`type`](#type) is strictly
configured in [`now.json`](#now-json) to avoid
configured in [`now.json`](#now-json) to avoid
## Contributions and Roadmap
#### Community
All feedback and suggestions are welcome!
All feedback and suggestions are welcome!
- 💬 Chat: Join us on [zeit.chat](https://zeit.chat) `#now-client`.
- 📣 Stay up to date on new features and announcments on [@zeithq](https://twitter.com/zeithq).
@ -284,4 +288,3 @@ npm run build
Now is licensed under the Apache License, Version 2.0.
See LICENSE for the full license text.

25
src/config/help.js

@ -0,0 +1,25 @@
const { bold } = require('chalk')
const cmd = require('../util/output/cmd')
const li = require('../util/output/list-item')
const link = require('../util/output/link')
// prettier-disable
const help = () =>
console.log(
`
${bold('now config [subcommand]')}: manage global configuration.
Subcommands:
${li('set <name> <value>')}
${li('help')}
For example, to set default provider to AWS Lambda, run:
${cmd('now config set defaultProvider aws')}
For more information: ${link('https://github.com/zeit/now')}.
`
)
module.exports = help

11
src/config/index.js

@ -0,0 +1,11 @@
module.exports = {
subcommands: new Set(['help', 'set']),
get help() {
return require('./help')
},
get set() {
return require('./set')
}
}

38
src/config/set.js

@ -0,0 +1,38 @@
const debug = require('debug')('now:config:set')
const error = require('../util/output/error')
const success = require('../util/output/success')
const param = require('../util/output/param')
const hp = require('../util/humanize-path')
const { writeToConfigFile, getConfigFilePath } = require('../util/config-files')
const CONFIGS = new Map([
[
'defaultProvider',
value => {
const providers = require('../providers')
return providers.hasOwnProperty(value)
}
]
])
module.exports = function set(ctx) {
const [name, value] = ctx.argv.slice(4)
debug('setting config %s to %s', name, value)
if (!CONFIGS.has(name)) {
console.error(error(`Unexpected config name: ${name}`))
return 1
}
const validate = CONFIGS.get(name)
if (!validate(value)) {
console.error(error(`Unexpected config value for ${name}: ${value}`))
return 1
}
ctx.config[name] = value
writeToConfigFile(ctx.config)
console.log(success(`Config saved in ${param(hp(getConfigFilePath()))}`))
}

32
src/now.js

@ -245,6 +245,31 @@ const main = async (argv_): Promise<number> => {
)
}
// the context object to supply to the providers or the commands
const ctx = {
config,
authConfig,
argv: argv_
}
if (targetOrSubcommand === 'config') {
const _config = require('./config')
const subcommand = _config.subcommands.has(argv._[3]) ? argv._[3] : 'help'
debug(`executing config %s`, subcommand)
try {
return _config[subcommand](ctx)
} catch (err) {
console.error(
error(
`An unexpected error occurred in config ${subcommand}: ${err.stack}`
)
)
return 1
}
}
let suppliedProvider = null
// if the target is something like `aws`
@ -304,13 +329,6 @@ const main = async (argv_): Promise<number> => {
const provider: Object = providers[suppliedProvider || defaultProvider]
// the context object to supply to the providers
const ctx = {
config,
authConfig,
argv: argv_
}
let subcommand
// we check if we are deploying something

Loading…
Cancel
Save