CommandLinePropertySource<T> class abstract

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"
Inheritance
Implementers
Annotations
  • @Generic(CommandLinePropertySource)

Constructors

CommandLinePropertySource(T source)
A base class for property sources that are backed by command line arguments.
CommandLinePropertySource.named(String name, T source)
Creates a CommandLinePropertySource with a custom name.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

containsOption(String name) → bool
Returns whether the set of parsed options includes the given name.
containsProperty(String name) → bool
Returns true if this property source contains a value for the given property name.
override
equalizedProperties() → List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
getName() → String
Returns the unique, human-readable name of this property source.
inherited
getNonOptionArgs() → List<String>
Returns the list of arguments that are not in --key=value format.
getOptionValues(String name) → List<String>?
Returns the values for a given option name.
getProperty(String name) → String?
Retrieves the value associated with the given property name, or null if the property is not present in this source.
override
getPropertyNames() → List<String>
Returns the full list of property names known to this PropertySource.
inherited
getSource() → T
Returns the underlying source object from which property data is retrieved.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setNonOptionArgsPropertyName(String name) → void
Allows setting a custom property name for non-option arguments.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

COMMAND_LINE_PROPERTY_SOURCE_NAME → const String
The default name used to register this property source in the environment.
DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME → const String
The default key used to access non-option arguments from getProperty.
JETLEAF_COMMAND_LINE_PROPERTY_SOURCE_NAME → const String
The default name used to register this property source in the environment.