Nice! Did this inherently resolve https://issues.apache.org/jira/browse/KITTY-3?

On Jan 17, 2011, at 9:53 AM, [email protected] wrote:

> Author: pidster
> Date: Mon Jan 17 17:53:28 2011
> New Revision: 1060024
> 
> URL: http://svn.apache.org/viewvc?rev=1060024&view=rev
> Log:
> Use Commons CLI / CliBuilder and JLine
> 
> Modified:
>    incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy
>    incubator/kitty/trunk/src/main/java/org/apache/kitty/Main.groovy
> 
> Modified: incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy
> URL: 
> http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy?rev=1060024&r1=1060023&r2=1060024&view=diff
> ==============================================================================
> --- incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy 
> (original)
> +++ incubator/kitty/trunk/src/main/java/org/apache/kitty/CmdShell.groovy Mon 
> Jan 17 17:53:28 2011
> @@ -1,3 +1,4 @@
> +
> /*
>  * Licensed to the Apache Software Foundation (ASF) under one or more
>  * contributor license agreements.  See the NOTICE file distributed with
> @@ -15,11 +16,10 @@
>  * limitations under the License.
>  */
> 
> -
> package org.apache.kitty
> 
> -import java.io.BufferedReader
> -import java.io.InputStreamReader
> +import jline.ConsoleReader
> +import jline.History
> 
> import org.apache.kitty.client.Client
> import org.apache.kitty.utils.Constants
> @@ -38,13 +38,16 @@ import org.apache.kitty.utils.Help
>  */
> class CmdShell {
> 
> -     def static final PROMPT = "kitty>"
> +     def static final PROMPT = "kitty> "
> +
>       static String HOST = "localhost"
> +
>       static String PORT = "9024"
> +
>       static Client client
> +
>       def static remote
> -     static InputStreamReader inReader;
> -     static BufferedReader bReader;
> +
>       static commands = [
>               "help",
>               "connect",
> @@ -74,18 +77,33 @@ class CmdShell {
>       }
> 
>       static startShell() {
> -             def input
> -             inReader = new InputStreamReader(System.in)
> -             bReader = new BufferedReader(inReader)
> +
>               client = new Client()
> 
> -             while (!(input.equals("exit"))) {
> -                     print PROMPT
> -                     input = getUserInput()
> -                     inputHandler(input)
> +             def history = new History()
> +             def reader = new ConsoleReader()
> +
> +             reader.setBellEnabled(false)
> +             reader.setUseHistory(true)
> +             reader.setDefaultPrompt(PROMPT)
> +             reader.setHistory(history)
> +
> +             LOOP: while (true) {
> +                     def input = reader.readLine().trim()
> +
> +                     if (input.length() == 0)
> +                             continue
> +
> +                     if (["exit", "quit"].contains(input.tokenize().get(0)))
> +                             break LOOP
> +
> +                     try {
> +                             inputHandler(input)
> +                     }
> +                     catch (Exception e) {
> +                             println e.getMessage()
> +                     }
>               }
> -             inReader.close()
> -             bReader.close()
>       }
> 
>       static inputHandler(String input) {
> @@ -97,7 +115,7 @@ class CmdShell {
>                       input = params[0]
>               }
>               else {
> -                     params = {input}
> +                     params = { input }
>               }
> 
>               if (commands.contains(input)) {
> @@ -199,12 +217,6 @@ class CmdShell {
>               }
>       }
> 
> -     static String getUserInput() {
> -             def userInput
> -             userInput = bReader.readLine()
> -             return userInput;
> -     }
> -
>       static cmdHelp() {
>               Help h = new Help()
>               println h.toString()
> 
> Modified: incubator/kitty/trunk/src/main/java/org/apache/kitty/Main.groovy
> URL: 
> http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/java/org/apache/kitty/Main.groovy?rev=1060024&r1=1060023&r2=1060024&view=diff
> ==============================================================================
> --- incubator/kitty/trunk/src/main/java/org/apache/kitty/Main.groovy 
> (original)
> +++ incubator/kitty/trunk/src/main/java/org/apache/kitty/Main.groovy Mon Jan 
> 17 17:53:28 2011
> @@ -1,42 +1,58 @@
> /*
> -* Licensed to the Apache Software Foundation (ASF) under one or more
> -* contributor license agreements.  See the NOTICE file distributed with
> -* this work for additional information regarding copyright ownership.
> -* The ASF licenses this file to You 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.
> -*/
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You 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.apache.kitty
> 
> /**
> -* <pre>
> -* <b>Description</b>
> -* <p>
> -* This is the entry point to the remote management framework.
> -* </p>
> -* </pre>
> -*
> -* @version $Id$
> -*
> -*/
> + * <pre>
> + * <b>Description</b>
> + * <p>
> + * This is the entry point to the remote management framework.
> + * </p>
> + * </pre>
> + *
> + * @version $Id$
> + *
> + */
> class Main {
> -     
> -     def config
> -     
> -     public init()
> -     {
> -             config = new ConfigSlurper().parse(new 
> File('kittyConfig.groovy')).toString()
> -             //TODO
> -     }
> 
> +     static final String KITTY_USAGE = "java -jar apache-kitty.jar <arg>"
> +
> +     static main(args) {
> +
> +             def cli = new CliBuilder(usage: KITTY_USAGE)
> +             cli.h(longOpt: 'help', 'Show help')
> +             cli.i(longOpt: 'interactive', 'Launch in an interactive prompt 
> (default)')
> +             cli.s(longOpt: 'script', 'Launch inline for scripted access')
> +
> +             /*
> +              cli.d(longOpt: 'debug', 'Display debug information on output')
> +              cli.q(longOpt: 'quiet', 'Restrict output to bare minimum')
> +              cli.v(longOpt: 'verbose', 'Display extra information on 
> output')
> +              */
> +
> +             def opt = cli.parse(args)
> +
> +             if (opt?.h) {
> +                     cli.usage()
> +                     return
> +             }
> +
> +             CmdShell.startShell()
> +     }
> }
> 
> 

Reply via email to