kopia lustrzana https://github.com/c9/core
Merge pull request +12936 from c9/pull/core/272
Added CLI exec commandpull/284/head
commit
3e8757b251
|
@ -80,6 +80,10 @@ return [
|
||||||
packagePath: "./c9.cli.open/open",
|
packagePath: "./c9.cli.open/open",
|
||||||
platform: process.platform
|
platform: process.platform
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
packagePath: "./c9.cli.exec/exec",
|
||||||
|
platform: process.platform
|
||||||
|
},
|
||||||
{
|
{
|
||||||
packagePath: "./c9.cli.open/restart",
|
packagePath: "./c9.cli.open/restart",
|
||||||
platform: process.platform
|
platform: process.platform
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
main.consumes = [
|
main.consumes = [
|
||||||
"Plugin", "bridge", "tabManager", "panels", "tree.favorites", "tree",
|
"Plugin", "bridge", "tabManager", "panels", "tree.favorites", "tree",
|
||||||
"fs", "preferences", "settings", "c9"
|
"fs", "preferences", "settings", "c9", "commands"
|
||||||
];
|
];
|
||||||
main.provides = ["bridge.commands"];
|
main.provides = ["bridge.commands"];
|
||||||
return main;
|
return main;
|
||||||
|
@ -18,6 +18,7 @@ define(function(require, exports, module) {
|
||||||
var fs = imports.fs;
|
var fs = imports.fs;
|
||||||
var c9 = imports.c9;
|
var c9 = imports.c9;
|
||||||
var prefs = imports.preferences;
|
var prefs = imports.preferences;
|
||||||
|
var commands = imports.commands;
|
||||||
|
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
|
|
||||||
|
@ -36,6 +37,9 @@ define(function(require, exports, module) {
|
||||||
case "open":
|
case "open":
|
||||||
open(message, e.respond);
|
open(message, e.respond);
|
||||||
break;
|
break;
|
||||||
|
case "exec":
|
||||||
|
exec(message, e.respond);
|
||||||
|
break;
|
||||||
case "pipe":
|
case "pipe":
|
||||||
createPipe(message, e.respond);
|
createPipe(message, e.respond);
|
||||||
break;
|
break;
|
||||||
|
@ -173,6 +177,12 @@ define(function(require, exports, module) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exec(message, callback) {
|
||||||
|
var result = commands.exec(message.command, message.args);
|
||||||
|
var err = result ? null : "command failed";
|
||||||
|
callback(err, result);
|
||||||
|
}
|
||||||
|
|
||||||
/***** Lifecycle *****/
|
/***** Lifecycle *****/
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
define(function(require, exports, module) {
|
||||||
|
main.consumes = ["Plugin", "cli_commands", "bridge.client"];
|
||||||
|
main.provides = ["exec"];
|
||||||
|
return main;
|
||||||
|
|
||||||
|
function main(options, imports, register) {
|
||||||
|
var Plugin = imports.Plugin;
|
||||||
|
var cmd = imports.cli_commands;
|
||||||
|
var bridge = imports["bridge.client"];
|
||||||
|
|
||||||
|
/***** Initialization *****/
|
||||||
|
|
||||||
|
var plugin = new Plugin("Ajax.org", main.consumes);
|
||||||
|
// var emit = plugin.getEmitter();
|
||||||
|
|
||||||
|
var loaded;
|
||||||
|
function load(){
|
||||||
|
if (loaded) return;
|
||||||
|
loaded = true;
|
||||||
|
|
||||||
|
cmd.addCommand({
|
||||||
|
name: "exec",
|
||||||
|
info: " Executes remote c9 commands.",
|
||||||
|
usage: "<command> [argument 1] [argument 2] ... [argument n]",
|
||||||
|
check: function(argv) {
|
||||||
|
if (argv._.length < 2)
|
||||||
|
throw new Error("Missing command");
|
||||||
|
},
|
||||||
|
options: {},
|
||||||
|
exec: function(argv) {
|
||||||
|
exec(
|
||||||
|
argv._[1],
|
||||||
|
argv._.slice(2),
|
||||||
|
function(){});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** Methods *****/
|
||||||
|
|
||||||
|
function exec(command, args, callback) {
|
||||||
|
args.unshift(process.cwd());
|
||||||
|
var message = {
|
||||||
|
type: "exec",
|
||||||
|
command: command,
|
||||||
|
args: args
|
||||||
|
};
|
||||||
|
|
||||||
|
bridge.send(message, function cb(err, response) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response !== true)
|
||||||
|
console.log("Could not execute", command);
|
||||||
|
|
||||||
|
process.exit(); // I don't get why this is needed
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** Lifecycle *****/
|
||||||
|
|
||||||
|
plugin.on("load", function(){
|
||||||
|
load();
|
||||||
|
});
|
||||||
|
plugin.on("enable", function(){
|
||||||
|
|
||||||
|
});
|
||||||
|
plugin.on("disable", function(){
|
||||||
|
|
||||||
|
});
|
||||||
|
plugin.on("unload", function(){
|
||||||
|
loaded = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
/***** Register and define API *****/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds or lists files and/or lines based on their filename or contents
|
||||||
|
**/
|
||||||
|
plugin.freezePublicAPI({
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
exec: exec
|
||||||
|
});
|
||||||
|
|
||||||
|
register(null, {
|
||||||
|
exec: plugin
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
Ładowanie…
Reference in New Issue