Browse Source
* add basic config command * Add a success message * Grammar * Remove extra spacesmaster
committed by
Matheus Fernandes
5 changed files with 109 additions and 14 deletions
@ -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 |
@ -0,0 +1,11 @@ |
|||
module.exports = { |
|||
subcommands: new Set(['help', 'set']), |
|||
|
|||
get help() { |
|||
return require('./help') |
|||
}, |
|||
|
|||
get set() { |
|||
return require('./set') |
|||
} |
|||
} |
@ -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()))}`)) |
|||
} |
Loading…
Reference in new issue