Skip to content

Commit

Permalink
Proper command design
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Jan 18, 2012
1 parent 434c2bd commit b2f87d0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,31 @@ police flatiron/plates
police -l ~/octonode
police -l ~/octonode/package.json

# To continue checking even though errors are encountered
# To continue checking even though errors are encountered (Doesnt work with -l)
police -f
police -u flatiron -f

# To edit and update missing keywords in package.json
police -k
police octonode -k
police -u flatiron -k
police flatiron/plates -k
# To edit all the fields in package.json (Doesnt work with -l)
police -e

# To edit and update dependencies in package.json
police -p
police octonode -p
police -u flatiron -p
police flatiron/plates -p
police -l ~/octonode -p
# To add the missing fields to package.json (Doesnt work with -l)
police -a

# To update dependencies in package.json
police -t
```

Given below are some ideal commands to help you.

```sh
# An ideal police command for github user for the first time on a module
police -f -e -t

# An ideal police command for github user
police -f -k -p
police -u flatiron -f -k -p
police -f -a -t

# An ideal police command locally
police -l ~/octonode -p
police -l ~/octonode -t
```

The token which we acquied during auth will be stored in `$HOME/.policeconf`. If you want to use another config file
Expand Down
19 changes: 13 additions & 6 deletions lib/police.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,24 @@ police.start = function (argv, callback) {
}

/*
* Set keywords parameter
* Set add parameter
*/
if (argv.keywords || argv.k) {
police.keywords = true;
if (argv.add || argv.a) {
police.add = true;
}

/*
* Set packages parameter
* Set edit parameter
*/
if (argv.packages || argv.p) {
police.packages = true;
if (argv.edit || argv.e) {
police.edit = true;
}

/*
* Set update parameter
*/
if (argv.update || argv.t) {
police.update = true;
}

/*
Expand Down
12 changes: 6 additions & 6 deletions lib/police/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ var path = require('path')
, police = require('../police');

/*
* Properties of keywords
* Properties of fields
*/
var prop = [];

/*
* Github data for keywords
* Github data for fields
*/
var gh = {};

Expand Down Expand Up @@ -48,14 +48,14 @@ ask.properties = function (pkg, gh) {
}

/*
* The main function which asks keywords and writes them
* The main function which asks fields and writes them
*/
ask.keywords = function (pkg, fields, callback) {
ask.fields = function (pkg, fields, callback) {
ask.release(function () {
if (!pkg.dependencies) pkg.dependencies = {};
if (!pkg.devDependencies) pkg.devDependencies = {};

if (!pkg.name) {
if (!pkg.name || police.edit) {
prop.push({
message: 'Module name',
name: 'name',
Expand All @@ -66,7 +66,7 @@ ask.keywords = function (pkg, fields, callback) {
});
}

if (!pkg.version) {
if (!pkg.version || police.edit) {
prop.push({
message: 'Module version',
name: 'version',
Expand Down
4 changes: 2 additions & 2 deletions lib/police/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ check.suggest = function (pkg, callback) {
} else {
police.winston.info(' ✗'.red.bold + ' Suggest adding ' + suggestions.join(', '));
}
if (police.keywords) {
police.ask.keywords(pkg, fields, callback);
if (police.add || police.edit) {
police.ask.fields(pkg, fields, callback);
} else {
callback();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/police/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ github.singleModule = function (name, callback) {
police.winston.info(' Getting package.json blob ' + blob[0].sha.substr(0,10).magenta);
github.blob(name, blob[0].sha, function (body) {
var pkg = JSON.parse(new Buffer(body.content, 'base64').toString('utf8'));
if (police.keywords) {
if (police.add || police.edit) {
var sname = name.split('/');
police.ask.properties(pkg, {name: name, repo: sname[1], user: sname[0]});
}
Expand Down
7 changes: 5 additions & 2 deletions lib/police/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ help.usage = [
'',

' --force, -f Continue running even if errors are encountered',
' --keywords, -k Edit & update keywords in package.json',
' --packages, -p Edit & update packages in package.json ',
' --edit, -e Edit all the fields in package.json',
' --add, -a Add missing fields to package.json',
' --update, -t Update packages in package.json ',
'',
' --destroy, -d Destroys exisiting authentication',
' --conf [FILE] Sets the configuraiton file to be used',
'',
' --version, -v Displays version',
' --help, -h Displays help and usage',
''
Expand Down

0 comments on commit b2f87d0

Please sign in to comment.