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
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.
override
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.
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 property name, or null if the property is not present in this source.
inherited
getPropertyNames() → List<String>
Returns the full list of property names known to this PropertySource.
override
getSource() → CommandLineArgs
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.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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