CommandLinePropertySource<T> constructor

CommandLinePropertySource<T>(
  1. T source
)

A base class for property sources that are backed by command line arguments.

This class is capable of handling both option arguments (e.g., --port=8080) and non-option arguments (e.g., positional values like input.txt).

It supports retrieving these arguments as properties through the familiar getProperty interface and allows customization of the key used to access non-option arguments.

Commonly extended by concrete sources such as argument parsers.

Example:

class SimpleCommandLinePropertySource extends CommandLinePropertySource<MyArgsParser> {
  SimpleCommandLinePropertySource(MyArgsParser parser) : super(parser);

  @override
  bool containsOption(String name) => source.hasOption(name);

  @override
  List<String>? getOptionValues(String name) => source.getOptionValues(name);

  @override
  List<String> getNonOptionArgs() => source.getNonOptionArgs();
}

final source = SimpleCommandLinePropertySource(parser);
print(source.getProperty('host')); // "localhost"
print(source.getProperty('nonOptionArgs')); // "input.txt,config.json"

Implementation

CommandLinePropertySource(T source) : super(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, source);