UNPKG

ethstats-cli

Version:
135 lines (117 loc) 5.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var CLI = /*#__PURE__*/ function () { function CLI(diContainer) { _classCallCheck(this, CLI); this.pkg = diContainer.pkg; this.chalk = diContainer.chalk; this.meow = diContainer.meow; this.boxen = diContainer.boxen; this.log = diContainer.logger; var boxOptions = { padding: 1, margin: 1, align: 'center', borderColor: 'yellow', borderStyle: 'round' }; var description = this.boxen(this.chalk.green.bold(this.pkg.description) + ' \n' + this.chalk.cyan('v' + this.pkg.version), boxOptions); var cli = this.meow("\n Usage\n $ ethstats-cli [options]\n \n Options\n --help, -h Show help\n --version, -V Show version\n --debug, -d Output values sent to server\n --verbose, -v Output more detailed information\n \n --server-url Server URL (Must include protocol and port if any)\n --net, -n Specify Ethereum network your node is running on (Default: mainnet)\n Available networks: mainnet|rinkeby|goerli\n If --server-url is specified, this option is ignored\n\n --client-url Client URL (Must include protocol and port if any; Default: http://localhost:8545)\n Based on the protocol specified in the url (http | ws) the app sets the corresponding Web3 provider \n If --client-ipc-path is specified, this option is ignored\n --client-ipc-path Client IPC path\n \n --configurator-url Configurator URL (Must include protocol and port if any). Custom configuration service to provide application specific configs. \n \n --register, -r Register node in non-interactive mode\n --account-email Account identification, also used in case of node/secret-key recovery\n It is possible to have multiple nodes under the same account-email\n --node-name Name of the node. If node is already registered, a unique 5 char hash will be appended\n \n", { description: description, flags: { help: { type: 'boolean', alias: 'h' }, version: { type: 'boolean', alias: 'V' }, debug: { type: 'boolean', alias: 'd' }, verbose: { type: 'boolean', alias: 'v' }, serverUrl: { type: 'string' }, net: { type: 'string', alias: 'n' }, clientUrl: { type: 'string' }, clientIpcPath: { type: 'string' }, configuratorUrl: { type: 'string' }, register: { type: 'boolean', alias: 'r' }, accountEmail: { type: 'string' }, nodeName: { type: 'string' } } }); diContainer.config.logger.showInfos = cli.flags.verbose; diContainer.config.logger.showDebugs = cli.flags.debug; if (diContainer.config.logger.showDebugs && !diContainer.config.logger.showInfos) { diContainer.config.logger.showInfos = true; } diContainer.logger.showInfos = diContainer.config.logger.showInfos; diContainer.logger.showDebugs = diContainer.config.logger.showDebugs; diContainer.logger.showDateTime = diContainer.config.logger.showInfos; return this.validateFlags(cli); } _createClass(CLI, [{ key: "validateFlags", value: function validateFlags(cli) { if (cli.flags.configuratorUrl === true || cli.flags.configuratorUrl === '') { this.log.error('Configurator URL is empty', false, true); } if (cli.flags.clientUrl === true || cli.flags.clientUrl === '') { this.log.error('Client URL is empty', false, true); } if (cli.flags.clientIpcPath === true || cli.flags.clientIpcPath === '') { this.log.error('Client IPC Path is empty', false, true); } if (cli.flags.serverUrl === true || cli.flags.serverUrl === '') { this.log.error('Server URL is empty', false, true); } if (cli.flags.net === true || cli.flags.net === '') { this.log.error('Network is empty', false, true); } if (cli.flags.register) { if (!cli.flags.accountEmail || cli.flags.accountEmail === true || cli.flags.accountEmail === '') { this.log.error('Account email is missing or empty', false, true); } if (!cli.flags.nodeName || cli.flags.nodeName === true || cli.flags.nodeName === '') { this.log.error('Node name is missing or empty', false, true); } } else if (cli.flags.accountEmail !== undefined || cli.flags.nodeName !== undefined) { this.log.error('Register flag is missing', false, true); } return cli; } }]); return CLI; }(); exports.default = CLI;