@whook/whook
Version:
Build strong and efficient REST web services.
34 lines • 1.12 kB
JavaScript
import { autoService } from 'knifecycle';
import { 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 ENV[name] &&
'undefined' === typeof defaultValue) {
throw new YError('E_NO_ENV_VALUE', name);
}
log('info', `${ENV[name] || defaultValue}`);
};
}
//# sourceMappingURL=env.js.map