/* Copyright 2016 Samsung Electronics Co., LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gearvrf.debug;

import java.util.List;

import javax.script.ScriptEngine;

import org.gearvrf.GVRContext;
import org.gearvrf.debug.cli.Command;
import org.gearvrf.debug.cli.HelpCommandHandler;
import org.gearvrf.debug.cli.Shell;
import org.gearvrf.debug.cli.ShellDependent;
import org.gearvrf.script.GVRScriptManager;

/**
 * Shell commands for GVRf debug console.
 */
public class ShellCommandHandler implements ShellDependent {
    protected Shell mShell;
    protected GVRContext mGVRContext;
    protected HelpCommandHandler mHelpHandler = new HelpCommandHandler();

    protected ScriptHandler mScriptHandler;
    protected List<String> mSavedPath;

    public ShellCommandHandler(GVRContext gvrContext) {
        mGVRContext = gvrContext;
    }

    @Command
    public void lua() {
        enterLanguage(GVRScriptManager.LANG_LUA);
    }

    @Command
    public void js() {
        enterLanguage(GVRScriptManager.LANG_JAVASCRIPT);
    }

    private void enterLanguage(String language) {
        ScriptEngine engine = mGVRContext.getScriptManager().getEngine(language);

        if (engine == null) {
            mShell.getOutputConverter().convertOutput("Cannot find the language engine for " + language);
            return;
        }

        mScriptHandler = new ScriptHandler(mGVRContext, language, engine);
        mShell.setLineProcessor(mScriptHandler);
    }

    @Command
    public Object help() {
        return mHelpHandler.help();
    }

    @Command
    public void exit() {
        // empty
    }

    @Override
    public void cliSetShell(Shell theShell) {
        mShell = theShell;
        mHelpHandler.cliSetShell(mShell);
    }
}

@@ -721,16 +721,47 @@
 ontext;%0A
+import org.gearvrf.GVRVersion;%0A
 import o
@@ -1422,20 +1422,22 @@
  public 
-void
+Object
  lua() %7B
@@ -1437,32 +1437,39 @@
 lua() %7B%0A        
+return 
 enterLanguage(GV
@@ -1525,20 +1525,22 @@
  public 
-void
+Object
  js() %7B%0A
@@ -1547,16 +1547,23 @@
         
+return 
 enterLan
@@ -1622,20 +1622,22 @@
 private 
-void
+Object
  enterLa
@@ -1791,50 +1791,15 @@
     
-mShell.getOutputConverter().convertOutput(
+return 
 %22Can
@@ -1847,29 +1847,8 @@
 uage
-);%0A            return
 ;%0A  
@@ -1979,16 +1979,123 @@
 andler);
+%0A%0A        return null;%0A    %7D%0A%0A    @Command%0A    public Object version() %7B%0A        return GVRVersion.CURRENT;
 %0A    %7D%0A%0A

Add version command