Maintaining static variables over different command calls

22 views
Skip to first unread message

Harsh Kumar

unread,
May 22, 2013, 1:06:26 AM5/22/13
to crash...@googlegroups.com, Julien Viet
Hi,

I want to use the same variable across different commands.

Can I initialize it in the login.groovy script and make it available for every other command I write?
--
Sincerely
Harsh Kumar
-------------------------------------------------------------------------------------------------------------------
Please consider the environment before printing this email.
Please do not print this email unless it is absolutely necessary.

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. I accept no liability for any damage caused by any virus transmitted by this email.
-------------------------------------------------------------------------------------------------------------------

Julien Viet

unread,
May 22, 2013, 5:01:51 AM5/22/13
to Harsh Kumar, crash...@googlegroups.com
yes you can, just use an identifier in login.groovy and in groovy commands.

foo = "123"

foo

it should bding to user session state in both case

Harsh Kumar

unread,
May 22, 2013, 5:15:45 AM5/22/13
to Julien Viet, crash...@googlegroups.com
Hi,

Does it also work for methods?

as in
Can I define methods in login.groovy and expect them to be available in every command/groovy file in crash/cmd?


Julien Viet

unread,
May 22, 2013, 8:56:58 AM5/22/13
to Harsh Kumar, crash...@googlegroups.com
here is an example used by the JCR integration :

https://github.com/crashub/crash/blob/master/jcr/core/src/main/resources/crash/commands/jcr/login.groovy
https://github.com/crashub/crash/blob/master/jcr/core/src/main/resources/crash/commands/jcr/ls.groovy

for instance the assertConnected() used by ls.groovy

that is defined in login.groovy and use currentPath session binding
Reply all
Reply to author
Forward
0 new messages