Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

Commit

Permalink
Stash console.
Browse files Browse the repository at this point in the history
  • Loading branch information
jushi committed May 9, 2012
1 parent ee04626 commit cff6742
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 178 deletions.
95 changes: 0 additions & 95 deletions console/src/main/scala/com/github/zhongl/house/Closure.scala

This file was deleted.

Expand Up @@ -14,30 +14,16 @@
* limitations under the License.
*/

package com.github.zhongl.house
package com.github.zhongl.house.cli;

import org.scalatest.matchers.ShouldMatchers
import org.scalatest.FunSuite
import collection.mutable.ListBuffer
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
*/
class ListMapByPatternTest extends FunSuite with ShouldMatchers {
test("Enviroment") {
val lines = ListBuffer.empty[String]
val enviroment = new Enviroment("PATH")
enviroment(null) { lines += _ }
lines.toList should contain("PATH = " + sys.env("PATH"))
}

test("Properties") {
val lines = ListBuffer.empty[String]
val properties = new Properites("os")
properties(null) { lines += _ }
lines.toList should contain("os.name = " + sys.props("os.name"))
}

@Retention(RetentionPolicy.RUNTIME)
public @interface Argument {
String name();
String description();
}


Expand Up @@ -14,18 +14,17 @@
* limitations under the License.
*/

package com.github.zhongl.house
package com.github.zhongl.house.cli;

import instrument.Instrumentation
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
*/
object ClosureExecutor extends App {
val klass = Class.forName("com.github.zhongl.house.Summary").asInstanceOf[Class[Closure]]
val method = klass.getMethod("apply", classOf[Instrumentation], classOf[String => Unit])
val instance = klass.newInstance()
val arguments = Seq(null, {x:String => println(x)}).asInstanceOf[Seq[AnyRef]]
method invoke(instance, arguments:_*)
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
String name();

String description();
}
65 changes: 65 additions & 0 deletions console/src/main/scala/com/github/zhongl/house/cli/Console.scala
@@ -0,0 +1,65 @@
/*
* Copyright 2012 zhongl
*
* 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 com.github.zhongl.house.cli

import java.io.PrintStream

/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
*/

object CommandLineParser {
def apply(out: PrintStream = System.out) = new CommandLineParser(out)
}

class CommandLineParser(out: PrintStream) {

def add(klass: Class[_]) {}

def parse(line: String) = _

trait Command

object Help {

@command(name = "help", description = "show help infomation of the command or all commands")
def apply(@argument(name = "command", description = "command name to show information")command: String = "*") {
command match {
case "*" => list()
case _ => usage(command)
}
}

private[this] def list() {
// TODO
}

private[this] def usage(command: String) {
// TODO
}
}

object Quit {

@command(name = "quit", description = "quit the console")
def apply() {
sys.exit()
}
}

}

29 changes: 29 additions & 0 deletions console/src/main/scala/com/github/zhongl/house/cli/Option.java
@@ -0,0 +1,29 @@
/*
* Copyright 2012 zhongl
*
* 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 com.github.zhongl.house.cli;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Option {
String[] name();
String description();
}
Expand Up @@ -16,14 +16,14 @@

package com.github.zhongl.house

import collection.mutable.ListBuffer
import annotation.target.field

/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
*/

trait OutputCollector extends Closure {
val lines = ListBuffer.empty[String]

def output(line: String) { lines += line }
package object cli {
type command = Command
type option = Option@field
type argument = Argument@field
}

This file was deleted.

1 change: 1 addition & 0 deletions project/Build.scala
Expand Up @@ -69,6 +69,7 @@ object Build extends sbt.Build {
lazy val consoleDependencies = Seq(
"asm" % "asm" % "3.3.1",
"asm" % "asm-commons" % "3.3.1",
"jline" % "jline" % "2.6",
"com.beust" % "jcommander" % "1.20",
"org.scala-lang" % "scala-library" % "2.9.2"
)
Expand Down

0 comments on commit cff6742

Please sign in to comment.