Permalink
Browse files

factor out argv remote checking into lib/argv.js

  • Loading branch information...
1 parent cc9fc12 commit 175b125727bd0b13d41aaa5ccd0e823e35d67f10 @substack committed Feb 29, 2012
Showing with 23 additions and 6 deletions.
  1. +4 −6 bin/deploy.js
  2. +15 −0 lib/argv.js
  3. +4 −0 lib/remote.js
View
@@ -1,16 +1,14 @@
#!/usr/bin/env node
-var argv = require('optimist').argv;
var propagit = require('propagit');
var seaport = require('seaport');
var EventEmitter = require('events').EventEmitter;
var git = require('../lib/git');
-
-// todo: infer repo from dirname and commit from `git log|head -n1`
+var argv = require('../lib/argv');
var p = propagit(argv);
p.on('error', function (err) {
- console.dir(err);
+ console.log(err.stack || err.toString());
});
p.hub(function (hub) {
@@ -37,10 +35,10 @@ p.hub(function (hub) {
});
function deploy (hub, opts) {
- var remote = 'http://' + argv.hub.split(':')[0]
+ var ref = 'http://' + argv.hub.split(':')[0]
+ ':' + hub.ports.git + '/' + opts.repo;
- git.push(remote, function (err) {
+ git.push(ref, function (err) {
if (err) {
console.error(err);
p.hub.close();
View
@@ -0,0 +1,15 @@
+var remote = require('./remote');
+var argv = module.exports = require('optimist').argv;
+
+// bare args with a leading + are remotes
+var args = argv._.reduce(function (acc, arg) {
+ if (!/^\+/.test(arg)) acc.remote = arg
+ else acc._.push(arg)
+ return acc;
+}, { _ : [] });
+argv.remote = argv.remote || args.remote;
+argv._ = args._;
+
+var target = remote.get(argv.remote || 'default');
+if (target && !argv.hub) argv.hub = target.hub;
+if (target && !argv.secret) argv.secret = target.secret;
View
@@ -30,3 +30,7 @@ exports.remove = function (name) {
exports.list = function () {
return remote;
};
+
+exports.get = function (name) {
+ return remote[name];
+};

0 comments on commit 175b125

Please sign in to comment.