SimpleCommandLinePropertySource class

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.

Inheritance

Constructors

SimpleCommandLinePropertySource(List<String> args)
A CommandLinePropertySource that adapts CommandLineArgs into a resolvable PropertySource.
SimpleCommandLinePropertySource.named(String name, List<String> args)
Creates a SimpleCommandLinePropertySource 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 pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
source → CommandLineArgs
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.
override
containsProperty(String name) bool
Returns true if this property source contains the given name.
override
equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
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.
override
getOptionValues(String name) List<String>?
Returns the values for a given option name.
override
getProperty(String name) String?
Retrieves the value associated with the given name, or null if not present.
inherited
getPropertyNames() List<String>
Returns the full list of property names known to this PropertySource.
override
getSource() → CommandLineArgs
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.
inherited
toString() String
A string representation of this object.
inherited

Operators

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