Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Scala Native
  3. mainargs

mainargs

NOASSERTIONScala0.7.8

A small, dependency-free library for command-line argument parsing in Scala, used by Ammonite and Mill.

GitHubGitHub
211 stars27 forks0 contributors

What is mainargs?

MainArgs is a lightweight, dependency-free library for parsing command-line arguments in Scala. It allows developers to define CLI interfaces by annotating methods and case classes with `@main` and `@arg`, eliminating the need for boilerplate configuration code. It solves the problem of quickly building command-line tools with support for sub-commands, custom types, and flexible error handling.

Target Audience

Scala developers building command-line applications, tools, or scripts who want a simple, annotation-based argument parser without external dependencies.

Value Proposition

Developers choose MainArgs for its zero-dependency design, ease of use with annotations, and seamless integration with Scala idioms like case classes. It offers a cleaner alternative to more verbose libraries like Scopt or Case App, with features tailored for real-world use in projects like Ammonite and Mill.

Overview

A small, convenient, dependency-free library for command-line argument parsing in Scala

Use Cases

Best For

  • Adding CLI interfaces to Scala scripts and REPL tools
  • Building command-line tools with multiple sub-commands
  • Parsing arguments directly into Scala case classes
  • Creating lightweight CLI applications without external dependencies
  • Integrating custom type parsers into command-line arguments
  • Developing Scala Native command-line utilities

Not Ideal For

  • Projects requiring complex, interdependent CLI flag validation or business logic during parsing
  • Teams that need automatic generation of extensive documentation or man pages from CLI definitions
  • Large-scale applications with hundreds of CLI flags where annotation management becomes cumbersome
  • Cross-language projects needing consistent CLI parsing across multiple programming languages

Pros & Cons

Pros

Zero Dependencies

MainArgs has no external dependencies, keeping projects lightweight and avoiding build bloat, as emphasized in its README as a key feature.

Annotation-Driven Simplicity

Using @main and @arg annotations, developers define CLI interfaces with minimal boilerplate, turning simple Scala methods into full commands, as shown in basic examples.

Seamless Case Class Integration

Arguments parse directly into Scala case classes, enabling clean configuration objects and re-use via implicit parsers, detailed in the 'Re-using Argument Sets' section.

Flexible Sub-Command Support

Multiple @main methods act as sub-commands, allowing complex CLI tools with distinct entrypoints without extra configuration, demonstrated with foo and bar examples.

Custom Type Parsers

Implicit TokensReader instances let developers parse custom types, providing extensibility for domain-specific arguments, illustrated with os.Path parsing in the README.

Cons

Pre-1.0 Version Instability

As a 0.x library, the API is not stable; the changelog shows frequent updates and breaking changes, which could disrupt production use.

Limited Advanced Features

Compared to Scopt or Case App, it lacks built-in features like argument grouping, rich help formatting, or complex validation, focusing only on basic parsing.

Annotation-Based Lock-in

CLI definitions are tightly coupled to code via annotations, making dynamic CLI generation or integration with non-annotation frameworks difficult.

Varargs and Defaults Limitation

The README admits that using varargs parameters (e.g., String*) prevents assigning default values to other parameters, constraining design flexibility.

Frequently Asked Questions

Quick Stats

Stars211
Forks27
Contributors0
Open Issues16
Last commit4 months ago
CreatedSince 2020

Tags

#case-class#scala-library#argument-parsing#annotation-based#dependency-free#cli#scala#command-line#scala-native

Built With

S
Scala
S
Scala Native

Included in

Scala Native273
Auto-fetched 1 day ago

Related Projects

scoptscopt

command line options parsing for Scala

Stars1,447
Forks159
Last commit8 months ago
scallopscallop

a simple Scala CLI parsing library

Stars686
Forks58
Last commit6 months ago
declinedecline

A composable command-line parser for Scala.

Stars679
Forks75
Last commit1 month ago
fansifansi

Scala/Scala.js library for manipulating Fancy Ansi colored strings

Stars236
Forks25
Last commit7 months ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub