added pipe command to c9.cli.open

pull/272/head
Shannon Duncan 2016-02-12 19:09:59 +00:00 zatwierdzone przez nightwing
rodzic 30df2c6cba
commit 1d536ff6c4
2 zmienionych plików z 69 dodań i 2 usunięć

Wyświetl plik

@ -36,6 +36,15 @@ define(function(require, exports, module) {
case "open": case "open":
open(message, e.respond); open(message, e.respond);
break; break;
case "pipe":
createPipe(message, e.respond);
break;
case "pipeData":
updatePipe(message, e.respond);
break;
case "pipeClosed":
closePipe(message, e.respond);
break;
case "ping": case "ping":
e.respond(null, true); e.respond(null, true);
break; break;
@ -66,6 +75,32 @@ define(function(require, exports, module) {
} }
/***** Methods *****/ /***** Methods *****/
var pipeTab;
var pipeClosed = true;
function createPipe(message, callback) {
if(pipeClosed)
{
tabManager.once("ready", function(){
tabManager.open({focus:true, editorType: "ace"}, function(err, tab){
pipeTab = tab;
pipeTab.document.value += "";
pipeClosed = false;
});
});
}
}
function updatePipe(message, callback){
console.log(message.data);
pipeTab.document.value += message.data.toString();;
}
function closePipe(message, callback){
pipeClosed = true;
}
function open(message, callback) { function open(message, callback) {
var i = -1; var i = -1;

Wyświetl plik

@ -11,6 +11,8 @@ define(function(require, exports, module) {
var fs = require("fs"); var fs = require("fs");
var PATH = require("path"); var PATH = require("path");
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder("utf8");
/***** Initialization *****/ /***** Initialization *****/
@ -25,19 +27,28 @@ define(function(require, exports, module) {
cmd.addCommand({ cmd.addCommand({
name: "open", name: "open",
info: " Opens a file or directory.", info: " Opens a file or directory.",
usage: "[--wait] <path>", usage: "[--wait] [--pipe] [--stream] <path>",
options: { options: {
"wait": { "wait": {
description: "Wait until the file(s) are closed", description: "Wait until the file(s) are closed",
"default": false, "default": false,
"boolean": true "boolean": true
},
"pipe": {
description: "Pipe data from a command into c9",
"default": false,
"boolean": true
} }
}, },
check: function(argv) { check: function(argv) {
if (argv._.length < 2 && !argv["path"]) if (argv._.length < 2 && !argv["path"] && !argv.pipe)
throw new Error("Missing path"); throw new Error("Missing path");
}, },
exec: function(argv) { exec: function(argv) {
if(argv.pipe) {
openWithPipe(function(){});
return;
}
open( open(
argv._.slice(1), // Remove "open" from the paths argv._.slice(1), // Remove "open" from the paths
argv.wait, argv.wait,
@ -49,6 +60,7 @@ define(function(require, exports, module) {
/***** Methods *****/ /***** Methods *****/
function open(paths, wait, callback) { function open(paths, wait, callback) {
try { try {
paths = paths.map(function(path) { paths = paths.map(function(path) {
var isDir = fs.existsSync(path) && fs.statSync(path).isDirectory(); var isDir = fs.existsSync(path) && fs.statSync(path).isDirectory();
@ -126,6 +138,26 @@ define(function(require, exports, module) {
}); });
} }
function openWithPipe(callback) {
var stdin = process.openStdin();
var tab;
bridge.send({ type: "pipe" }, function(){});
stdin.on("data", function(chunk){
var textChunk = decoder.write(chunk);
bridge.send({ type: "pipeData", data: textChunk}, function(err, message) {
});
});
stdin.on("end", function(){
bridge.send({ type: "pipeClosed"}, function(err, message) {
process.exit(40);
});
});
}
function startCloud9Local(opts, callback) { function startCloud9Local(opts, callback) {
if (options.platform == "darwin") { if (options.platform == "darwin") {
proc.spawn("open", { proc.spawn("open", {