function main() { var parser, option; var conf = { 'showUserDetails': false, 'json': false }; parser = new mod_getopt.BasicParser('ju', process.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'j': conf.json = true; break; case 'u': conf.showUserDetails = true; break; } } readStreamJson(process.stdin, function (err, data) { if (err) throw (err); if (conf.json) console.log(JSON.stringify(data)); else report(conf, denormalize(data)); }); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('vf:(file)', process.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'f': opts.file = option.optarg; break; case 'v': // Allows us to set -vvv -> this little hackery // just ensures that we're never < TRACE LOG_LEVEL_OVERRIDE = true; LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10))); break; default: LOG.fatal('Unsupported option: ', option.option); process.exit(1); break; } } return (opts); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('k:', process.argv); while ((option = parser.getopt()) !== undefined) { if (option.error) { usage(); } switch (option.option) { case 'k': opts.mantaKey = option.optarg; break; default: usage('Unknown option: ' + option.option); break; } } if (!opts.mantaKey) { usage('-k [manta_key] is a required argument'); } return (opts); }
function parseOptions() { var option; var opts = { 'configFiles': [] }; var parser = new getopt.BasicParser('c:p:', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'c': opts.configFiles.push(option.optarg); break; case 'p': opts.port = parseInt(option.optarg, 10); break; default: usage('Unknown option: ' + option.option); break; } } if (opts.configFiles.length === 0) { usage('No config files specified.'); } return (opts); }
function parseOptions() { var option; var opts = { log: LOG }; var parser = new getopt.BasicParser('e:f:s:', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'e': opts.errorFile = option.optarg; break; case 'f': opts.file = option.optarg; break; case 's': opts.storageListFile = option.optarg; break; default: usage('Unknown option: ' + option.option); break; } } if (!opts.errorFile) { usage('-e [file] is a required argument'); } if (!opts.file) { usage('-f [file] is a required argument'); } if (!opts.storageListFile) { usage('-s [storage_list_file] is a required argument'); } return (opts); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('d:e:m:', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'd': opts.dumpDate = parseDate(option.optarg); break; case 'e': opts.earliestDumpDate = parseDate(option.optarg); break; case 'm': opts.morayHostname = option.optarg; break; default: usage('Unknown option: ' + option.option); break; } } if (!opts.dumpDate) { usage('-d [dump_date] is a required argument'); } if (!opts.earliestDumpDate) { usage('-e [earliest_dump_date] is a required argument'); } if (!opts.morayHostname) { usage('-m [moray_hostname] is a required argument'); } return (opts); }
function main() { var parser, option, video; var raw = false; var log = new mod_bunyan({ 'name': 'kart' }); parser = new mod_getopt.BasicParser('r', process.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'r': raw = true; break; default: /* error message already emitted */ usage(); break; } } video = { 'log': log }; mod_carrier.carry(process.stdin, mod_kartvid.parseKartvid(video)); process.stdin.resume(); process.stdin.on('end', function () { if (raw) console.log('%s', JSON.stringify(video.races, null, 4)); else video.races.forEach(summarize); }); }
function aqParseOptions() { var parser, cc; parser = new mod_getopt.BasicParser('f:r:h:o:', process.argv); while ((cc = parser.getopt()) !== undefined) { if (cc['error']) aqUsage(); switch (cc['option']) { case 'h': aq_broker['host'] = cc['optarg']; break; case 'r': aq_routekey = cc['optarg']; break; case 'f': aq_filters.push( mod_vm.createScript(cc['optarg'])); break; case 'o': aq_outputter = aq_outputters[cc['optarg']]; if (aq_outputter === undefined) { console.error('unknown output format: %s', cc['optarg']); aqUsage(); } break; } } }
function parseOptions() { var option; var opts = {}; opts.fields = []; opts.reverse = false; opts.exclude = false; var parser = new getopt.BasicParser('f:rx', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'f': opts.fields.push(option.optarg); break; case 'r': opts.reverse = true; break; case 'x': opts.exclude = true; break; default: usage('Unknown option: ' + option.option); break; } } if (opts.fields.length === 0 && !opts.reverse) { usage('-f [field] is a required argument'); } return (opts); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('hva:b:s:p:f:', process.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'a': opts.expiry = parseInt(option.optarg, 10); break; case 'b': opts.balancerSocket = option.optarg; break; case 'f': opts.configFile = option.optarg; break; case 'h': usage(); break; case 'p': opts.port = parseInt(option.optarg, 10); break; case 's': opts.size = parseInt(option.optarg, 10); break; case 'v': // Allows us to set -vvv -> this little hackery // just ensures that we're never < TRACE LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10))); if (LOG.level() <= bunyan.DEBUG) LOG = LOG.child({src: true}); break; default: process.exit(1); break; } } var fopts = {}; opts.configFile = opts.configFile || './etc/config.json'; try { var fcfg = fs.readFileSync(opts.configFile); fopts = JSON.parse(fcfg); } catch (e) { LOG.fatal(e); process.exit(1); } var options = xtend({}, clone(DEFAULTS), fopts, opts); LOG.info(options, 'starting with options'); return (options); }
function parseOptions() { var option; //First take what's in the config file, override what's on the // command line, and use the defaults if all else fails. var opts = MOLA_AUDIT_CONFIG_OBJ; opts.shards = opts.shards || []; var parser = new getopt.BasicParser('a:d:m:np:r:s:t', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'a': opts.assetFile = option.optarg; break; case 'd': opts.auditReduceDisk = parseInt(option.optarg, 10); break; case 'm': opts.shards.push(option.optarg); break; case 'n': opts.noJobStart = true; break; case 'p': opts.auditMapDisk = parseInt(option.optarg, 10); break; case 'r': opts.auditReduceMemory = parseInt(option.optarg, 10); break; case 's': opts.mantaStorageId = option.optarg; break; case 't': opts.jobName = 'manta_audit_test'; opts.jobRoot = MP + '/manta_audit_test'; break; default: usage('Unknown option: ' + option.option); break; } } //Set up some defaults... opts.jobName = opts.jobName || 'manta_audit'; opts.jobRoot = opts.jobRoot || MP + '/manta_audit'; opts.assetDir = opts.jobRoot + '/assets'; opts.assetObject = opts.assetDir + '/mola.tar.gz'; opts.assetFile = opts.assetFile || '/opt/smartdc/common/bundle/mola.tar.gz'; opts.auditMapDisk = opts.auditMapDisk || 32; opts.auditReduceMemory = opts.auditReduceMemory || 4096; opts.auditReduceDisk = opts.auditReduceDisk || 16; opts.marlinPathToAsset = opts.assetObject.substring(1); opts.marlinAssetObject = opts.assetObject; return (opts); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('cvf:r:p:k:s:', process.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'c': opts.cover = true; break; case 'f': opts.file = option.optarg; break; case 'r': opts.ringLocation = option.optarg; break; case 'p': opts.port = parsePort(option.optarg); break; case 'k': opts.monitorPort = parsePort(option.optarg); break; case 's': opts.statusPort = parsePort(option.optarg); break; case 'v': // Allows us to set -vvv -> this little hackery just ensures // that we're never < TRACE LOG_LEVEL_OVERRIDE = true; LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10))); if (LOG.level() <= bunyan.DEBUG) LOG = LOG.child({src: true}); break; default: process.exit(1); break; } } if (!opts.file) { LOG.fatal({ opts: opts }, 'No config file specified.'); process.exit(1); } return (opts); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('g:', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'g': opts.gracePeriodSeconds = parseInt(option.optarg, 10); break; default: usage('Unknown option: ' + option.option); break; } } return (opts); }
function parse_arguments(argv) { var opt_c = 0; var opt_h = 0; var option; var obj = {}; var parser = new mod_getopt.BasicParser('cho:', argv); var defs; while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'c': opt_c++; obj.action = 'c'; break; case 'h': opt_h++; obj.action = 'h'; break; case 'o': obj.output = option.optarg; break; default: usage(); break; } } obj.input = argv[parser.optind()]; if (opt_c + opt_h != 1) usage(); if (!obj.input) usage(); defs = fs.readFileSync(obj.input); obj.defs = JSON.parse(defs); BUILTIN_ERRORS.forEach(function _prepend_err(e) { obj.defs.errors.unshift(e); }); return (obj); }
///--- Helpers /** * Standard POSIX getopt-style options parser. * * Some options, like directory/user/port are pretty cut and dry, but note * the 'verbose' or '-v' option afflicts the log level, repeatedly. So you * can run something like: * * node main.js -p 80 -vv 2>&1 | bunyan * * And the log level will be set to TRACE. */ function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('hvd:p:u:z:', process.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'd': opts.directory = path.normalize(option.optarg); break; case 'h': usage(); break; case 'p': opts.port = parseInt(option.optarg, 10); break; case 'u': opts.user = option.optarg; break; case 'v': // Allows us to set -vvv -> this little hackery // just ensures that we're never < TRACE LOG.level(Math.max(bunyan.TRACE, LOG.level() - 10)); if (LOG.level() <= bunyan.DEBUG) { LOG = LOG.child({ src: true }); } break; case 'z': opts.password = option.optarg; break; default: usage('invalid option: ' + option.option); break; } } return opts; }
function parseArgs(options) {// \/\\*(?:(?!\\*\/)|.|\\n)*?\\*\/ var optionString = '', required = [], modal = false; Object.keys(options).forEach(function(option){ var def = options[option]; optionString += option; if (def.type === 'String') optionString += ':'; if (def.long) optionString += '(' + def.long + ')'; if (def.required) required.push(option); }); var parser = new getopt.BasicParser(optionString, process.argv); var args = {}, option; while ((option = parser.getopt())) { var arg = args[option.option] || { count : 0}; arg.count++; arg.value = option.optarg || true; args[option.option] = arg; if (options[option.option].modal) { modal = true; } } if (!modal) { required.forEach(function(option) { if (!args[option] || !args[option].value) { console.log("Must specify a value for option %s (%s : %s)", option, options[option].long, options[option].desc); info.help(); process.exit(1); } }); } // what's left in argv args.files = process.argv.slice(parser.optind()); return args; }
function parseOptions() { var parser = new mod_getopt.BasicParser(':vf:r:', process.argv); var option; var opts = {}; while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'f': opts.file = option.optarg; break; case 'v': LOG = mod_cmd.increaseVerbosity(LOG); break; case 'r': FLAVOR = option.optarg; break; case ':': throw new VError('Expected argument for -%s', option.optopt); default: throw new VError('Invalid option: -%s', option.optopt); } } if (parser.optind() !== process.argv.length) { throw new VError( 'Positional arguments found when none were expected: %s', process.argv.slice(parser.optind()).join(' ')); } if (!opts.file) { LOG.fatal({ opts: opts }, 'No config file specified.'); throw new Error('No config file specified'); } return (opts); }
function parseOptions() { var option; var jsonOpts = fs.readFileSync(MOLA_CONFIG); var opts = JSON.parse(jsonOpts); var parser = new getopt.BasicParser('L', process.argv); while ((option = parser.getopt()) !== undefined) { if (option.error) { usage(); } switch (option.option) { case 'L': opts.noLink = true; break; default: usage('Unknown option: ' + option.option); break; } } return (opts); }
function parseOptions() { var option; var opts = {}; var parser = new getopt.BasicParser('d:h:s:', process.argv); while ((option = parser.getopt()) !== undefined) { if (option.error) { usage(); } switch (option.option) { case 'd': opts.tmpDirectory = option.optarg; break; case 'h': opts.mantaStorageId = option.optarg; break; case 's': opts.sharksFile = option.optarg; break; default: usage('Unknown option: ' + option.option); break; } } if (!opts.tmpDirectory) { usage('-d [tmp directory] is a required argument'); } if (!opts.sharksFile) { usage('-s [sharks file] is a required argument'); } return (opts); }
exports.run = function(args, puts, eputs) { var offset = 0; var files = []; var includePaths = [process.cwd()]; var output; var formatter = formatters[formatters.DEFAULT]; var resolverClasses = [FileResolver]; while (offset < args.length) { var parser = new getopt.BasicParser('h(help)o:(output)I:(include)f:(format)r:(resolver)', ['', ''].concat(args.slice(offset))); var option; while ((option = parser.getopt()) !== undefined) { if (option.error) { usage(eputs); return 1; } switch (option.option) { case 'h': usage(puts); return 0; case 'o': output = option.optarg; break; case 'I': includePaths.push(option.optarg); break; case 'f': formatter = formatters[option.optarg]; if (!formatter) { try { formatter = require(option.optarg); } catch (ex) {} } if (!formatter) { eputs('Cannot find formatter for ' + option.optarg); usage(eputs); return 1; } break; case 'r': try { var resolverPath = option.optarg; if (fs.existsSync(resolverPath)) { resolverClasses.push(require(Path.join(process.cwd(), resolverPath))); } else { resolverClasses.push(require(option.optarg)); } } catch (ex) { eputs('Error reading resolver ' + option.optarg + ': ' + ex); usage(eputs); return 1; } break; } } for (offset += parser.optind() - 2; args[offset] && args[offset][0] !== '-'; offset++) { files.push(args[offset]); } } assert.ok( files.length > 0, 'Please provide at least one file to convert.' ); if (typeof formatter === 'function') { formatter = new formatter(); } var resolvers = resolverClasses.map(function(resolverClass) { return new resolverClass(includePaths); }); var container = new Container({ formatter: formatter, resolvers: resolvers }); files.forEach(function(file) { container.getModule(file); }); if (output) { container.write(output); } else { var outputs = container.convert(); assert.equal( outputs.length, 1, 'Cannot output ' + outputs.length + ' files to stdout. ' + 'Please use the --output flag to specify where to put the ' + 'files or choose a formatter that concatenates.' ); process.stdout.write(recast.print(outputs[0]).code); } };
function install(argv, callback) { var $0 = process.env.CMD || path.basename(argv[1]); var parser = new Parser( [ ':v(version)', 'h(help)', 'b:(base)', 'e:(set-env)', 'u:(user)', 'p:(port)', 'j:(job-file)', 'n(dry-run)', 'f(force)', 'i:(upstart)', // -i unused, posix-getopt doesn't do long-only options 's(systemd)', 'm:(metrics)', 'a:(http-auth)', 'd:(driver)', 'P:(base-port)', 'I(skip-default-install)', ].join(''), argv); var jobConfig = { user: '******', pmBaseDir: null, pmPort: 8701, basePort: 3000, driver: 'direct', dryRun: false, jobFile: null, // strong-service-install provides an init-specific default force: false, upstart: false, systemd: false, env: {}, pmEnv: '', pmSeedEnv: {}, _touched: [], // not a real config, used for recording paths to chown dirs: [], }; var option; while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'v': console.log(require('../package.json').version); return callback(); case 'h': printHelp($0, console.log); return callback(); case 'b': jobConfig.pmBaseDir = option.optarg; jobConfig.dirs.push(jobConfig.pmBaseDir); break; case 'd': jobConfig.driver = option.optarg; break; case 'e': jobConfig.pmEnv = option.optarg; break; case 'p': jobConfig.pmPort = option.optarg; break; case 'P': jobConfig.basePort = option.optarg; break; case 'u': jobConfig.user = option.optarg; break; case 'j': jobConfig.jobFile = option.optarg; break; case 'n': jobConfig.dryRun = true; break; case 'f': jobConfig.force = true; break; case 'i': // actually --upstart jobConfig.upstart = option.optarg; break; case 's': jobConfig.systemd = true; break; case 'm': jobConfig.pmSeedEnv.STRONGLOOP_METRICS = option.optarg; break; case 'a': jobConfig.env.STRONGLOOP_PM_HTTP_AUTH = auth.parse(option.optarg).normalized; break; case 'I': // --skip-default-install jobConfig.env.STRONGLOOP_PM_SKIP_DEFAULT_INSTALL = 'true'; break; default: console.error('Invalid usage (near option \'%s\'), try `%s --help`.', option.optopt, $0); return callback(Error('usage')); } } if (parser.optind() !== argv.length) { console.error('Invalid usage (extra arguments), try `%s --help`.', $0); return callback(Error('usage')); } if (!(jobConfig.pmPort > 0)) { console.error('Port %j is not valid, try `%s --help`.', jobConfig.pmPort, $0); return callback(Error('usage')); } if (!(jobConfig.basePort > 0)) { console.error('Base port %j is not valid, try `%s --help`.', jobConfig.basePort, $0); return callback(Error('usage')); } if (!jobConfig.systemd && !jobConfig.upstart) { jobConfig.upstart = '1.4'; // default } else if (jobConfig.systemd && jobConfig.upstart) { console.error( 'Invalid usage (cannot specify both --systemd and --upstart)' + ', see `%s --help`', $0); return callback(Error('usage')); } if (!jobConfig.systemd && jobConfig.upstart !== '0.6' && jobConfig.upstart !== '1.4') { console.error('Invalid usage (only upstart "0.6" and "1.4" supported)' + ', see `%s --help`', $0); return callback(Error('usage')); } if (jobConfig.env.STRONGLOOP_PM_HTTP_AUTH && auth.parse(jobConfig.env.STRONGLOOP_PM_HTTP_AUTH).scheme === 'none') { console.error( 'Bad http-auth specification: %s', jobConfig.env.STRONGLOOP_PM_HTTP_AUTH); return callback(Error('usage')); } if (!/^(direct|docker)$/.test(jobConfig.driver)) { console.error('Invalid driver: %s', jobConfig.driver); return callback(Error('usage')); } if (jobConfig.upstart === '0.6' && jobConfig.driver === 'docker') { console.error('Upstart 0.6 does not support setgid. Please run:\n' + ' "sudo usermod -aG docker %s".', jobConfig.user); } if (jobConfig.driver === 'docker') { jobConfig.group = 'docker'; } jobConfig.name = 'strong-pm'; jobConfig.description = 'StrongLoop Process Manager'; jobConfig.command = [ process.execPath, require.resolve('../bin/sl-pm'), '--listen', jobConfig.pmPort, '--driver', jobConfig.driver, // --base is added in fixupCommand, after $HOME and $CWD get resovled ]; jobConfig.preWrite = fixupCommand; var steps = [ ensureDocker, slServiceInstall, ].map(w); return async.applyEachSeries(steps, jobConfig, report); function report(err) { if (err) { console.error('Error installing service \'%s\':', jobConfig.name, err.message); } return callback(err); } function w(fn) { return function(opts, cb) { debug('enter', fn.name); fn(opts, function(err) { debug('exit', fn.name, err); cb.apply(this, arguments); }); }; } }
exports.build = function build(argv, callback) { var $0 = process.env.SLC_COMMAND ? 'slc ' + process.env.SLC_COMMAND : path.basename(argv[1]); var parser = new Parser([ ':v(version)', 'h(help)', 's(scripts)', 'i(install)', 'b(bundle)', 'p(pack)', 'O:(onto)', 'c(commit)', 'N(no-commit)', ].join(''), argv); var option; var onto = 'deploy'; var install; var scripts; var bundle; var pack; var commit; while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'v': console.log(require('./package.json').version); return callback(); case 'h': printHelp($0, console.log); return callback(); case 's': scripts = true; break; case 'i': install = true; break; case 'b': bundle = true; break; case 'p': pack = true; break; case 'O': onto = option.optarg; break; case 'c': commit = true; break; case 'N': commit = false; break; default: console.error('Invalid usage (near option \'%s\'), try `%s --help`.', option.optopt, $0); return callback(Error('usage')); } } if (parser.optind() !== argv.length) { console.error('Invalid usage (extra arguments), try `%s --help`.', $0); return callback(Error('usage')); } // With no actions selected, do everything we can (onto requires an argument, // so we can't do it automatically). if (!(install || pack || commit || bundle)) { install = true; if (git.isGit()) { commit = true; bundle = pack = false; } else { commit = false; bundle = pack = true; } } if (commit && !git.isGit()) { console.error('Cannot perform commit on non-git working directory'); return callback(Error('usage')); } var steps = []; if (commit) { steps.push(doEnsureGitBranch); steps.push(doGitSyncBranch); } if (install) { steps.push(doNpmInstall); } if (bundle) { steps.push(doBundle); } if (pack) { steps.push(doNpmPack); } if (commit) { steps.push(doGitCommit); } vasync.pipeline({funcs: steps}, callback); function doEnsureGitBranch(_, callback) { try { git.ensureBranch(onto); return callback(); } catch(er) { console.error('%s', er.message); return callback(er); } } function doGitSyncBranch(_, callback) { try { var info = git.syncBranch(onto); if (info.srcBranch && info.dstBranch) console.log('Merged source tree of `%s` onto `%s`', info.srcBranch, info.dstBranch); else console.log('Not merging HEAD into `%s`, already up to date.', onto); return callback(); } catch(er) { console.error('%s', er.message); return callback(er); } } function doNpmInstall(_, callback) { var pkg = require(path.resolve('package.json')); var install = 'npm install'; if (!scripts) { install += ' --ignore-scripts'; } var steps = [ runStep(install) ]; if (pkg.scripts && pkg.scripts.build) { steps.push(runStep('npm run build')); } steps.push(runStep('npm prune --production')); vasync.pipeline({ funcs: steps }, function(er) { return callback(er); }); } function doBundle(_, callback) { // Build output won't get packed if it is .npmignored (a configuration // error, don't .npmignore your build output) or if there is no .npmignore, // if it is .gitignored (as they should be). So, create an empty .npmignore // if there is a .gitignore but not a .npmignore so build products are // packed. if (fs.existsSync('.gitignore') && !fs.existsSync('.npmignore')) { console.log('Running `touch .npmignore`'); console.warn('Check the auto-generated .npmignore is correct!'); fs.close(fs.openSync('.npmignore', 'a')); } // node_modules is unconditionally ignored by npm pack, the only way to get // the dependencies packed is to name them in the package.json's // bundledDepenencies. var info = require(path.resolve('package.json')); if (info.bundleDependencies || info.bundledDependencies) { // Use package specified dependency bundling return callback(); } // Bundle non-dev dependencies. Optional deps may fail to build at deploy // time, that's OK, but must be present during packing. If the user has // more specific desires, they can configure the dependencies themselves, or // just not run the --bundle action. var bundled = lodash.union( Object.keys(info.dependencies || {}), Object.keys(info.optionalDependencies || {}) ).sort(); debug('saving bundled: %j', bundled); if (bundled.length < 1) { return callback(); } console.log('Setting package.json "bundleDependencies" to: [\n %s\n]', bundled.join(',\n ')); // Re-write package.json, preserving its format if possible. json('package.json', function(er, p) { if (er) { console.error('Error reading package.json: %s', er.message); return callback(er); } p.data.bundleDependencies = bundled; p.save(function(er) { if (er) { console.error('Error writing package.json: %s', er.message); return callback(er); } return callback(); }); }); } function doNpmPack(_, callback) { var ignoreFiles = shell.find('node_modules').filter(function(file) { return file.match(/\.(git|npm)ignore$/); }); shell.rm('-f', ignoreFiles); runWait('npm --quiet pack', function(er, output) { if (er) return callback(er); // npm pack output is a single line with the pack file name var src = output.split('\n')[0]; var dst = path.join('..', src); console.log('Running `mv -f %s %s`', src, dst); shell.mv('-f', src, dst); return callback(); }); } function doGitCommit(_, callback) { try { var info = git.commitAll(onto); if (info.branch) console.log('Committed build products onto `%s`', info.branch); else console.log('Build products already up to date on `%s`', onto); return callback(); } catch(er) { console.error('%s', er.message); return callback(er); } } };
function main(argv, callback) { var $0 = process.env.CMD ? process.env.CMD : path.basename(argv[1]); var parser = new Parser([ ':v(version)', 'h(help)', 'b:(base)', 'c:(config)', 'l:(listen)', 'C:(control)', 'N(no-control)', ].join(''), argv); var base = '.strong-pm'; var config; var listen; var control = 'pmctl'; while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'v': console.log(require('./package.json').version); return callback(); case 'h': printHelp($0, console.log); return callback(); case 'b': base = option.optarg; break; case 'c': config = option.optarg; break; case 'l': listen = option.optarg; break; case 'C': control = option.optarg; break; case 'N': control = undefined; break; default: console.error('Invalid usage (near option \'%s\'), try `%s --help`.', option.optopt, $0); return callback(Error('usage')); } } base = path.resolve(base); if (control) control = path.resolve(control); if (config == null) { config = path.resolve(base, 'config'); } if (parser.optind() !== argv.length) { console.error('Invalid usage (extra arguments), try `%s --help`.', $0); return callback(Error('usage')); } if (listen == null) { console.error('Listen port was not specified, try `%s --help`.', $0); return callback(true); } // Run from base directory, so files and paths are created in it. mkdirp(base); process.chdir(base); var app = new Server($0, config, base, listen, control); app.on('listening', function(listenAddr){ console.log('%s: listen on %s, work base is `%s` with config `%s`', $0, listenAddr.port, base, config); }); app.start(); // XXX stop just signals the supervisor with SIGTERM, and closes sockets. // the socket close won't even complete while there are open connections..., // which may happen if exec keeps a persistent ipc connection on pm. I'm // not sure there is any point to this anymore, now what we only support // supervisor as a runner, and supervisor exits when the parent exits. I think // we can just let the signal terminate us, the OS will close sockets, and // supervisor will exit itself. // // A fair amount of code dribbles down from this point that could be deleted. stopWhenDone($0, app); return app; }
var modules = require('../lib'); var utils = require('../lib/utils'); var endsWith = utils.endsWith; var ExpectedError = require('./support/expected_error'); var examples = Path.join(__dirname, 'examples'); var paths = []; var formatters = require('../lib/formatters'); var formatterNames = Object.keys(formatters).filter(function(formatter) { return formatter !== 'DEFAULT'; }); var formatter = formatters.DEFAULT; var getopt = require('posix-getopt'); var parser = new getopt.BasicParser('h(help)f:(format)', process.argv); var option; while ((option = parser.getopt()) !== undefined) { if (option.error) { usage(); process.exit(1); } switch (option.option) { case 'f': formatter = option.optarg; if (formatterNames.indexOf(formatter) < 0) { usage(); process.exit(1); }
function parseOptions() { var option; //First take what's in the config file, override what's on the // command line, and use the defaults if all else fails. var opts = MOLA_CONFIG_OBJ; opts.shards = opts.shards || []; var parser = new getopt.BasicParser('a:b:m:no:p:y:F', process.argv); while ((option = parser.getopt()) !== undefined) { if (option.error) { usage(); } switch (option.option) { case 'a': opts.assetFile = option.optarg; break; case 'b': opts.backfill = option.optarg; break; case 'm': opts.shards.push(option.optarg); break; case 'n': opts.noJobStart = true; break; case 'o': opts.outputDirectory = option.optarg; break; case 'p': opts.pgMapDisk = lib.common.parseNumberOption( option.optarg, '-p', 1, null, usage); break; case 'y': opts.pgMapMemory = lib.common.parseNumberOption( option.optarg, '-y', 1, null, usage); break; case 'F': opts.forceRun = true; break; default: usage('Unknown option: ' + option.option); break; } } //Set up some defaults... opts.jobNamePrefix = opts.jobNamePrefix || 'manta_pg_transform'; //This is the root for all of the transform jobs. We'll split them // out later... opts.jobRoot = opts.jobRoot || MP + '/manta_pg_transform'; opts.assetDir = opts.jobRoot + '/assets'; opts.assetObject = opts.assetDir + '/mola.tar.gz'; opts.assetFile = opts.assetFile || '/opt/smartdc/common/bundle/mola.tar.gz'; opts.jobEnabled = opts.pgEnabled; opts.marlinPathToAsset = opts.assetObject.substring(1); opts.marlinAssetObject = opts.assetObject; //In places other than coal, the marlin and storage shard may not be // in the list of shards... if (opts.marlinShard && opts.shards.indexOf(opts.marlinShard) === -1) { opts.shards.push(opts.marlinShard); } if (opts.storageShard && opts.shards.indexOf(opts.storageShard) === -1) { opts.shards.push(opts.storageShard); } opts.pgMapDisk = opts.pgMapDisk || 16; opts.pgMapMemory = opts.pgMapMemory || 1024; if (opts.outputDirectory && !lib.common.endsWith(opts.outputDirectory, '/')) { opts.outputDirectory += '/'; } return (opts); }
function install(argv, opts, callback) { var $0 = process.env.CMD || path.basename(argv[1]); var parser = new Parser([ ':v(version)', 'h(help)', 'b:(base)', 'c:(config)', 'u:(user)', 'j:(job-file)', 'f(force)', 'i:(upstart)', // -i unused, posix-getopt doesn't do long-only options 's(systemd)' ].join(''), argv); var ignorePlatform = process.env.SL_PM_INSTALL_IGNORE_PLATFORM; var jobConfig = { user: opts.name, baseDir: null, // defaults to options.cwd in fillInHome port: 8701, jobFile: null, // strong-service-install provides an init-specific default force: false, upstart: false, systemd: false, env: {}, pmEnv: '', pmSeedEnv: {}, name: opts.name, description: opts.description, _touched: [] // not a real config, used for recording paths to chown }; var option; while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'v': console.log(require('../package.json').version); return callback(); case 'h': printHelp($0, console.log); return callback(); case 'b': jobConfig.baseDir = option.optarg; break; case 'u': jobConfig.user = option.optarg; break; case 'j': jobConfig.jobFile = option.optarg; break; case 'n': jobConfig.dryRun = true; break; case 'f': jobConfig.force = true; break; case 'i': // actually --upstart jobConfig.upstart = option.optarg; break; case 's': jobConfig.systemd = true; break; default: console.error('Invalid usage (near option \'%s\'), try `%s --help`.', option.optopt, $0); return callback(Error('usage')); } } if (parser.optind() !== argv.length) { console.error('Invalid usage (extra arguments), try `%s --help`.', $0); return callback(Error('usage')); } if (process.platform !== 'linux') { console.error('%s: only Upstart on Linux is supported', ignorePlatform ? 'Warning' : 'Error'); if (!ignorePlatform) return callback(Error('platform')); } if (!jobConfig.systemd && !jobConfig.upstart) { jobConfig.upstart = '1.4'; // default } else if (jobConfig.systemd && jobConfig.upstart) { console.error( 'Invalid usage (cannot specify both --systemd and --upstart)' + ', see `%s --help`', $0); return callback(Error('usage')); } if (!jobConfig.systemd && jobConfig.upstart !== '0.6' && jobConfig.upstart !== '1.4') { console.error('Invalid usage (only upstart "0.6" and "1.4" supported)' + ', see `%s --help`', $0); return callback(Error('usage')); } if (jobConfig.env.STRONGLOOP_PM_HTTP_AUTH && auth.parse(jobConfig.env.STRONGLOOP_PM_HTTP_AUTH).scheme === 'none') { console.error( 'Bad http-auth specification: %s', jobConfig.env.STRONGLOOP_PM_AUTH); return callback(Error('usage')); } var steps = [ ensureUser, fillInGroup, fillInHome, resolveIds, setCommand, ensureBaseDir, ensureOwner, serviceInstall ].map(w); return async.applyEachSeries(steps, jobConfig, report); function report(err) { if (err) { console.error('Error installing service \'%s\':', jobConfig.name, err.message); } return callback(err); } function w(fn) { return function (opts, cb) { debug('enter', fn.name); fn(opts, function (err) { debug('exit', fn.name, err); cb.apply(this, arguments); }); }; } }
mine_minimum_ether, faucets ); } init( null, account, mine_minimum_ether, upload_contracts ); } var option, optstring, parser, done; optstring = "d(debug)r(reset)g(geth)o(gospel)f(faucets)s(nodiscover)b(bootnodes)u:(augur)t:(contract)n:(networkid)"; parser = new getopt.BasicParser(optstring, process.argv); while ( (option = parser.getopt()) !== undefined) { switch (option.option) { case 'd': options.DEBUG = true; gethjs.debug = true; break; case 'r': options.RESET = true; options.SPAWN_GETH = true; break; case 'g': options.SPAWN_GETH = false; break; case 'f':
/* * Parse command-line options and common environment variables. This function * instantiates a node-getopt option parser that will handle the requested * command-line options plus the common options implemented in this file. * Common options are processed to fill in the "clientOptions" object described * below. Each command-specific option is passed to the "onOption" callback * function described below. * * The returned value is the node-getopt parser itself, which allows callers to * access the index of the last option argument that was parsed. * * Named arguments: * * argv command-line arguments, including Node's leading two * arguments. This would usually be `process.argv`. * * env process environment. This would usually be `process.env`. * * errstream stream for error messages. This would usually be * `process.stderr`. * * extraOptStr getopt-style option string for this command's custom * options. This will be combined with the common option * string above and used to parse options with node-getopt. * * clientOptions an object that will be populated with arguments used to * create a Moray client. That will include some combination * of "host", "port", and "srvDomain" as well as an appropriate * bunyan logger, configured based on the environment and * presence of "-v" options. This may also contain * cueballOptions. * * onUsage function to be invoked when there's a usage error * * onOption function to be invoked for each getopt option parsed. The * only argument is the option returned by node-getopt itself. * This field should be specified if and only if extraOptStr is * a non-empty string. The function should handle unrecognized * options (usually by invoking the caller's usage function). * * This function uses the MORAY_SERVICE and MORAY_URL environment variables from * `env` to fill in common options where possible. `LOG_LEVEL` is used to * configure the level of the bunyan logger. Log verbosity is increased with * each instance of the "-v" option. */ function parseCliOptions(args) { var parser, option, commonOpts, shortOpts; assert.object(args, 'args'); assert.object(args.argv, 'args.argv'); assert.object(args.env, 'args.env'); assert.object(args.errstream, 'args.errstream'); assert.string(args.extraOptStr, 'args.extraOptStr'); assert.object(args.clientOptions, 'args.clientOptions'); assert.func(args.onUsage, 'args.onUsage'); assert.optionalFunc(args.onOption, 'args.onOption'); if (args.extraOptStr === '') { assert.ok(typeof (args.onOption) != 'function'); } else { assert.func(args.onUsage, 'args.onOption'); } if (!args.clientOptions.log) { args.clientOptions.log = bunyan.createLogger({ 'name': path.basename(args.argv[1]), 'level': (args.env.LOG_LEVEL || 'fatal'), 'stream': process.stderr, 'serializers': bunyan.stdSerializers }); } /* * Validate that the extra option string doesn't try to override any of our * common options. It's easiest to strip out long option names and then * check for the presence of any of our options. */ shortOpts = args.extraOptStr; shortOpts = shortOpts.replace(/\([^)]*\)/g, ''); commonOpts = commonOptStr; commonOpts = commonOpts.replace(/\([^)]*\)/g, ''); commonOpts = commonOpts.replace(/:/g, ''); commonOpts.split('').forEach(function (c) { if (shortOpts.indexOf(c) != -1) { throw (new VError('internal error: ' + 'command cannot replace option: -%s', c)); } }); /* * Parse the combination option string. */ parser = new getopt.BasicParser(commonOptStr + args.extraOptStr, args.argv); while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'b': case 'h': case 'p': case 'S': case 'v': if (!parseCommonCliOption(args.errstream, args.clientOptions, option)) { args.onUsage(); } break; default: if (args.extraOptStr === '') { args.onUsage(); } else { args.onOption(option); } break; } } /* * For all of our commands, we use failFast by default so that the command * doesn't block indefinitely if Moray is down, and we use * mustCloseBeforeNormalProcessExit to make sure the commands clean up after * themselves. */ args.clientOptions.failFast = true; args.clientOptions.mustCloseBeforeNormalProcessExit = true; /* * Perform final validation of the common options. */ if (!finalizeCliOptions(args.errstream, args.clientOptions, args.env)) { args.onUsage(); } return (parser); }
/* * Library function that implements a testcase runner. The caller passes: * * testcases the set of testcases to choose from, as an object with * values of the test case object passed to * jobTestCaseRun(). * * argv process arguments, allowing users to specify common * arguments like "-S" to mean "non-strict mode" * * concurrency number of testcases to run concurrently */ function jobTestRunner(testcases, argv, concurrency) { var parser, option, opts, cases; var queue, api, timeout; parser = new mod_getopt.BasicParser('S', argv); /* * By default, we run in strict mode. Users can override that using the * MARLIN_TESTS_STRICT environment variable or the -S command-line * option. For details on what "strict" means, see jobTestCaseRun(). */ opts = { 'strict': true }; if (process.env['MARLIN_TESTS_STRICT'] == 'false') opts.strict = false; while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'S': opts.strict = false; break; default: /* error message already emitted by getopt */ mod_assert.equal('?', option.option); break; } } /* * Test cases are supposed to have a label so that jobTestCaseRun can * report which test its running, but for convenience most of them * aren't present directly in the test case definition. Fill them in * here. */ mod_jsprim.forEachKey(testcases, function (name, testcase) { testcase['label'] = name; }); /* * Figure out which cases the user selected. If none, run all of them. */ cases = []; if (argv.length > parser.optind()) { argv.slice(parser.optind()).forEach(function (name) { if (!testcases.hasOwnProperty(name)) throw (new VError('no such test: "%s"', name)); cases.push(testcases[name]); }); } else { mod_jsprim.forEachKey(testcases, function (_, testcase) { cases.push(testcase); }); } /* * The "concurrency" argument determines how many test cases we can run * concurrently. When concurrency > 1, we allow each test to take * longer to account for the fact that they're all sharing resources, * but the total test time shouldn't change. */ if (concurrency > 1) { timeout = cases.reduce(function (sum, testjob) { return (sum + testjob['timeout']); }, 0); log.info('using timeout = %s', timeout); cases.forEach(function (testcase) { testcase['timeout'] = timeout; }); } /* * To implement all possible values for "concurrency", we run the tests * through a vasync queue with the corresponding concurrency. */ queue = mod_vasync.queue(function (testcase, queuecb) { jobTestCaseRun(api, testcase, opts, function (err) { if (err) { err = new VError(err, 'TEST FAILED: "%s"', testcase['label']); log.fatal(err); throw (err); } queuecb(); }); }, concurrency); /* * Finally, run the tests. */ mod_testcommon.pipeline({ 'funcs': [ function setup(_, next) { mod_testcommon.setup(function (c) { api = c; next(); }); }, function runTests(_, next) { queue.on('end', next); queue.push(cases); queue.close(); }, function teardown(_, next) { mod_testcommon.teardown(api, next); } ] }); }
function parseOptions() { var option; //First take what's in the config file, override what's on the // command line, and use the defaults if all else fails. var opts = MOLA_REBALANCE_CONFIG_OBJ; opts.shards = opts.shards || []; opts.ignoreSharks = []; var parser = new getopt.BasicParser('a:h:i:m:nr:s:t', process.argv); while ((option = parser.getopt()) !== undefined && !option.error) { switch (option.option) { case 'a': opts.assetFile = option.optarg; break; case 'h': opts.host = option.optarg; break; case 'i': opts.ignoreSharks.push(option.optarg); break; case 'm': opts.shards.push(option.optarg); break; case 'n': opts.noJobStart = true; break; case 'r': opts.rebalanceMemory = parseInt(option.optarg, 10); break; case 's': opts.storageShard = option.optarg; break; case 't': opts.jobName = 'manta_rebalance_test'; opts.jobRoot = MP + '/manta_rebalance_test'; break; default: usage('Unknown option: ' + option.option); break; } } if (!opts.storageShard) { usage('Storage shard is required.'); } //Set up some defaults... opts.jobName = opts.jobName || 'manta_rebalance'; opts.jobRoot = opts.jobRoot || MP + '/manta_rebalance'; opts.directories = [ opts.jobRoot + '/do' ]; opts.assetDir = opts.jobRoot + '/assets'; opts.assetObject = opts.assetDir + '/mola.tar.gz'; opts.sharksAssetObject = opts.assetDir + '/sharks.json'; opts.assetFile = opts.assetFile || '/opt/smartdc/common/bundle/mola.tar.gz'; opts.rebalanceMemory = opts.rebalanceMemory || 4096; opts.marlinPathToAsset = opts.assetObject.substring(1); opts.marlinAssetObject = opts.assetObject; return (opts); }