command line completion in GlassFish

"GlassFish ":https://glassfish.dev.java.net/ has powerful command line interface in the form of asadmin. I used the following technique to have the bash shell autocomplete the asadmin commands and options .

1. create the directory (if it doesnt exist already)



mkdir -p /etc/bash_completion.d/

2. create the file /etc/bash_completion.d/asadmin with the following contents



_asadmin()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=`cat /etc/bash_completion.d/commands.txt`
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _asadmin asadmin

3. download and copy the "file commands.txt ":http://blogs.sun.com/harsha/resource/commands.txt to /etc/bash_completion.d/

4. source the above script into your current bash shell



source /etc/bash_completion.d/asadmin

Now say you want to start the domain in debug mode, press

asadmin sta[TAB]do[TAB] --deb[TAB]
, you can see autocompletion in action.

I used "this helpful document ":http://www.debian-administration.org/articles/317 in trying out this. The file commands.txt was generated from the "file CLIDescriptor ":http://fisheye5.cenqua.com/browse/glassfish/admin-cli/commands/src/java/com/sun/enterprise/cli/commands/CLIDescriptor.xml?r=MAIN .

Comments:

This is cool!

It even displays a list of available options if you tab twice.

eg.

./asadmin create-domain --admin[tab][tab] --adminpassword --adminport --adminuser

Do you know if this feature can be added to "asadmin" script?

Thanks!!

Posted by Jane Young on September 20, 2006 at 09:31 AM IST #

Very cool! Could this be done automatically as part of GlassFish installation, so that we don't need to worry about keeping the commands.txt uptodate? I shall send a mail to dev AT glassfish.

Posted by Sivakumar Thyagarajan on September 20, 2006 at 09:48 AM IST #

Yes, I think if the file commands.txt (something like that) is bundled with glassfish, and the asadmin script souces the autocompletion script, it could be automatic (provided the user is using bash). We have to try this out first.

Posted by Harsha R A on September 20, 2006 at 09:52 AM IST #

This will save much time and energy. Can some thing be done for dotted name syntax of set and get commands?

Posted by sankar on September 20, 2006 at 10:20 AM IST #

Could we get the equivalent script porting the same functionality to zsh? :o)

Posted by Cyril Bouteille on September 20, 2006 at 02:29 PM IST #

Thanks for the suggestion Cyril. It is even easier in zsh. Just past the following into your ~/.zshrc
function commandlist { reply=(`cat ~/.asadmin-options`); }
compctl -K commandlist asadmin
set COMPLETE_ALIASES
and copy the commands.txt into
~/.asadmin-options

simple!

Posted by Harsha R A on September 20, 2006 at 02:54 PM IST #

How can I get the callflow monitoring data into my file using asadmin utility?

Posted by sandhya on July 22, 2008 at 10:47 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

harsha

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today