Browse Source

Adding CLI edit command

Josh Engebretson 10 years ago
parent
commit
a7e0fbf1ca

+ 1 - 1
CLI/atomic-cli-mac/index.js

@@ -1,7 +1,7 @@
 
 var PLATFORM_DATA_DIR = __dirname + "/data";
 var ATOMICTOOL_BIN = __dirname + "/bin/AtomicTool";
-var EDITOR_APPLICATION = __dirname + "/bin/editor/AtomicEditor.app";
+var EDITOR_APPLICATION = __dirname + "/bin/editor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
 var EDITOR_DATA_DIR = __dirname + "/bin/editor/AtomicEditor.app/Contents/Resources";
 
 exports.PLATFORM_DATA_DIR = PLATFORM_DATA_DIR;

+ 8 - 2
CLI/atomic-cli/cli.js

@@ -109,6 +109,14 @@ cmd.setDefaults({action: function (args) {
             server.start();
 }});
 
+var cmd = commands.addParser("editor", {help: "Starts the Atomic Editor and loads current project",
+    description: "Starts the Atomic Editor and loads current project.",
+    aliases: ["edit"]});
+cmd.setDefaults({action: function (args) {
+            cli.editor()
+}});
+
+
 // GO!
 if (process.argv.length > 2) {
     var args = parser.parseArgs();
@@ -116,5 +124,3 @@ if (process.argv.length > 2) {
 } else {
     parser.printHelp();
 }
-
-// spawn(cli.ATOMIC_TOOL_BIN, { stdio: 'inherit' });

+ 14 - 7
CLI/atomic-cli/index.js

@@ -9,18 +9,13 @@ var wrench = require("wrench");
 
 try {
   var platform_cli = require('atomic-cli-mac');
-  console.log(platform_cli);
 }
 catch (e) {
-
-  console.log(e);
 }
 
-
 var DATA_DIR = platform_cli.EDITOR_DATA_DIR;
-exports.DATA_DIR = DATA_DIR;
-
 var ATOMIC_TOOL_BIN = platform_cli.ATOMICTOOL_BIN;
+var EDITOR_APPLICATION = platform_cli.EDITOR_APPLICATION;
 
 var HTTP_PORT = 4000;
 var SOCKET_PORT = HTTP_PORT+1;
@@ -56,7 +51,6 @@ var exec = function (command, flags, opts) {
 };
 exports.exec = exec;
 
-
 var atomictool = function (flags, opts) {
     opts = opts || {};
     opts.windowsCmd = false;
@@ -67,6 +61,15 @@ var atomictool = function (flags, opts) {
 };
 exports.atomictool = atomictool
 
+var atomiceditor = function (flags, opts) {
+    opts = opts || {};
+    opts.detached = true;
+    opts.stdio = ["ignore", "ignore", "ignore"];
+    var child = spawn(EDITOR_APPLICATION, flags, opts);
+    child.unref();
+};
+exports.atomiceditor = atomiceditor
+
 exports.newProject = function (output) {
   return atomictool(["new", output], {output:true});
 };
@@ -79,6 +82,10 @@ exports.addPlatform = function (platform) {
   return atomictool(["platform-add", platform], {output:true});
 };
 
+exports.editor = function () {
+  return atomiceditor(["-project", process.cwd()], {output:true});
+};
+
 exports.run = function (platform, opts) {
     opts = opts || {};
     var debug = opts.debug;

+ 35 - 1
Source/AtomicEditor/Source/AEApplication.cpp

@@ -141,12 +141,47 @@ void AEApplication::Start()
         sceneProcess->Process();
         sceneProcess->Write();
     }
+
+    if (cmdLineProjectFile_.Length())
+    {
+        editor->LoadProject(cmdLineProjectFile_);
+    }
 }
 
 void AEApplication::Setup()
 {
     FileSystem* filesystem = GetSubsystem<FileSystem>();
 
+    const Vector<String>& arguments = GetArguments();
+
+    for (unsigned i = 0; i < arguments.Size(); ++i)
+    {
+        if (arguments[i].Length() > 1 && arguments[i][0] == '-')
+        {
+            String argument = arguments[i].Substring(1).ToLower();
+            String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
+
+            if (argument == "project" && value.Length())
+            {
+                Vector<String> projectFiles;
+                filesystem->ScanDir(projectFiles, value, "*.atomic", SCAN_FILES, false);
+                if (!projectFiles.Size())
+                {
+                    ErrorExit(ToString("No .atomic project file in %s", value.CString()));
+                    return;
+                }
+                else if (projectFiles.Size() > 1)
+                {
+                    ErrorExit(ToString("Multiple .atomic project files found in %s", value.CString()));
+                    return;
+                }
+
+                cmdLineProjectFile_ = value + "/" + projectFiles[0];
+
+            }
+        }
+    }
+
     engineParameters_["WindowTitle"] = "AtomicEditor";
     engineParameters_["WindowResizable"] = true;
     engineParameters_["FullScreen"] = false;
@@ -158,7 +193,6 @@ void AEApplication::Setup()
         engineParameters_["WindowHeight"] = prefs.windowHeight;
     }
 
-
 #ifdef __APPLE__
     engineParameters_["ResourcePrefixPath"] = "../Resources";
 #else

+ 2 - 0
Source/AtomicEditor/Source/AEApplication.h

@@ -28,6 +28,8 @@ public:
     virtual void Stop();
 
 private:
+
+    String cmdLineProjectFile_;
     
 };