Comparing version 1.1.5 to 1.1.6
@@ -11,2 +11,6 @@ (function() { | ||
Command = (function() { | ||
var RE_SQUOT; | ||
RE_SQUOT = /'/g; | ||
function Command(connection) { | ||
@@ -34,2 +38,11 @@ this.connection = connection; | ||
Command.prototype._escape = function(arg) { | ||
switch (typeof arg) { | ||
case 'number': | ||
return arg; | ||
default: | ||
return "'" + arg.toString().replace(RE_SQUOT, "'\"'\"'") + "'"; | ||
} | ||
}; | ||
return Command; | ||
@@ -36,0 +49,0 @@ |
@@ -11,4 +11,2 @@ (function() { | ||
ShellCommand = (function(_super) { | ||
var RE_SQUOT; | ||
__extends(ShellCommand, _super); | ||
@@ -20,7 +18,5 @@ | ||
RE_SQUOT = /'/g; | ||
ShellCommand.prototype.execute = function(command, callback) { | ||
if (Array.isArray(command)) { | ||
command = command.map(this._escapeArg).join(' '); | ||
command = command.map(this._escape).join(' '); | ||
} | ||
@@ -42,11 +38,2 @@ this.parser.readAscii(4, (function(_this) { | ||
ShellCommand.prototype._escapeArg = function(arg) { | ||
switch (typeof arg) { | ||
case 'number': | ||
return arg; | ||
default: | ||
return "'" + arg.toString().replace(RE_SQUOT, "'\"'\"'") + "'"; | ||
} | ||
}; | ||
return ShellCommand; | ||
@@ -53,0 +40,0 @@ |
@@ -13,3 +13,3 @@ (function() { | ||
StartActivityCommand = (function(_super) { | ||
var RE_ERROR; | ||
var EXTRA_TYPES, RE_ERROR; | ||
@@ -24,2 +24,13 @@ __extends(StartActivityCommand, _super); | ||
EXTRA_TYPES = { | ||
string: 's', | ||
"null": 'sn', | ||
bool: 'z', | ||
int: 'i', | ||
long: 'l', | ||
float: 'l', | ||
uri: 'u', | ||
component: 'cn' | ||
}; | ||
StartActivityCommand.prototype.execute = function(options, callback) { | ||
@@ -51,7 +62,10 @@ var args; | ||
args = []; | ||
if (options.extras) { | ||
args.push.apply(args, this._formatExtras(options.extras)); | ||
} | ||
if (options.action) { | ||
args.push("-a " + options.action); | ||
args.push('-a', this._escape(options.action)); | ||
} | ||
if (options.component) { | ||
args.push("-n " + options.component); | ||
args.push('-n', this._escape(options.component)); | ||
} | ||
@@ -61,2 +75,77 @@ return this._send("shell:am start " + (args.join(' '))); | ||
StartActivityCommand.prototype._formatExtras = function(extras) { | ||
if (!extras) { | ||
return []; | ||
} | ||
if (Array.isArray(extras)) { | ||
return extras.reduce((function(_this) { | ||
return function(all, extra) { | ||
return all.concat(_this._formatLongExtra(extra)); | ||
}; | ||
})(this), []); | ||
} else { | ||
return Object.keys(extras).reduce((function(_this) { | ||
return function(all, key) { | ||
return all.concat(_this._formatShortExtra(key, extras[key])); | ||
}; | ||
})(this), []); | ||
} | ||
}; | ||
StartActivityCommand.prototype._formatShortExtra = function(key, value) { | ||
var sugared; | ||
sugared = { | ||
key: key | ||
}; | ||
if (value === null) { | ||
sugared.type = 'null'; | ||
} else if (Array.isArray(value)) { | ||
throw new Error("Refusing to format array value '" + key + "' using short syntax; empty array would cause unpredictable results due to unknown type. Please use long syntax instead."); | ||
} else { | ||
switch (typeof value) { | ||
case 'string': | ||
sugared.type = 'string'; | ||
sugared.value = value; | ||
break; | ||
case 'boolean': | ||
sugared.type = 'bool'; | ||
sugared.value = value; | ||
break; | ||
case 'number': | ||
sugared.type = 'int'; | ||
sugared.value = value; | ||
break; | ||
case 'object': | ||
sugared = value; | ||
sugared.key = key; | ||
} | ||
} | ||
return this._formatLongExtra(sugared); | ||
}; | ||
StartActivityCommand.prototype._formatLongExtra = function(extra) { | ||
var args, type; | ||
args = []; | ||
if (!extra.type) { | ||
extra.type = 'string'; | ||
} | ||
type = EXTRA_TYPES[extra.type]; | ||
if (!type) { | ||
throw new Error("Unsupported type '" + extra.type + "' for extra '" + extra.key + "'"); | ||
} | ||
if (extra.type === 'null') { | ||
args.push("-e" + type); | ||
args.push(this._escape(extra.key)); | ||
} else if (Array.isArray(extra.value)) { | ||
args.push("-e" + type + "a"); | ||
args.push(this._escape(extra.key)); | ||
args.push(this._escape(extra.value.join(','))); | ||
} else { | ||
args.push("-e" + type); | ||
args.push(this._escape(extra.key)); | ||
args.push(this._escape(extra.value)); | ||
} | ||
return args; | ||
}; | ||
return StartActivityCommand; | ||
@@ -63,0 +152,0 @@ |
{ | ||
"name": "adbkit", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "A pure Node.js client for the Android Debug Bridge.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -483,2 +483,9 @@ # adbkit | ||
- **component** The component. | ||
- **extras** Any extra data. | ||
* When an `Array`, each item must be an `Object` the following properties: | ||
- **key** The key name. | ||
- **type** The type, which can be one of `'string'`, `'null'`, `'bool'`, `'int'`, `'long'`, `'float'`, `'uri'`, `'component'`. | ||
- **value** The value. Optional and unused if type is `'null'`. If an `Array`, type is automatically set to be an array of `<type>`. | ||
* When an `Object`, each key is treated as the key name. Simple values like `null`, `String`, `Boolean` and `Number` are type-mapped automatically (`Number` maps to `'int'`) and can be used as-is. For more complex types, like arrays and URIs, set the value to be an `Object` like in the Array syntax (see above), but leave out the `key` property. | ||
* **callback(err)** | ||
@@ -485,0 +492,0 @@ - **err** `null` when successful, `Error` otherwise. |
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
148677
2924
721