<commit_before>#!/usr/bin/env node

// usage:
// npm [global options] command [command args]

// only run as main module.
if (module.id !== ".") return;

// figure out where we're at.
// don't assume that npm is installed in any particular spot, since this
// might conceivably be a bootstrap attempt.
var fs = require("fs"),
  path = require("path"),
  sys = require("sys"),
  path = require("path"),
  npm;
if (fs.lstatSync(__filename).isSymbolicLink()) {
  npm = path.join(path.dirname(fs.readlinkSync(__filename)), "npm");
} else {
  npm = path.join(__dirname, "npm");
}
npm = require(npm);

// supported commands.
var commands = ["help", "install", "activate", "ls", "list"],
  log = require(npm.moduleName+"/../lib/utils").log;

var argv = process.argv, arg = "";
while (argv.shift() !== module.filename);

log("cli: "+sys.inspect(process.argv));

// add usage onto any existing help documentation.
npm.help = (function (h) { return function () {
  usage();
  h && h.apply(npm, arguments);
}})(npm.help);

var globalOption = (function () {
  // state or something goes here.
  return function (arg) {
    usage();
    throw new Error("global options not yet implemented");
  }
})();

var state = "globalOptions", command = "help";
while (arg = argv.shift()) {
  if (commands.indexOf(arg) !== -1) {
    command = arg;
    break;
  } else globalOption(arg);
}

function usage () {
  var out = (arg === "help" ? "puts" : "error");
  function p (m) { sys[out](m); return p };
  p
    ("")
    ("Usage: ")
    ("  " + path.basename(module.filename) + " [global options] <command> [command options]")
    ("")
    ("[global options]   Not yet implemented")
    ("<command>          Method to call on the npm object.")
    ("                   Supported: "+commands)
    ("[command options]  The arguments to pass to the function.");
}

var result = npm[command].apply(npm, argv.concat(function (er, ok) {
  if (er) {
    log("failed " + er.message);
    throw er;
  } else log("ok");
}));
<commit_msg>Better logging.<commit_after>#!/usr/bin/env node

// usage:
// npm [global options] command [command args]

// only run as main module.
if (module.id !== ".") return;

// figure out where we're at.
// don't assume that npm is installed in any particular spot, since this
// might conceivably be a bootstrap attempt.
var fs = require("fs"),
  path = require("path"),
  sys = require("sys"),
  path = require("path"),
  npm;
if (fs.lstatSync(__filename).isSymbolicLink()) {
  npm = path.join(path.dirname(fs.readlinkSync(__filename)), "npm");
} else {
  npm = path.join(__dirname, "npm");
}
npm = require(npm);

// supported commands.
var commands = ["help", "install", "activate", "ls", "list"],
  log = require(npm.moduleName+"/../lib/utils").log;

var argv = process.argv, arg = "";
while (argv.shift() !== module.filename);

log(sys.inspect(process.argv), "cli");

// add usage onto any existing help documentation.
npm.help = (function (h) { return function () {
  usage();
  h && h.apply(npm, arguments);
}})(npm.help);

var globalOption = (function () {
  // state or something goes here.
  return function (arg) {
    usage();
    throw new Error("global options not yet implemented");
  }
})();

var state = "globalOptions", command = "help";
while (arg = argv.shift()) {
  if (commands.indexOf(arg) !== -1) {
    command = arg;
    break;
  } else globalOption(arg);
}

function usage () {
  var out = (arg === "help" ? "puts" : "error");
  function p (m) { sys[out](m); return p };
  p
    ("")
    ("Usage: ")
    ("  " + path.basename(module.filename) + " [global options] <command> [command options]")
    ("")
    ("[global options]   Not yet implemented")
    ("<command>          Method to call on the npm object.")
    ("                   Supported: "+commands)
    ("[command options]  The arguments to pass to the function.");
}

var result = npm[command].apply(npm, argv.concat(function (er, ok) {
  if (er) {
    log("failed " + er.message);
    throw er;
  } else log("ok");
}));

{'fraction_non_alphanumeric': 0.1868598551086685, 'fraction_numerical': 0.0004996252810392206, 'mean_word_length': 3.319309600862999, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4270640', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1273, 'n_words': 387}