deno.land / x / yargs@v17.6.0-deno / test / fixtures / cmddir / 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
32
33
34
35
36
37
/* eslint-disable no-undef */exports.command = 'dream [command] [opts]';exports.desc = 'Go to sleep and dream';exports.builder = function (yargs) { return yargs .commandDir('deep', { extensions: ['js', 'json'], }) .option('shared', { desc: 'Is the dream shared with others?', type: 'boolean', global: true, }) .option('extract', { desc: 'Attempt extraction?', type: 'boolean', global: true, });};exports.handler = function (argv) { if (argv.extract) { if (!argv.shared) throw new Error('Dream is not shared, there is no one to extract from!'); if (!chancesLevel1()) throw new Error('Extraction failed!'); if (!argv._msg) argv._msg = 'Extraction succesful'; } if (argv._msg) console.log(argv._msg); else console.log( argv.shared ? 'Training session over' : 'Well, that was a refreshing nap' );};
function chancesLevel1() { return Math.floor(Math.random() * 10) < 9;}
yargs

Version Info

Tagged at
2 years ago