mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(cloudcmd) env: add ability to pass 0 and 1
This commit is contained in:
parent
45d44dc74d
commit
33827fea5e
2 changed files with 34 additions and 2 deletions
|
|
@ -8,12 +8,18 @@ const up = (a) => a.toUpperCase();
|
|||
module.exports = parse;
|
||||
module.exports.bool = (name) => {
|
||||
const value = parse(name);
|
||||
|
||||
|
||||
if (value === 'true')
|
||||
return true;
|
||||
|
||||
|
||||
if (value === '1')
|
||||
return true;
|
||||
|
||||
if (value === 'false')
|
||||
return false;
|
||||
|
||||
if (value === '0')
|
||||
return false;
|
||||
};
|
||||
|
||||
function parse(name) {
|
||||
|
|
|
|||
|
|
@ -29,3 +29,29 @@ test('cloudcmd: server: env: bool: snake_case', (t) => {
|
|||
t.ok(result);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: server: env: bool: number', (t) => {
|
||||
const {cloudcmd_terminal} = process.env;
|
||||
|
||||
process.env.CLOUDCMD_TERMINAL = '1';
|
||||
|
||||
const result = env.bool('terminal');
|
||||
|
||||
process.env.CLOUDCMD_TERMINAL = cloudcmd_terminal;
|
||||
|
||||
t.ok(result);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: server: env: bool: number: 0', (t) => {
|
||||
const {cloudcmd_terminal} = process.env;
|
||||
|
||||
process.env.cloudcmd_terminal = '0';
|
||||
|
||||
const result = env.bool('terminal');
|
||||
|
||||
process.env.cloudcmd_terminal = cloudcmd_terminal;
|
||||
|
||||
t.notOk(result);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue