How to use extsprintf - 10 common examples

To help you get started, we’ve selected a few extsprintf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joyent / dragnet / lib / datasource-manta.js View on Github external
throw (new VError('internal error: don\'t know how ' +
			    'serialize field property "%s"', key));
		});

		if (!hasextra) {
			fields.push(shEscape(fc.name));
			return;
		}

		fields.push(sprintf('%s[%s]', shEscape(fc.name),
		    values.join(',')));
	});

	if (fields.length > 0)
		/* XXX escape commas, semicolons, and spaces in field names? */
		rv.push(sprintf('--breakdowns=%s', fields.join(',')));

	return (rv);
};
github joyent / dragnet / lib / source-manta.js View on Github external
/* XXX figure out hourly vs. daily */
	query = args.query;
	inputstream = this.listInputs(args.indexroot,
	    'by_day/%Y-%m-%d.sqlite', query);
	if (inputstream instanceof Error)
		return (this.asyncError(inputstream));

	job = this.jobBuilder();
	job.inputstream = inputstream;
	job.builder.name('dragnet query');
	job.builder.phase({
	    'type': 'map',
	    'assets': [ job.assetpath ],
	    'init': sprintf(JOBTPL_INIT_UNPACK_ASSET, job.assetpath),
	    'exec': sprintf(JOBTPL_EXEC_QUERY0,
	        queryToCliArgs(query, false, 'breakdowns').join(' '))
	});

	job.builder.phase({
	    'type': 'reduce',
	    'assets': [ job.assetpath ],
	    'init': sprintf(JOBTPL_INIT_UNPACK_ASSET, job.assetpath),
	    'exec': sprintf(JOBTPL_EXEC_SCAN0, 'json-skinner') + ' ' +
		queryToCliArgs(query, true, 'breakdowns').join(' ') +
		' /dev/stdin'
	});

	rv = mod_vstream.wrapTransform(new mod_stream.PassThrough({
	    'objectMode': true,
	    'highWaterMark': 0
	}));
github joyent / manatee / test / tst.manateeAdmUsage.js View on Github external
/*
 * manateeAdmUsage.test.js: test invocations of the "manatee-adm" command
 * Just run this test directly with Node, not with nodeunit.  All manatee-adm
 * subcommands should be covered by a test case below.  This program will fail
 * if it finds a subcommand with no test cases.
 */

var assertplus = require('assert-plus');
var forkexec = require('forkexec');
var path = require('path');
var vasync = require('vasync');
var VError = require('verror');
var extsprintf = require('extsprintf');

var sprintf = extsprintf.sprintf;
var fprintf = extsprintf.fprintf;

