Top 10 CmdOption Shortcuts Every Developer Should Know

Written by

in

CmdOption is a lightweight, annotation-driven command-line argument parser toolkit designed primarily for Java applications. Developed by ToToTec, it simplifies how a program reads text arguments provided by a user at launch by automatically mapping them directly to fields or methods within a Java object. Core Features

Annotation-Driven: Developers decorate standard Java fields or methods with @CmdOption to declare flags, options, and parameters.

Automatic Parsing: The framework parses the array of arguments (String[] args) and maps the values directly to the corresponding variable types.

Built-in Help Management: Setting isHelp=true automatically bypasses standard validation rules when a user asks for help (e.g., via -h or –help), allowing the application to safely print usage hints and exit without crashing.

Localization Support: It natively supports localizing validation errors, argument exceptions, and auto-generated usage messages into multiple languages.

No Heavy Dependencies: It was originally engineered to work seamlessly even on older environments like Java 6, keeping your compiled deployment payload small. Quick Code Example

Instead of writing complex loops to scan through command-line inputs, you define a configuration class like this:

import de.tototec.cmdoption.CmdOption; import de.tototec.cmdoption.CmdlineParser; public class AppConfig { @CmdOption(names = {“–file”, “-f”}, args = “path”, description = “Path to the input file”) private String filePath; @CmdOption(names = {“–verbose”, “-v”}, description = “Enable verbose logging”) private boolean verbose; @CmdOption(names = {“–help”, “-h”}, description = “Show this help menu”, isHelp = true) private boolean help; public static void main(String[] args) { AppConfig config = new AppConfig(); CmdlineParser parser = new CmdlineParser(config); try { parser.parse(args); if (config.help) { parser.usage(); return; } // Your application logic continues here using config.filePath and config.verbose } catch (Exception e) { System.err.println(“Error: ” + e.getMessage()); parser.usage(); } } } Use code with caution. Installation

The toolkit can be quickly added to your project via Maven or Mill dependencies managed through ⁠Maven Central: Maven

de.tototec de.tototec.cmdoption 0.7.1 Use code with caution. Mill ivy”de.tototec:de.tototec.cmdoption:0.7.1” Use code with caution.

If you are looking to build a CLI or integration script, let me know:

What Java or build framework version (e.g., Maven, Gradle) you are targeting.

The complexity of your arguments (e.g., simple flags, nested subcommands, or positional parameters).

I can tailor a specific snippet or configuration to help get your terminal interface up and running!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *