SimpleCommandLinePropertySource constructor

SimpleCommandLinePropertySource(
  1. List<String> args
)

A CommandLinePropertySource that adapts CommandLineArgs into a resolvable PropertySource.

This class wraps a parsed list of command-line arguments and exposes them as key-value properties, allowing flexible configuration using flags like:

  • --key=value
  • --key value
  • multiple --key=value for lists

Behavior

  • If a key is not present, the property will be null.
  • If present without value (--debug), returns an empty list.
  • If present with one value, returns that value as a string.
  • If present multiple times, returns all values as a comma-separated string.

Example usage:

final args = ['--env=prod', '--debug', '--features=a', '--features=b'];
final propertySource = SimpleCommandLinePropertySource(args);

print(propertySource.getProperty('env'));       // "prod"
print(propertySource.getProperty('debug'));     // ""
print(propertySource.getProperty('features'));  // "a,b"
print(propertySource.containsProperty('debug')); // true

This class is often registered within the MutablePropertySources collection and resolved through a PropertyResolver during app bootstrap.

Implementation

SimpleCommandLinePropertySource(List<String> args) : super(SimpleCommandLineArgsParser().parse(args));