Class CommandLineConfigSource
java.lang.Object
cloud.opencode.base.config.source.CommandLineConfigSource
- All Implemented Interfaces:
ConfigSource
Command Line Arguments Configuration Source
命令行参数配置源
Parses command line arguments into configuration properties with support for multiple formats: --key=value, -Dkey=value, and boolean flags.
将命令行参数解析为配置属性,支持多种格式: --key=value, -Dkey=value 和布尔标志。
Features | 主要功能:
- Multiple argument formats - 多种参数格式
- Boolean flag support (--flag -> flag=true) - 布尔标志支持
- Highest priority (200) - 最高优先级(200)
- Order preservation - 顺序保留
Usage Examples | 使用示例:
// Parse arguments
String[] args = {
"--server.port=9090",
"-Dapp.env=prod",
"--debug",
"--database.url=jdbc:mysql://localhost/db"
};
ConfigSource source = new CommandLineConfigSource(args);
// server.port=9090
// app.env=prod
// debug=true
// database.url=jdbc:mysql://localhost/db
Supported Formats | 支持的格式:
--key=value -> key=value -Dkey=value -> key=value --flag -> flag=true -Dflag -> flag=true
Performance | 性能特性:
- Time complexity: O(n) for parsing - 时间复杂度: 解析为O(n)
- Arguments parsed once at creation - 参数在创建时解析一次
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Immutable properties - 不可变属性
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCommandLineConfigSource(String[] args) Create command line config source 创建命令行配置源 -
Method Summary
Modifier and TypeMethodDescriptiongetName()Get configuration source name 获取配置源名称intGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Get all configuration properties 获取所有配置属性Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ConfigSource
getProperty, reload, supportsReload
-
Constructor Details
-
CommandLineConfigSource
Create command line config source 创建命令行配置源- Parameters:
args- command line arguments | 命令行参数
-
-
Method Details
-
getName
Description copied from interface:ConfigSourceGet configuration source name 获取配置源名称- Specified by:
getNamein interfaceConfigSource- Returns:
- source name | 源名称
-
getProperties
Description copied from interface:ConfigSourceGet all configuration properties 获取所有配置属性Performance | 性能:
This method should return a cached immutable map for best performance.
此方法应返回缓存的不可变映射以获得最佳性能。
- Specified by:
getPropertiesin interfaceConfigSource- Returns:
- configuration properties map | 配置属性映射
-
getPriority
public int getPriority()Description copied from interface:ConfigSourceGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Default Priorities | 默认优先级:
- CommandLine: 200
- Environment: 100
- Properties/YAML: 50
- InMemory: 10
- Specified by:
getPriorityin interfaceConfigSource- Returns:
- priority value | 优先级值
-