/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. */
  18. package org.fusesource.scalate.tool
  19. import org.fusesource.scalate.util.IOUtil
  20. import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
  21. import org.apache.karaf.shell.console.Main
  22. import org.apache.karaf.shell.console.jline.Console
  23. import jline.Terminal
  24. import java.io.{PrintStream, InputStream}
  25. import org.fusesource.jansi.Ansi
  26. import org.apache.felix.service.command.CommandSession
  27. import org.apache.felix.gogo.runtime.CommandProcessorImpl
  28. object ScalateMain {
  29. def main(args: Array[String]) = {
  30. Ansi.ansi()
  31. new ScalateMain().run(args)
  32. }
  33. // Some ANSI helpers...
  34. def ANSI(value:Any) = "\u001B["+value+"m"
  35. val BOLD = ANSI(1)
  36. val RESET = ANSI(0)
  37. }
  38. @command(scope = "scalate", name = "scalate", description = "Executes a scalate command interpreter")
  39. class ScalateMain extends Main with Action {
  40. import ScalateMain._
  41. setUser("me")
  42. setApplication("scalate")
  43. var debug = false
  44. override def getDiscoveryResource = "META-INF/services/org.fusesource.scalate/commands.index"
  45. override def isMultiScopeMode() = false
  46. override def createConsole(commandProcessor: CommandProcessorImpl, in: InputStream, out: PrintStream, err: PrintStream, terminal: Terminal) = {
  47. new Console(commandProcessor, in, out, err, terminal, null) {
  48. protected override def getPrompt = BOLD+"scalate> "+RESET
  49. protected override def welcome = {
  50. session.getConsole().println(IOUtil.loadText(getClass().getResourceAsStream("banner.txt")))
  51. }
  52. protected override def setSessionProperties = {}
  53. }
  54. }
  55. @argument(name = "args", description = "scalate sub command arguments", multiValued=true)
  56. var args = Array[String]()
  57. def execute(session: CommandSession): AnyRef = {
  58. run(session, args)
  59. null
  60. }
  61. }