Running jarchi in batch mode

Started by vegardv, September 20, 2019, 14:42:59 PM

Previous topic - Next topic

Phil Beauvoir

This returns the CLI arguments:


var args = Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs();

for(i = 0; i < args.length; i++) {
    console.log(args[i]);
}
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.


Jean-Baptiste Sarrodie

Hi,

Quote from: Phil Beauvoir on February 27, 2020, 11:50:47 AM
This returns the CLI arguments:


var args = Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs();

for(i = 0; i < args.length; i++) {
    console.log(args[i]);
}


@Phil: but this will no more work with next version because of how this issue has been solved, no?

If so, then maybe we should add an explicit option like "--script.arg" which would be kept so that your sample code can be used.

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

@JB No, it won't affect it. Non-ACLI arguments are filtered out when running the Command Line Providers. The raw string array from Eclipse's Platform.getApplicationArgs() will return all user args regardless.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Jean-Baptiste Sarrodie

Hi,

Quote from: Phil Beauvoir on February 27, 2020, 13:04:18 PM
@JB No, it won't affect it. Non-ACLI arguments are filtered out when running the Command Line Providers. The raw string array from Eclipse's Platform.getApplicationArgs() will return all user args regardless.

Yes, you're right. So basically we could even provide a kind of API for this with a full JS implementation through init.js

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

Quote from: Jean-Baptiste Sarrodie on February 27, 2020, 13:21:40 PM
Hi,

Quote from: Phil Beauvoir on February 27, 2020, 13:04:18 PM
@JB No, it won't affect it. Non-ACLI arguments are filtered out when running the Command Line Providers. The raw string array from Eclipse's Platform.getApplicationArgs() will return all user args regardless.

Yes, you're right. So basically we could even provide a kind of API for this with a full JS implementation through init.js

JB

You mean like the one I've already written in init.js?


function getArgs() {
return Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs();
}


8)
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Jean-Baptiste Sarrodie

If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

AlexL

Quote from: Phil Beauvoir on February 27, 2020, 13:23:12 PM
Quote from: Jean-Baptiste Sarrodie on February 27, 2020, 13:21:40 PM
Hi,

Quote from: Phil Beauvoir on February 27, 2020, 13:04:18 PM
@JB No, it won't affect it. Non-ACLI arguments are filtered out when running the Command Line Providers. The raw string array from Eclipse's Platform.getApplicationArgs() will return all user args regardless.

Yes, you're right. So basically we could even provide a kind of API for this with a full JS implementation through init.js

JB

You mean like the one I've already written in init.js?


function getArgs() {
return Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs();
}


8)

So when it's planned to be released? )

Phil Beauvoir

Quote from: AlexL on February 27, 2020, 14:10:05 PM

So when it's planned to be released? )

The source code is available now - https://github.com/archimatetool/archi-scripting-plugin

You can also edit your copy of init.js to add the lines, although it amounts to the same code that I posted above.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

vegardv

Quote from: Phil Beauvoir on February 27, 2020, 10:55:15 AM
What arguments are we talking about? Do we mean the ones passed via the ACLI as in the following -myArg "HelloWord"?

Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript "MyScript.ajs" -myArg "HelloWord"

If so, these can be accessed from jArchi with the following:

var args = Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs()

This returns an object with the args.

This is great!

Using archi 4.6.0 I get an error when running the example exactly as given:
org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -myArg

but creating a script like this:
var args = Java.type("org.eclipse.core.runtime.Platform").getApplicationArgs()
for (var i=0; i<args.length; i++){
    console.log ("script was called with arg: "+args[i]);
}

.. and invoking it like this:
archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript args.js -- -myArg foo

results in:
script was called with arg: --script.runScript
script was called with arg: args.js
script was called with arg: --
script was called with arg: -myarg
script was called with arg: foo


So it works in principle, but is this the appropriate way to supply CLI arguments?

Phil Beauvoir

> Using archi 4.6.0 I get an error when running the example exactly as given:


Fixed in Archi 4.7 Early Access version.

jArchi 0.7.2 has the new JS function getArgs() which is a wrapper around the Java call.

var args = getArgs();

for(i = 0; i < args.length; i++) {
    console.log(args);
}
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.