Database Reference
In-Depth Information
def cl = new CliBuilder(usage: 'groovy runCalc [options] script-
Name...',
header: '(Options a & d required)',
stopAtNonOption: false); assert cl.stopAtNonOption == false
// stop on parse errors
cl.u(args: 1, longOpt: 'username', 'Essbase user name')
cl.p(args: 1, longOpt: 'password', 'Essbase password')
cl.s(args: 1, longOpt: 'server', 'Essbase server')
cl.a(required: true, args: 1, longOpt: 'application', 'Essbase
application')
cl.d(required: true, args: 1, longOpt: 'database', 'Essbase
database')
def opt = cl.parse(args) // process command line arguments
if (!opt) { return }
// if parsing failed, opt is null.
end script
if (opt.arguments().size() < 1) { //also need a standalone
argument
println 'error: missing scriptName'
cl.usage()
return
}
svr = opt.s ?: cs.essSvr
// command line
user = opt.u ?: cs.essUser
// args override
pass = opt.p ?: cs.essPass
// config settings
essHome = IEssbase.Home.create(IEssbase.JAPI_VERSION)
essSvr = essHome.signOn(user, pass, false, null, 'embedded', svr)
essCube = essSvr.getApplication(opt.a).getCube(opt.d)
opt.arguments().each{
essCube.calculate(false, it-'.csc') // removes .csc if present
println "$user ran $opt.a.$opt.d.${opt.arguments()[0]}
successfully on $svr!"
}
essCube.clearActive(); essSvr.disconnect(); essHome.signOff();
This code will execute a calc script if we save it to runcalc.groovy and run it like this:
>groovy runcalc -a Sample -d Basic Rollup.csc
The CliBuilder has set up five options, to which we can refer by short names (pre-
pended by one dash) or long names (prepended by two dashes). two of the options are
required, as is at least one calc script name as a freestanding argument. If we make a
mistake, we are presented with usage details:
usage: groovy runCalc [options] scriptName...
(Options a & d required)
-a,--application <arg> Essbase application
-d,--database <arg>
Essbase database
-p,--password <arg>
Essbase password
-s,--server <arg>
Essbase server
-u,--username <arg>
Essbase user name
Search WWH ::




Custom Search