config
0.10.0, released 5 days ago by serverpod.dev
Typed CLI argument and config file parser with env support
What it does
Extends Dart's args package to provide typed options, environment variable integration, YAML/JSON config files, and comprehensive validation. It offers a drop‑in replacement for ArgParser via ConfigParser.
AI-written summary of version 0.10.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Migrating an existing ArgParser setup to support typed options and multiple config sources
- Building command‑line tools that need environment variable or file based configuration
- Requiring consistent, fail‑fast error reporting for CLI arguments
Skip it when
- Projects that only need simple flag parsing and are already using args without the need for env or file support
Strengths
- Typed option definitions with automatic parsing and constraints
- Support for environment variables and YAML/JSON config files
- Collects all validation errors upfront for better UX
- Drop‑in replacement for ArgParser with minimal code changes
Weaknesses
- Requires Dart SDK 3.9+ (breaking change in 0.10.0)
- addCommand() not supported, needs BetterCommandRunner from cli_tools
- No code generation support
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 7
Add dependency, import config, replace ArgParser with ConfigParser; no build_runner needed
import 'package:config/config.dart';
final parser = ConfigParser();
parser.addOption('port', defaultsTo: '8080');
parser.addOption('host', envName: 'HOST');
final results = parser.parse(['--port', '3000']);
print(results['port']);Alternatives
Packages that do the same job and could replace config.
- cli_util
Utilities to help build Dart command-line apps, find the SDK, and display progress.
88Compare - package_config
Read and write Dart package configuration files.
80Compare - pubspec_parse
Parse pubspec.yaml files with a type‑safe API and detailed error reporting.
93Compare - cli_completion
Completion functionality for Dart Command-Line Interfaces built using CommandRunner.
85Compare
Works with
Packages commonly used together with config: ones it builds on, ones built on it, and its own family.
- yamlconfig depends on itA Dart library for parsing YAML documents into Dart data structures.
- argsconfig depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- charactersconfig depends on itUnicode and grapheme cluster aware string manipulation operations for Dart.
- rfc_6901config depends on itImplements RFC 6901 JSON Pointer for reading, writing and removing values in JSON documents.
- cli_toolsBuilt on configUtilities for building command‑line interfaces, including argument parsing, analytics, and progress reporting.
- serverpod_cliBuilt on configCommand line tools for Serverpod.
- ciachBuilt on configDead code detector for Dart and Flutter that finds and removes unused declarations.