2015-02-10 19:41:24 +00:00
|
|
|
define(function(require, exports, module) {
|
|
|
|
main.consumes = ["Plugin", "cli_commands", "workspace"];
|
|
|
|
main.provides = ["cli"];
|
|
|
|
return main;
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var Plugin = imports.Plugin;
|
|
|
|
var cmd = imports.cli_commands;
|
|
|
|
|
2015-05-01 02:34:40 +00:00
|
|
|
var fs = require("fs");
|
|
|
|
var resolve = require("path").resolve;
|
|
|
|
|
2015-02-10 19:41:24 +00:00
|
|
|
var optimist;
|
|
|
|
|
|
|
|
/***** Initialization *****/
|
|
|
|
|
|
|
|
var plugin = new Plugin("Ajax.org", main.consumes);
|
|
|
|
// var emit = plugin.getEmitter();
|
|
|
|
|
|
|
|
/***** Methods *****/
|
|
|
|
|
|
|
|
function start(){
|
|
|
|
var commands = cmd.commands;
|
|
|
|
var module;
|
|
|
|
var argv;
|
|
|
|
|
2015-05-01 02:34:40 +00:00
|
|
|
process.argv.slice(2).some(function(n) {
|
2015-02-10 19:41:24 +00:00
|
|
|
if (!n.match(/^[-\/]/) && n != "node") {
|
|
|
|
module = n;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2015-05-01 02:34:40 +00:00
|
|
|
if (!commands[module] && process.argv.length > 2) {
|
|
|
|
for (var i = 2; i < process.argv.length; i++) {
|
|
|
|
if (process.argv[i].charAt(0) == "-") continue;
|
|
|
|
var path = resolve(process.argv[i]);
|
|
|
|
if (fs.existsSync(path)) {
|
|
|
|
process.argv.splice(2, 0, "open");
|
|
|
|
module = "open";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 19:41:24 +00:00
|
|
|
optimist = require('optimist');
|
|
|
|
|
|
|
|
if (!module || !commands[module]) {
|
2015-06-04 08:03:20 +00:00
|
|
|
if (process.argv.indexOf("--version") != -1) {
|
|
|
|
console.log(require("../../package.json").version);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2015-02-10 19:41:24 +00:00
|
|
|
argv = optimist
|
|
|
|
.usage("The Cloud9 CLI.\nUsage: c9 [--verbose] <command> [<args>]\n\n"
|
|
|
|
+ "The most commonly used c9 commands are:\n"
|
|
|
|
+ Object.keys(commands).map(function(name) {
|
|
|
|
var cmd = commands[name];
|
|
|
|
return " " + cmd.name + " " + cmd.info;
|
|
|
|
}).join("\n")
|
|
|
|
)
|
|
|
|
.options({
|
|
|
|
verbose: {
|
|
|
|
alias: "v",
|
|
|
|
description: "Output more information",
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.check(function(){
|
|
|
|
throw new Error("See 'c9 <command> --help' for more information on a specific command.");
|
|
|
|
})
|
|
|
|
.argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
var def = commands[module];
|
|
|
|
def.options.help = {
|
|
|
|
alias: "h",
|
|
|
|
description: "Output help information"
|
|
|
|
};
|
|
|
|
|
|
|
|
argv = optimist
|
|
|
|
.usage("The Cloud9 CLI.\nUsage: c9 " + module + " [--help] " + def.usage)
|
|
|
|
.options(def.options);
|
2015-05-03 00:18:05 +00:00
|
|
|
|
|
|
|
if (argv.argv.help)
|
2015-05-02 23:35:04 +00:00
|
|
|
argv = argv.check(function(){
|
|
|
|
if (argv.help)
|
|
|
|
throw new Error("Help Requested");
|
|
|
|
});
|
2015-02-10 19:41:24 +00:00
|
|
|
if (def.check)
|
|
|
|
argv = argv.check(def.check);
|
|
|
|
argv = argv.argv;
|
|
|
|
|
|
|
|
cmd.exec(module, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Lifecycle *****/
|
|
|
|
|
|
|
|
plugin.on("load", function(){
|
|
|
|
});
|
|
|
|
plugin.on("unload", function(){
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Register and define API *****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds or lists files and/or lines based on their filename or contents
|
|
|
|
**/
|
|
|
|
plugin.freezePublicAPI({
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
start: start
|
|
|
|
});
|
|
|
|
|
|
|
|
register(null, {
|
|
|
|
cli: plugin
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//require("node-optimist");
|