Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Groovy command line


May 14, 2021 Groovy


Table of contents


Groovy shell, called groovysh, can be easily used to evaluate groovy expressions, define classes, and run simple programs. When Groovy is installed, the command line shell is installed.

Here are the command line options available in Groovy:

Command-line arguments Name Describe
-C --color [= FLAG] Enable or disable the use of ANSI colors
-D --define = NAME = VALUE Define system properties
-T --terminal = TYPE Specify the terminal TYPE to use
-V --version The display version
-classpath Specify where to find the class file - it must be the first argument
-cp --classpath Alias "-classpath"
-d --debug --debug enables debug output
-e --evaluate=arg When you start an interactive session, evaluate the option metrics
-H --help This help message is displayed
-q --quiet Do not allow extra output
-v --verbose Enable detailed output

The following snapshot shows a simple example of an expression executed in the Groovy shell. In the following example, we just print "Hello World" in the groovy shell.

Groovy command line

Classes and functions

It is easy to define a class under the command prompt, create a new object, and call the methods on the class. od. n the following example, we use a simple method to create a simple Task class. I n the command prompt itself, we are creating a class object and calling the Display method.

Groovy command line

It is easy to define and call a method in the command prompt. it. lso note that we've included an argument called a name and then replaced it with an actual value when the Display method is called. T he following example shows how to implement it.

Groovy command line

Command

Shell has many different commands that provide rich access to the shell environment. Here's their list and what they do.

Command The command description
:help (:h) this help message is displayed
? (:? Alias:: Help
:exit (:x) Exit shell
:quit (:q) Alias::exit
import (i) Import a class into the namespace
:display (:d) shows the current buffer
:clear (c) Clear the buffer and reset the prompt counter
:show (:S) displays variables, classes, or imports
:inspect (:n) Use the GUI object browser to examine the variable or the last result
:purge (:p) clear variables, classes, imports, or preferences
:edit (:e) Edit the current buffer
:load (l) Load the file or URL into the buffer
. (:.) Alias::load
.save (:s) Save the current buffer to the file
.record (:r) Record the current session to a file
:alias (a) Create an alias
:set Set (or list) preferences
:register (: rc) Register a new command using shell
:doc (:D) open a browser window that displays the parameters of the document
:history (:H) displays, manages, and recalls edit line history