
module.exports = config

var ini = require("./utils/ini")
  , log = require("./utils/log")
  , sys = require("sys")
  , npm = require("../npm")

// npm config set key value
// npm config get key
// npm config list
function config (args, cb) {
  var action = args.shift()
  switch (action) {
    case "set": return set(args[0], args[1], cb)
    case "get": return get(args[0], cb)
    case "delete": case "rm": case "del": return del(args[0], cb)
    case "list": case "ls": return list(cb)
    default: return unknown(action, cb)
  }
}

function del (key, cb) {
  if (!key) return cb(new Error(
    "no key provided"))
  ini.del(key)
  ini.save(cb)
}

function set (key, val, cb) {
  if (val === undefined && key.indexOf("=") !== -1) {
    var k = key.split("=")
    key = k.shift()
    val = k.join("=")
  }
  key = key.trim()
  val = val.trim()
  log("set "+key+" "+val, "config")
  var where = ini.get("global") ? "global" : "user"
  ini.set(key, val, where)
  ini.save(cb)
}

function get (key, cb) {
  if (key.charAt(0) === "_") return cb(new Error("---sekretz---"))
  sys.puts(npm.config.get(key))
  cb()
}

function list (cb) {
  ini.keys.sort(function (a,b) { return a > b ? 1 : -1 })
    .forEach(function (i) {
      var val = (i.charAt(0) === "_")
          ? "---sekretz---"
          : JSON.stringify(ini.get(i))
      log(i+" "+val, "config")
    })
  cb()
}

function unknown (action, cb) {
  cb(new Error("Unrecognized config command "+action))
}

@@ -89,33 +89,8 @@
 g%22)%0A
-  , sys = require(%22sys%22)%0A
   , 
@@ -1047,16 +1047,19 @@
 )%0A  
-sys.puts
+console.log
 (npm
@@ -1308,31 +1308,50 @@
     
-log(i+%22 %22+val, %22config%22
+console.log(i.replace(/%5E_/,';_')+%22 = %22+val
 )%0A  

Use console.log instead of sys.puts, and output in ini format