cli_config
0.2.0, released 3 years ago by tools.dart.dev
Library to read config from CLI args, env vars, and JSON/YAML files
What it does
It provides a uniform API to access configuration values from command‑line arguments, environment variables, and configuration files. The library handles precedence, hierarchical keys, and optional list merging.
AI-written summary of version 0.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a single source of truth for configuration across CLI, env, and files
- You want hierarchical configuration with dot or double‑underscore separators
- You need both sync and async configuration loading
Skip it when
- You only need a single configuration source
- You require code generation for config models
Strengths
- Simple API with clear precedence rules
- Supports hierarchical keys and list merging
- Provides both async and sync loading
Weaknesses
- No code generation or type safety for config models
- Limited to CLI, env, and file sources only
- No built‑in validation or schema support
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
final config = await Config.fromArguments(arguments: arguments);
final pathValue = config.optionalPath('my_path', resolveUri: true, mustExist: false);
print(pathValue?.toFilePath());Alternatives
Packages that do the same job and could replace cli_config.
- package_config
Read and write Dart package configuration files.
80Compare - flutter_dotenv
Loads configuration variables from .env asset files or strings into Flutter apps.
89Compare - config
Typed CLI argument and config file parser with env support
84Compare - dotenv
Load environment variables at runtime from a .env file.
50Compare
Works with
Packages commonly used together with cli_config: ones it builds on, ones built on it, and its own family.
- yamlcli_config depends on itA Dart library for parsing YAML documents into Dart data structures.
- argscli_config depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- analyzerSame familyPerforms static analysis of Dart code for tool integration and embedding.
- dart_styleSame familyProvides an API and CLI to format Dart source code automatically.
- pubspec_parseSame familyParse pubspec.yaml files with a type‑safe API and detailed error reporting.
- cli_utilSame familyUtilities to help build Dart command-line apps, find the SDK, and display progress.
- yaml_editSame familyYAML manipulation library preserving comments and whitespace
- extension_discoverySame familyConvention and utilities for discovering package extensions via config.yaml files.