savi icon indicating copy to clipboard operation
savi copied to clipboard

Override constants with compile-time CLI args

Open jemc opened this issue 4 years ago • 1 comments

We want to allow overriding a :const value at compile-time (without editing source code), by specifying a compile-time CLI argument for it.

For example, consider the following program:

:module MyApp
  :const version: "unknown"
  
:actor Main
  :new (env Env)
    env.out.print("MyApp version: " + MyApp.version)

When compiled as normal, it would print the source-code-defined value ("unknown"):

> savi && ./main

MyApp version: unknown

But when compiled with a compile-time constant value override defined, it would print the overridden value:

> savi --define MyApp.version="v3.5.21 (git a46fde0d)" && ./main

MyApp version: v3.5.21 (git a46fde0d)

jemc avatar Nov 22 '21 01:11 jemc

It should be possible to override a string constant, a boolean constant, or a numeric constant.

  • if the constant is a string type, the CLI arg will be used directly as a string
  • if the constant is a integer type, the CLI arg will be parsed as an integer
  • if the constant is a floating-point type, the CLI arg will be parsed as a floating-point value
  • if the constant is a boolean type, the CLI arg will be checked (case-insensitively) for common boolean string values (e.g. "true", "false", "yes", "no")

If the constant has some other (unsupported) type, or if the CLI arg fails to parse as the expected type, a compilation error will result, requesting the user to fix the CLI invocation with a supported kind of value defined.

jemc avatar Nov 22 '21 01:11 jemc