-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathservices.js
37 lines (32 loc) · 1.2 KB
/
services.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
/**
* Parses service arguments
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// scrappy way to parse command line arguments until we drop support for Node.js 10.x
let argList = process.argv.slice(2); // this removes `node` and the filename from arguments list
let args = {};
if (argList.indexOf("--services") !== -1) { // if it exists
let after = argList.slice(argList.indexOf("--services") + 1);
let until = after.findIndex(value => value.indexOf('--') === 0); // find next
args.services = after.slice(0, (until === -1 ? undefined : until));
} else {
args.services = [];
}
// Note: With minimum support for Node 12.x, we can use yargs instead:
/*
let yargs = require('yargs');
let args = yargs
.option('services', {
alias: 's',
describe: 'specify optional services this server supports, e.g. world',
type: 'array',
demand: false,
default: []
}).argv;
console.log(args.services);
*/
module.exports.providedServices = args.services;
module.exports.hasWorldService = args.services.includes('world');