Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Fix #13
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardolundgren committed Jun 4, 2013
1 parent 0bcb768 commit 73b9e05
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
48 changes: 36 additions & 12 deletions bin/gh.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
* @author Eduardo Lundgren <[email protected]>
*/

// -- Requires -----------------------------------------------------------------
var async = require('async'),
base = require('../lib/base'),
fs = require('fs'),
git = require('../lib/git'),
help = require('../lib/cmds/help').Impl.prototype,
logger = require('../lib/logger'),
nopt = require('nopt'),
commandFilePath,
commandImpl,
path = require('path'),
command,
commandDir,
commandFiles,
commandPath,
cooked,
operations,
options,
parsed,
remain,
payload;
payload,
remain;

// -- Init ---------------------------------------------------------------------
operations = [];
parsed = nopt(process.argv);
remain = parsed.argv.remain;
Expand All @@ -34,14 +39,33 @@ if (!remain.length) {
process.exit(0);
}

commandFilePath = __dirname + '/../lib/cmds/' + remain[0] + '.js';
commandDir = path.join(__dirname, '..', 'lib', 'cmds');
commandPath = path.join(commandDir, remain[0] + '.js');

if (fs.existsSync(commandFilePath)) {
commandImpl = require(commandFilePath).Impl;
// -- Find command -------------------------------------------------------------
if (fs.existsSync(commandPath)) {
command = require(commandPath).Impl;
}
else {
commandFiles = base.find(commandDir, /\.js$/i);
commandFiles.every(function(file) {
commandPath = path.join(commandDir, file);
command = require(commandPath).Impl;

if (command.DETAILS.alias === remain[0]) {
return false;
}

command = null;
return true;
});
}

// -- Run command --------------------------------------------------------------
if (command) {
options = nopt(
commandImpl.DETAILS.options,
commandImpl.DETAILS.shorthands, process.argv, 2);
command.DETAILS.options,
command.DETAILS.shorthands, process.argv, 2);

cooked = options.argv.cooked;

Expand All @@ -55,13 +79,13 @@ if (fs.existsSync(commandFilePath)) {
options.repo = options.repo || results[2];
options.currentBranch = options.currentBranch || results[3];

if ((remain.length === cooked.length) && commandImpl.DETAILS.payload) {
if ((remain.length === cooked.length) && command.DETAILS.payload) {
payload = options.argv.cooked.concat();
payload.shift();
commandImpl.DETAILS.payload(payload, options);
command.DETAILS.payload(payload, options);
}

new commandImpl(options).run();
new command(options).run();
});
}
else {
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/is.js → lib/cmds/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Issue(options) {

// -- Constants ----------------------------------------------------------------
Issue.DETAILS = {
alias: 'is',
description: 'Provides a set of util commands to work with Issues.',
options: {
'all' : Boolean,
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/nt.js → lib/cmds/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Notifications(options) {

// -- Constants ----------------------------------------------------------------
Notifications.DETAILS = {
alias: 'nt',
description: 'Provides a set of util commands to work with Notifications.',
options: {
'latest': Boolean,
Expand Down
3 changes: 2 additions & 1 deletion lib/cmds/pr.js → lib/cmds/pull-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var async = require('async'),
path = require('path'),
logger = require('../logger'),
stripNewLines,
issueImpl = require('./is').Impl;
issueImpl = require('./issue').Impl;

// -- Constructor --------------------------------------------------------------
function PullRequest(options) {
Expand All @@ -32,6 +32,7 @@ function PullRequest(options) {

// -- Constants ----------------------------------------------------------------
PullRequest.DETAILS = {
alias: 'pr',
description: 'Provides a set of util commands to work with Pull Requests.',
options: {
'all' : Boolean,
Expand Down

0 comments on commit 73b9e05

Please sign in to comment.