3

In a command line Java application you can get arguments through the args parameter:

public static void main(String[] args) {

How can I do something similar in Ceylon? I tried copying the Java style:

shared void run(String[] args) {

but got an error since that is not allowed:

ceylon run: Cannot run toplevel method 'test.project.run': 
it should have no parameters or they should all have default values.

I've been reading the ceylon-lang.org tour but I haven't found the answer.

KPD
  • 5,281
  • 4
  • 20
  • 19

1 Answers1

9

Use the top-level process object in the language module.

String[] arguments = process.arguments;
String? argument = process.namedArgumentValue("name");
if (process.namedArgumentPresent("name")) {
    // ...
}
gdejohn
  • 7,451
  • 1
  • 33
  • 49
  • How did you know about the properties 'arguments' and 'namedArgumentValue' ? I can't see them in the list of members: https://herd.ceylon-lang.org/modules/ceylon.process/1.3.3/members –  Nov 12 '18 at 19:02
  • You're looking at the `ceylon.process` module, which is distinct from and serves a different purpose than the `process` top-level object in the language module that I linked to in my answer. – gdejohn Nov 12 '18 at 19:07