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
-
- Object
- PropertySource<
T> - ListablePropertySource<
T> - CommandLinePropertySource
- Implementers
- Annotations
-
- @Generic.new(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
- name → String
-
The unique name that identifies this property source.
Typically used for logging, debugging, and source resolution order.
finalinherited
- nonOptionArgsPropertyName ↔ String
-
The current key used to access non-option arguments.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → T
-
The underlying object that holds the raw property data.
finalinherited
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 the givenname
.override -
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode
, andtoString
.inherited -
getName(
) → String -
Returns the 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
name
, ornull
if not present.override -
getPropertyNames(
) → List< String> -
Returns the full list of property names known to this PropertySource.
inherited
-
getSource(
) → T -
Returns the underlying source object.
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.