UNPKG

@dotenvx/dotenvx-radar

Version:
86 lines (70 loc) 2.27 kB
#!/usr/bin/env node /* c8 ignore start */ const { Command } = require('commander') const program = new Command() const { setLogLevel } = require('@dotenvx/dotenvx') const packageJson = require('./../lib/helpers/packageJson') const Session = require('./../db/session') const sesh = new Session() // global log levels program .usage('login') .option('-l, --log-level <level>', 'set log level', 'info') .option('-q, --quiet', 'sets log level to error') .option('-v, --verbose', 'sets log level to verbose') .option('-d, --debug', 'sets log level to debug') .hook('preAction', (thisCommand, actionCommand) => { const options = thisCommand.opts() setLogLevel(options) }) // cli program .name('dotenvx-radar') .description(packageJson.description) .version(packageJson.version) .allowUnknownOption() // dotenvx-radar observe base64String const observeAction = require('./actions/observe') program.command('observe') .usage('<BASE64> [options]') .description('[INTERNAL] observe') .allowUnknownOption() .argument('BASE64', 'BASE64') .option('--hostname <url>', 'set hostname', sesh.hostname()) .option('--token <token>', 'set token') .action(function (...args) { observeAction.apply(this, args) }) // dotenvx-radar login const loginAction = require('./actions/login') program .command('login') .description('log in') .option('--hostname <url>', 'set hostname', sesh.hostname()) .action(loginAction) // dotenvx-radar logout const logoutAction = require('./actions/logout') program .command('logout') .description('log out') .option('--hostname <url>', 'set hostname', sesh.hostname()) .action(logoutAction) // dotenvx-radar status const statusAction = require('./actions/status') program .command('status') .description('status') .action(statusAction) // dotenvx-radar settings program.addCommand(require('./commands/settings')) // monkey-patch help output program.helpInformation = function () { const originalHelp = Command.prototype.helpInformation.call(this) const lines = originalHelp.split('\n') const filteredLines = lines.filter(line => !line.includes('INTERNAL') // hide observe command ) return filteredLines.join('\n') } /* c8 ignore stop */ program.parse(process.argv)