Skip to content

Commit

Permalink
Source format node-gh#88
Browse files Browse the repository at this point in the history
  • Loading branch information
zenorocha committed Jun 7, 2013
1 parent 2cfeb1a commit 9411d44
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 43 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
npm-debug.log
.DS_Store
.idea
.DS_Store
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
* [Dependencies](https://github.com/eduardolundgren/node-gh#dependencies)
* [Demonstration](https://github.com/eduardolundgren/node-gh#demonstration)
* [Available commands](https://github.com/eduardolundgren/node-gh#available-commands)
* [Pull requests](https://github.com/eduardolundgren/node-gh#pull-requests)
* [Notifications](https://github.com/eduardolundgren/node-gh#notifications)
* [Issues](https://github.com/eduardolundgren/node-gh#issues)
* [Pull requests](https://github.com/eduardolundgren/node-gh#pull-requests)
* [Notifications](https://github.com/eduardolundgren/node-gh#notifications)
* [Issues](https://github.com/eduardolundgren/node-gh#issues)
* [User](https://github.com/eduardolundgren/node-gh#user)
* [Team](https://github.com/eduardolundgren/node-gh#team)
* [Contributing](https://github.com/eduardolundgren/node-gh#contributing)
* [History](https://github.com/eduardolundgren/node-gh#history)
Expand Down Expand Up @@ -437,6 +438,35 @@ gh is --list --label todo,bug
gh is --list --user eduardolundgren --repo node-gh
```
## User
```
gh user
```
> **Alias:** `gh us`
### 1. Login/Logout
Option | Usage | Type
--- | --- | ---
`-l`, `--login` | **Required** | `Boolean`
`-L`, `--logout` | **Required** | `Boolean`
#### Examples
* Login.
```
gh user --login
```
* Logout.
```
gh user --logout
```
## Team
[![Eduardo Lundgren](http://gravatar.com/avatar/42327de520e674a6d1686845b30778d0?s=70)](https://github.com/eduardolundgren/) | [![Zeno Rocha](http://gravatar.com/avatar/e190023b66e2b8aa73a842b106920c93?s=70)](https://github.com/zenorocha/)
Expand Down Expand Up @@ -484,16 +514,16 @@ Contribute new commands to this project by copying and editing the content of [H
* Rename pull request `--comment` to `--message`
* Rename pull request `--pull` to `--number`
* **v0.1.3** May 28, 2013
* Remove mustache dependency
* Remove mustache dependency
* **v0.1.2** May 28, 2013
* Removing wrong number on submit
* Removing wrong number on submit
* **v0.1.1** May 27, 2013
* Add **Help** task
* Standardize logs
* Bug fixes
* **v0.1.0** May 26, 2013
* Allow log handlebars template from string
* Move apply replacements logic to logger
* Allow log handlebars template from string
* Move apply replacements logic to logger
* Use handlebars templates instead of strings
* Refactoring template integration with logger
* Rename pull request `--comment` to `--message`
Expand Down
19 changes: 10 additions & 9 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ exports.authorize = function(opt_callback) {
opt_callback && opt_callback();
};

exports.logout = function() {
fs.unlink(exports.getGlobalConfigPath(), function (err) {
if (err) throw err;
logger.success('Successfully logout!');
});
}

exports.createAuthorization = function(opt_callback) {
logger.log('First we need authorization to use GitHub\'s API');

Expand Down Expand Up @@ -156,7 +149,7 @@ exports.hasCredentials = function() {

config = exports.getGlobalConfig();

if (config.github_token && config.github_user && config.github_token != '' && config.github_user != '') {
if (config.github_token && config.github_user) {
return true;
}
return false;
Expand All @@ -171,6 +164,12 @@ exports.login = function(opt_callback) {
}
};

exports.logout = function() {
var configPath = exports.getGlobalConfigPath();

fs.unlink(configPath, logger.defaultCallback);
};

exports.writeGlobalConfig = function(jsonPath, value) {
var config,
i,
Expand All @@ -194,7 +193,9 @@ exports.writeGlobalConfig = function(jsonPath, value) {
};

exports.writeGlobalConfigCredentials = function(user, token) {
logger.success('Writing config data to file: ' + exports.getGlobalConfigPath() );
var configPath = exports.getGlobalConfigPath();

logger.success('Writing GH config data: ' + configPath);
exports.writeGlobalConfig('github_user', user);
exports.writeGlobalConfig('github_token', token);
};
1 change: 0 additions & 1 deletion lib/cmds/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Help.prototype.run = function() {
}

logger.logTemplateFile('help.handlebars', {
userName: base.getUser(),
commands: cmdOutput
});
};
Expand Down
2 changes: 0 additions & 2 deletions lib/cmds/templates/help.handlebars
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{{prefix}} Logged in as: {{{userName}}}
{{prefix}}
{{prefix}} Syntax: {{{cyan "gh"}}} [{{{magentaBright "command"}}}] [{{{cyanBright "payload"}}}] [{{{greenBright "--flags"}}}]
{{prefix}}
{{prefix}} List of available commands:
Expand Down
48 changes: 26 additions & 22 deletions lib/cmds/log.js → lib/cmds/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,49 @@ var base = require('../base'),
logger = require('../logger');

// -- Constructor --------------------------------------------------------------
function Log(options) {
function User(options) {
this.options = options;
}

// -- Constants ----------------------------------------------------------------
Log.DETAILS = {
description: 'Provides the ability to logout if needed and re-login',
User.DETAILS = {
alias: 'us',
description: 'Provides the ability to logout if needed and re-login.',
options: {
'login': Boolean,
'logout': Boolean,
'user': String,
'password': String
'login' : Boolean,
'logout': Boolean
},
shorthands: {
'i': [ '--login' ],
'o': [ '--logout' ],
'u': [ '--user' ],
'p': [ '--password' ]
'l': [ '--login' ],
'L': [ '--logout' ]
},
payload: function(payload, options) {
options.login = true;
}
};

// -- Commands -----------------------------------------------------------------
Log.prototype.run = function() {
User.prototype.run = function() {
var instance = this,
options = instance.options;
options.login = options.login || instance.logout();
options.logout = options.logout || instance.login(options);
};

function opt_callback() {
// implement
}
if (options.login) {
logger.logTemplate('{{prefix}} [info] You\'re already logged in as {{greenBright options.user}}', {
options: options
});
}

if (options.logout) {
logger.logTemplate('{{prefix}} [info] Logging out of user {{greenBright options.user}}', {
options: options
});

Log.prototype.login = function(options) {
base.createAuthorization(opt_callback);
instance.logout();
}
};

Log.prototype.logout = function() {
User.prototype.logout = function() {
base.logout();
};

exports.Impl = Log;
exports.Impl = User;

0 comments on commit 9411d44

Please sign in to comment.