-
Notifications
You must be signed in to change notification settings - Fork 996
/
within-a-dream.js
31 lines (30 loc) · 983 Bytes
/
within-a-dream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* eslint-disable no-undef */
module.exports = {
command: 'within-a-dream [command] [opts]',
desc: 'Dream within a dream',
builder: function (yargs) {
return yargs.commandDir('deeper').option('with-kick', {
desc: 'Plan a kick for controlled wake up?',
type: 'boolean',
global: true,
});
},
handler: function (argv) {
let factor = 7;
if (argv.context) argv.context.counter++; // keep track of how many times we've invoked this handler.
if (argv.extract) {
if (!argv.withKick) factor -= 2;
if (!chancesLevel2(factor))
throw new Error(
'Something went wrong at level 2! Check your options for increased chance of success.'
);
if (!argv._msg)
argv._msg = 'You got lucky this time. Extraction successful.';
return;
}
if (!argv._msg) argv._msg = "Let's not make a habit of this.";
},
};
function chancesLevel2(factor) {
return Math.floor(Math.random() * 10) < factor;
}