UNPKG

@whook/whook

Version:

Build strong and efficient REST web services.

33 lines 1.12 kB
import { autoService } from 'knifecycle'; import { hasDefinedKey, noop } from '../libs/utils.js'; import { YError } from 'yerror'; export const definition = { name: 'env', description: 'A command printing env values', example: `whook env --name NODE_ENV --default "default value"`, config: { promptArgs: true }, arguments: [ { name: 'name', required: true, description: 'Environment variable name to pick-up', schema: { type: 'string' }, }, { name: 'default', description: 'Provide a default value', schema: { type: 'string' }, }, ], }; export default autoService(initEnvCommand); async function initEnvCommand({ ENV, log = noop, }) { return async (args) => { const { namedArguments: { name, default: defaultValue }, } = args; if ('undefined' === typeof defaultValue && !hasDefinedKey(ENV, name)) { throw new YError('E_NO_ENV_VALUE', [name]); } log('info', `${ENV[name] || defaultValue}`); }; } //# sourceMappingURL=env.js.map