Comparing version 1.5.0 to 1.6.0
@@ -1,2 +0,2 @@ | ||
var Command, Option, Signature, parse, settings, state, _; | ||
var Command, Option, Signature, parse, settings, state, utils, _; | ||
@@ -17,2 +17,4 @@ _ = require('lodash'); | ||
utils = require('./utils'); | ||
module.exports = Command = (function() { | ||
@@ -56,2 +58,10 @@ function Command(options) { | ||
Command.prototype._checkElevation = function(callback) { | ||
if (this.root != null) { | ||
return utils.isElevated(callback); | ||
} else { | ||
return callback(null, true); | ||
} | ||
}; | ||
Command.prototype.execute = function(args, callback) { | ||
@@ -63,20 +73,28 @@ if (args == null) { | ||
return function(error, params) { | ||
var parsedOptions; | ||
if (error != null) { | ||
return typeof callback === "function" ? callback(error) : void 0; | ||
} | ||
parsedOptions = _this._parseOptions(args.options); | ||
return _this.applyPermissions(function(error) { | ||
return _this._checkElevation(function(error, isElevated) { | ||
var parsedOptions; | ||
if (error != null) { | ||
return typeof callback === "function" ? callback(error) : void 0; | ||
} | ||
try { | ||
_this.action(params, parsedOptions, callback); | ||
} catch (_error) { | ||
error = _error; | ||
return typeof callback === "function" ? callback(error) : void 0; | ||
if (_this.root && !isElevated) { | ||
return callback(new Error('You need admin privileges to run this command')); | ||
} | ||
if (_this.action.length < 3) { | ||
return typeof callback === "function" ? callback() : void 0; | ||
} | ||
parsedOptions = _this._parseOptions(args.options); | ||
return _this.applyPermissions(function(error) { | ||
if (error != null) { | ||
return typeof callback === "function" ? callback(error) : void 0; | ||
} | ||
try { | ||
_this.action(params, parsedOptions, callback); | ||
} catch (_error) { | ||
error = _error; | ||
return typeof callback === "function" ? callback(error) : void 0; | ||
} | ||
if (_this.action.length < 3) { | ||
return typeof callback === "function" ? callback() : void 0; | ||
} | ||
}); | ||
}); | ||
@@ -83,0 +101,0 @@ }; |
@@ -1,5 +0,9 @@ | ||
var stdin; | ||
var isElevated, stdin; | ||
stdin = require('get-stdin'); | ||
isElevated = require('is-elevated'); | ||
exports.getStdin = stdin; | ||
exports.isElevated = isElevated; |
{ | ||
"name": "capitano", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Powerful, non opitionated command line parser for serious applications", | ||
@@ -43,2 +43,3 @@ "main": "build/capitano.js", | ||
"get-stdin": "^4.0.1", | ||
"is-elevated": "^1.0.0", | ||
"lodash": "~2.4.1", | ||
@@ -45,0 +46,0 @@ "minimist": "~1.1.0", |
@@ -107,2 +107,6 @@ Capitano | ||
### root (boolean) | ||
If you specify this option to true, then the command will only be runnable by a user with admin privileges, or prefixed by `sudo`. | ||
## capitano.globalOption(options) | ||
@@ -144,2 +148,8 @@ | ||
This is also the command you need to use if you need to call a command from another command. For example: | ||
```coffee | ||
capitano.run('my other command --foo bar', callback) | ||
``` | ||
**Note:** `capitano.run` is a shorcut function for `capitano.execute(capitano.parse(argv), callback)`. You will usually use this function, however you can use `parse()` and `execute()` in particular situations when you need to differenciate between parsing and executing the commands. | ||
@@ -420,2 +430,6 @@ | ||
### 1.6.0 | ||
- Implement root property support. | ||
### 1.5.0 | ||
@@ -422,0 +436,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134501
34
740
505
6
2382
+ Addedis-elevated@^1.0.0
+ Addedis-admin@1.0.2(transitive)
+ Addedis-elevated@1.0.0(transitive)
+ Addedis-root@1.0.0(transitive)