A Scala library for parsing command-line options with functional and object-oriented DSLs.
scopt is a Scala library for parsing command-line arguments in type-safe and declarative ways. It solves the problem of handling complex CLI interfaces by providing DSLs to define options, commands, and validations, reducing boilerplate and errors.
Scala developers building command-line applications, tools, or scripts that require robust argument parsing and help text generation.
Developers choose scopt for its dual DSL support, seamless integration with Scala's type system, and extensive features like command nesting and validation, which streamline CLI development compared to manual parsing.
command line options parsing for Scala
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Leverages Scala's Read typeclass to enforce correct argument types at compile-time, reducing runtime errors. The README shows support for Int, File, Seq, Map, and custom types like enums.
Offers both functional (OParser) and object-oriented (OptionParser) APIs, allowing developers to choose based on coding style. Examples in the README demonstrate both approaches with clear syntax.
Includes nested commands, custom validation, automatic help text generation, and effect abstraction. For instance, it supports commands like 'update' with child options and validation functions.
Compatible with multiple Scala versions (2.11 to 3.x) and platforms (JVM, JS, Native), as shown in the version table, making it versatile for different deployment environments.
Allows interception of side effects like output and termination via OParser.runParser, enabling easier unit testing without actual IO operations, as detailed in the advanced usage section.
Requires defining a case class and using DSLs even for simple parsers, which can be overkill compared to lighter alternatives. The README example starts with a multi-field Config case class for basic options.
The parser is defined at compile-time, making it difficult to dynamically modify or generate options based on runtime conditions, limiting flexibility for adaptive CLI interfaces.
Breaking changes between major versions (e.g., scopt 3.x to 4.x) require code updates, as noted in the mutable parsing section, increasing maintenance overhead for legacy projects.
Mastering features like type classes, effect abstraction, and command nesting requires solid Scala functional programming knowledge, which may slow down onboarding for less experienced developers.