Run configurations

Greet takes a person's name as its argument and greets them with whatever the GREETING environment variable says - Hello when nothing sets it. The argument and the environment are two things a run needs that are not in the code. A run configuration keeps them, under a name, so you do not type them again; this lesson saves two for Greet and switches between them. Read greeter.ek9. To play it in the IDE: Help > Lessons > Running and testing…, or ek9 -ide -lesson run-configurations.

The EK9 IDE as the lesson opens

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

#!ek9
defines module lesson.greeter

  defines program

    Greet()
      -> person as String
      stdout <- Stdout()
      env <- EnvVars()
      greeting <- env.get("GREETING")
      if greeting?
        stdout.println(`${greeting}, ${person}`)
      else
        stdout.println(`Hello, ${person}`)

//EOF

Step 1: A one-off run

Choose Run > Run Program…

The EK9 IDE once this is done: Choose Run > Run Program…

Type Ada into Arguments (space-separated), then choose Run.

The EK9 IDE just before choosing Run: Type Ada into Arguments (space-separated), then choose Run

Hello, Ada - nothing sets GREETING, and the argument you typed was used once and not kept. Run Program… is for a run you will not repeat. Choose Close.

The EK9 IDE just before choosing Close: Hello, Ada - nothing sets GREETING, and the argument you typed was used once and not kept

Step 2: Save two configurations

Choose Run > Configurations…

The EK9 IDE once this is done: Choose Run > Configurations…

Greet is the only program, so it is already the one a new configuration will belong to. Choose + New Configuration…

Name it Formal, type Lovelace into Arguments and, into Environment, GREETING=Good morning. Choose Create.

The EK9 IDE just before choosing Create: Name it Formal, type Lovelace into Arguments and, into Environment, GREETING=Good morning

Choose + New Configuration… again, for a second one.

The EK9 IDE just before choosing + New Configuration…: Choose + New Configuration… again, for a second one

Name it Casual, type Sam into Arguments and GREETING=Hey into Environment. Choose Create.

The EK9 IDE just before choosing Create: Name it Casual, type Sam into Arguments and GREETING=Hey into Environment

Both are listed, each with its arguments and the number of environment variables it sets, and both are already kept - nothing here needs saving again. Choose Cancel. Nothing runs.

The EK9 IDE just before choosing Cancel: Both are listed, each with its arguments and the number of environment variables it sets, and both are already kept - nothing here needs saving again

Step 3: Switch with the toolbar's picker

In the toolbar's picker, beside the green play icon, choose Casual.

The EK9 IDE once this is done: In the toolbar's picker, beside the green play icon, choose Casual

Choose the green play icon - Run selected configuration.

The EK9 IDE once this is done: Choose the green play icon - Run selected configuration

Hey, Sam - Casual's argument and its GREETING, both from the configuration. Choose Close.

In the toolbar's picker, beside the green play icon, choose Formal.

The EK9 IDE once this is done: In the toolbar's picker, beside the green play icon, choose Formal

Choose the green play icon - Run selected configuration.

The EK9 IDE once this is done: Choose the green play icon - Run selected configuration

Good morning, Lovelace - the same program, a different argument and a different GREETING, one click after choosing it. Choose Close.

Step 4: Edit one, run it again

Choose the gear beside the picker - Edit Configurations… - which opens the same window as Run > Configurations….

The EK9 IDE once this is done: Choose the gear beside the picker - Edit Configurations… - which opens the same window as Run > Configurations…

Double-click Casual in the list to edit it.

The EK9 IDE once this is done: Double-click Casual in the list to edit it

Change Arguments to Alex. Choose Save.

The EK9 IDE just before choosing Save: Change Arguments to Alex

Casual is selected and now reads Alex. Choose Run. This window runs the selected configuration, as the toolbar does.

The EK9 IDE just before choosing Run: Casual is selected and now reads Alex

Hey, Alex - the edit was kept, and the configuration it changed is the one that ran. Choose Close.

The EK9 IDE just before choosing Close: Hey, Alex - the edit was kept, and the configuration it changed is the one that ran

The result

That is a run configuration: a name, an argument line and an environment, kept for one program - as many as you like. Run > Run Program… (or the gutter's play icon) is for a run you will not repeat; Run > Configurations… saves, edits and deletes them; the toolbar's picker switches between them and runs the chosen one with a click, and its gear opens the same Configurations window. A configuration is yours alone, kept beside your other IDE settings and never in the project - an environment value written ${NAME} is read from your own environment when it runs, so a secret is never saved. AI assistants run a program with the same settings through ek9_run_program {programName, args, env}.

The EK9 IDE when the lesson has finished

Where this lesson comes from