scraper/src/console/input.js

59 lines
924 B
JavaScript
Raw Normal View History

2020-04-11 22:18:23 +02:00
"use strict";
var Minimist = require('minimist');
class Input {
2023-03-31 17:53:24 +02:00
/**
* Constructor.
*
* @param object process
*/
constructor(process) {
this.args = Minimist(process.argv.slice(2))
this.node = process.argv[0]
this.script = process.argv[1]
}
/**
* Return the value of the given name argument.
*
* @param string name
* @param mixed default
*
* @return mixed
*/
get(name, defaultValue) {
if (this.has(name)) {
return this.args[name]
2020-04-11 22:18:23 +02:00
}
2023-03-31 17:53:24 +02:00
if (defaultValue !== undefined) {
return defaultValue
2020-04-11 22:18:23 +02:00
}
2023-03-31 17:53:24 +02:00
return null;
}
/**
* Check the given argument name exists.
*
* @param string name
*
* @return boolean
*/
has(name) {
return this.args.hasOwnProperty(name)
}
/**
* Return if args is empty.
*
* @return boolean
*/
empty() {
return Object.keys(this.args).length === 1
}
2020-04-11 22:18:23 +02:00
}
module.exports = Input