Erlang module for parsing command line arguments using GNU getopt syntax with type conversion and environment variable expansion.
Getopt is an Erlang library that provides command-line argument parsing following the GNU getopt syntax. It enables Erlang applications to handle complex command-line interfaces with support for short and long options, typed arguments, and automatic usage generation.
Erlang developers building command-line tools, escripts, or applications that require robust argument parsing with GNU-style syntax and Erlang type integration.
Developers choose Getopt for its familiar GNU getopt syntax, seamless integration with Erlang's type system for argument validation and conversion, and features like environment variable expansion and automatic help text generation.
Erlang module to parse command line arguments using the GNU getopt syntax
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Implements standard GNU getopt syntax for short (-h) and long (--help) options, making it intuitive for developers experienced with Unix command-line tools, as detailed in the command-line syntax section.
Converts arguments to Erlang types like atoms, binaries, integers, and booleans with validation, using ArgSpec in option specifications, which ensures type safety and reduces manual parsing code.
Generates formatted help text from option specifications via usage/2,3,4 functions, simplifying documentation and providing consistent CLI help, as shown in the usage examples.
Supports expansion of $VAR, ${VAR}, and %VAR% patterns in command-line strings, handling both Unix and Windows formats, which is explicitly documented with examples.
Handles quoted arguments, escape characters, option terminators (--), and multiple repetitions, demonstrated in tokenize and parse examples for embedded whitespace and special cases.
Lacks built-in support for nested subcommands, a common need in modern CLI tools like git, limiting its use for complex command hierarchies without additional custom logic.
The built documentation is described as 'very limited' in the README when using rebar edoc, which can hinder learning and troubleshooting for advanced features.
For Erlang/20+, manual setup of unicode on standard_error is required to print usage correctly with UTF-8 arguments, adding an extra step that's easy to overlook, as noted in the README.
Requires rebar3 for compilation and integration, adding setup overhead compared to lighter-weight or standard library solutions, especially for small projects.