/*
 * Test cases are configured with the "subcmds" object below, which specifies
 * two properties for each "manatee-adm" subcommand:
 *
 *     o the list of required arguments
 *
 *     o whether running the command with all required arguments is
 *       "destructive", by which we mean only that it makes any actual changes
 *       to a Manatee cluster
 *
 * Using this configuration, the test suite will invoke the subcommand several
 * times:
 *
 *     o For each required argument, the subcommand will be invoked once with
 *       that argument _missing_ but the other required arguments present.  The
github joyent / node-verror / examples / props-verror.js View on Github external
console.log('%s',
	    sprintf('%15s: %s', 'constructor', err.constructor.name));
	for (i = 0; i < props.length; i++) {
		prop = props[i];

		if (prop != 'name' && !err.hasOwnProperty(prop))
			continue;

		if (prop == '_cause')
			continue;

		console.log('%s', sprintf('%15s: %s', prop, err[prop]));
	}

	console.log('%s', sprintf('%15s: %s', 'toString', err.toString()));

	var cause = err.cause ? err.cause() : null;
	if (cause) {
		console.log('\nCAUSED BY:');
		dump(cause);
	}
}
github bahamas10 / hue-cli / hue-cli.js View on Github external
function printf() { console.log(sprintf.apply(this, arguments)); }
github joyent / manatee / lib / adm.js View on Github external
if (lst.oneNodeWriteMode && !nst.oneNodeWriteMode) {
        return ('cluster transitioned from singleton ' +
            '(one-node-write) mode to multi-peer mode');
    }

    if (nst.primary.zoneId != lst.primary.zoneId) {
        if (nst.generation == lst.generation) {
            return ('error: new primary, but same gen number');
        }

        if (lst.sync === null ||
            nst.primary.zoneId != lst.sync.zoneId) {
            return ('error: new primary was not previous sync');
        }

        return (sprintf('sync (%s) took over as primary (from %s)',
            nst.primary.zoneId.substr(0, 8),
            lst.primary.zoneId.substr(0, 8)));
    }

    if (nst.generation > lst.generation) {
        if (lst.sync === null && lst.oneNodeWriteMode !== true) {
            /*
             * We seem to have arrived here due to an invalid state on the
             * previous generation, namely the previous generation is
             * multi-mode, writable, with no replicas. This should never
             * happen, but somehow it did. At any rate, we're just happy that
             * there's a replica now.
             */
            return (sprintf('sync "%s" added',
                nst.sync.zoneId.substr(0, 8)));
        }
github joyent / dragnet / lib / source-manta.js View on Github external
keys.forEach(function (key) {
			if (key != 'name') {
				if (!fc[key])
					values.push(shEscape(key));
				else
					values.push(sprintf('%s=%s',
					    shEscape(key),
					    shEscape(fc[key].toString())));
			}

			if (key == 'date' || key == 'aggr') {
				hasextra = true;
				return;
			}

			if (key == 'step' || key == 'name' || key == 'field')
				return;

			/*
			 * XXX Blow up here if we encounter a field
			 * configuration that we don't know how to serialize.
			 * It would be nice if we could verify this statically,
github joyent / dragnet / lib / source-manta.js View on Github external
str = query.qc_before.toISOString();
			rv.push(sprintf('--before "%s"', str));
			str = query.qc_after.toISOString();
			rv.push(sprintf('--after "%s"', str));
		}

		/*
		 * If there was an extra time field, we need to pass that
		 * through to the first phase.
		 */
		fields = query.qc_synthetic.filter(function (fc) {
			return (!query.qc_fieldsbyname.hasOwnProperty(fc.name));
		});
		if (fields.length > 0) {
			mod_assertplus.ok(fields.length == 1);
			rv.push(sprintf('--time-field=%s', fields[0].name));
		}
	}

	fields = [];
	query.qc_breakdowns.forEach(function (ofc) {
		var fc, keys, hasextra, values;

		/*
		 * The first phase is a direct translation of the command-line
		 * arguments, but subsequent phases are special in the case of
		 * synthetic fields, since these values will already be present
		 * in those phases, and the origin field likely won't.  We
		 * rewrite these here, and we assert that such fields (which are
		 * always dates) are aggregated in order to make sure the
		 * numeric type is preserved.  This is pretty gnarly.
		 */
github joyent / smartos-live / src / img / lib / cli.js View on Github external
var beforeText = before.map(function (s) {
                var options = [];
                if (s.insecure) {
                    options.push('insecure');
                }
                return sprintf(template, s.url, s.type, options.join(','))
                    .trimRight();
            }).join('\n')
            + '\n\n'
github joyent / node-jsprim / lib / jsprim.js View on Github external
function iso8601(d)
{
	if (typeof (d) == 'number')
		d = new Date(d);
	mod_assert.ok(d.constructor === Date);
	return (mod_extsprintf.sprintf('%4d-%02d-%02dT%02d:%02d:%02d.%03dZ',
	    d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate(),
	    d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(),
	    d.getUTCMilliseconds()));
}

extsprintf

extended POSIX-style sprintf

MIT
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis

Similar packages