Wiki
Clone wikiGroovy Cmd / Home
Welcome
Welcome to Groovy Cmd Wiki page. This is a little framework for creating simple cli programms. Using it you just need to extends Cmd class and write your own cli methods.
Your methods must сomply with the following terms:
- Return type should be
boolean
; - Method's name should starts with do_ prefix;
- It has to have only one argument of type String[];
- Presence of @Description annotation is optional.
Example:
@Description( brief='short description', full='full description' ) boolean do_MyMethod(String[] args) { // your implementation }
After executing your program, you can run your command by typing its name without prefix do_:
cmd:> MyMethod
Unfortunately, you can not move text cursor by the keyboard arrows, because of peculiarity of Java (accordingly, Groovy too) console I/O. That's why I didn't implement:
- History scrolling by up/down arrows;
- Tab autocompletion;
- And etc...
The workaround - is to use Java libraries, which include C/C++ wrapped code for working with console...but, in my opinion, it is too "expensive" for simple Cli framework and, also, destructs a portability of your console scripts.
How was implemented commands history in Groovy Cmd see in links.
Links
- Get started
- Using Groovy Merger
- Immediate execution
- Commands list
- Localization
- Using shell
- Commands history
Installation
For getting framework from Bitbucket type the following command in shell:
$ git clone https://xxlabaza@bitbucket.org/xxlabaza/groovy-cmd.git
Then, enter in created directory:
$ cd groovy-cmd
There are place the groovy files:
File name | Short description |
---|---|
Cmd.groovy | Abstract class, that contains all framework logic and you just need to extend it for work. Furthermore it contains @Description annotation for methods description |
Shell.groovy | It's not a part of Cmd, but very useful class with only one static method for running shell commands |
Updated