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":
open(message, e.respond);
break;
case "pipe":
createPipe(message, e.respond);
break;
case "pipeData":
updatePipe(message, e.respond);
break;
case "pipeClosed":
closePipe(message, e.respond);
break;
case "ping":
e.respond(null, true);
break;
@ -66,6 +75,32 @@ define(function(require, exports, module) {
}
/***** 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) {
var i = -1;

Wyświetl plik

@ -11,6 +11,8 @@ define(function(require, exports, module) {
var fs = require("fs");
var PATH = require("path");
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder("utf8");
/***** Initialization *****/
@ -25,19 +27,28 @@ define(function(require, exports, module) {
cmd.addCommand({
name: "open",
info: " Opens a file or directory.",
usage: "[--wait] <path>",
usage: "[--wait] [--pipe] [--stream] <path>",
options: {
"wait": {
description: "Wait until the file(s) are closed",
"default": false,
"boolean": true
},
"pipe": {
description: "Pipe data from a command into c9",
"default": false,
"boolean": true
}
},
check: function(argv) {
if (argv._.length < 2 && !argv["path"])
if (argv._.length < 2 && !argv["path"] && !argv.pipe)
throw new Error("Missing path");
},
exec: function(argv) {
if(argv.pipe) {
openWithPipe(function(){});
return;
}
open(
argv._.slice(1), // Remove "open" from the paths
argv.wait,
@ -49,6 +60,7 @@ define(function(require, exports, module) {
/***** Methods *****/
function open(paths, wait, callback) {
try {
paths = paths.map(function(path) {
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) {
if (options.platform == "darwin") {
proc.spawn("open", {