PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/scalate-tool/src/main/scala/org/fusesource/scalate/tool/ScalateMain.scala

http://github.com/scalate/scalate
Scala | 76 lines | 43 code | 15 blank | 18 comment | 0 complexity | ed196809698b73cd91ad93b7cdbaab22 MD5 | raw file
 1/**
 2 * Copyright (C) 2009-2011 the original author or authors.
 3 * See the notice.md file distributed with this work for additional
 4 * information regarding copyright ownership.
 5 *
 6 * Licensed under the Apache License, Version 2.0 (the "License");
 7 * you may not use this file except in compliance with the License.
 8 * You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.fusesource.scalate.tool
19
20import org.fusesource.scalate.util.IOUtil
21
22import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
23import org.apache.karaf.shell.console.Main
24import org.apache.karaf.shell.console.jline.Console
25import jline.Terminal
26import java.io.{PrintStream, InputStream}
27import org.fusesource.jansi.Ansi
28import org.apache.felix.service.command.CommandSession
29import org.apache.felix.gogo.runtime.CommandProcessorImpl
30
31object ScalateMain {
32  def main(args: Array[String]) = {
33    Ansi.ansi()
34    new ScalateMain().run(args)
35  }
36
37  // Some ANSI helpers...
38  def ANSI(value:Any) =  "\u001B["+value+"m"
39  val BOLD =  ANSI(1)
40  val RESET = ANSI(0)
41}
42
43@command(scope = "scalate", name = "scalate", description = "Executes a scalate command interpreter")
44class ScalateMain extends Main with Action {
45  import ScalateMain._
46
47  setUser("me")
48  setApplication("scalate")
49
50  var debug = false
51
52  override def getDiscoveryResource = "META-INF/services/org.fusesource.scalate/commands.index"
53
54  override def isMultiScopeMode() = false
55
56
57  override def createConsole(commandProcessor: CommandProcessorImpl, in: InputStream, out: PrintStream, err: PrintStream, terminal: Terminal) = {
58    new Console(commandProcessor, in, out, err, terminal, null) {
59      protected override def getPrompt = BOLD+"scalate> "+RESET
60      protected override def welcome = {
61         session.getConsole().println(IOUtil.loadText(getClass().getResourceAsStream("banner.txt")))
62      }
63      protected override def setSessionProperties = {}
64    }
65  }
66
67  @argument(name = "args", description = "scalate sub command arguments", multiValued=true)
68  var args = Array[String]()
69
70  def execute(session: CommandSession): AnyRef = {
71    run(session, args)
72    null
73  }
74
75
76}