java/zargs/SKILL.md
Add zero-dependency argument parsing to Java CLI applications using the zargs pattern — an enum-based argument parser. Use when adding CLI argument parsing, command-line option handling, or adding options to a Java project. Triggers on "zargs", "argument parsing", "CLI arguments", "command-line options", "parse arguments", "add options", or requests to add argument/option parsing to a Java CLI application without external dependencies.
npx skillsauth add adambien/airails zargsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Add zero-dependency argument parsing to a Java CLI application using $ARGUMENTS. Apply all rules below.
zargs is a zero-dependency, enum-based argument parsing pattern for Java CLI applications. It is not a library or dependency — it is a set of conventions and code patterns to apply directly when generating argument parsing code.
Define an enum where each constant represents a CLI option. The enum provides matching, lookup, and usage generation:
import java.util.stream.Collectors;
import java.util.stream.Stream;
public enum Arg {
HELP("-help", "Show this help"),
VERBOSE("-verbose", "Enable verbose output"),
OUTPUT("-output", "Specify output file");
final String option;
final String description;
Arg(String option, String description) {
this.option = option;
this.description = description;
}
boolean matches(String value) {
return this.option.equals(value)
|| value.startsWith(this.option + ":");
}
static Arg from(String value) {
return Stream.of(values())
.filter(a -> a.matches(value))
.findFirst()
.orElse(null);
}
static String usage() {
return Stream.of(values())
.map(a -> " %-12s %s".formatted(a.option, a.description))
.collect(Collectors.joining("\n"));
}
}
Define a record matching the application's parsed arguments:
import java.util.List;
public record Args(boolean verbose, String output, List<String> files) {}
zargs supports two value styles for options that take a value:
| Style | Example | Description |
|-------|---------|-------------|
| Colon-separated | -output:result.txt | Value follows : immediately |
| Space-separated | -output result.txt | Value is the next argument |
Boolean flags (like -verbose) require no value.
Use pattern matching with switch and case null to parse arguments:
Args parseArgs(String[] args) {
var verbose = false;
String output = null;
var files = new ArrayList<String>();
for (int i = 0; i < args.length; i++) {
var arg = args[i];
switch (Arg.from(arg)) {
case HELP -> printUsage();
case VERBOSE -> verbose = true;
case OUTPUT -> output = extractValue(arg, args, i++);
case null -> {
if (arg.startsWith("-")) Log.stop("Unknown option: " + arg);
files.add(arg);
}
}
}
return new Args(verbose, output, List.copyOf(files));
}
String extractValue(String arg, String[] args, int index) {
if (arg.contains(":")) {
return arg.substring(arg.indexOf(":") + 1);
}
if (index + 1 >= args.length) {
Log.stop("Missing value for " + arg);
}
return args[index + 1];
}
void printUsage() {
Log.user("""
Usage: appname [options] <files...>
Options:
%s
""".formatted(Arg.usage()));
System.exit(0);
}
Arg.from() returns null for unknown args — enables case null in switch for positional arguments and unknown option detectionmatches() handles both syntaxes — exact match (-output) or colon-prefixed (-output:value)extractValue() extracts values — from colon syntax or next argument, with missing-value error handlingusage() auto-generates help text — no manual formatting needed; derived from enum constantsArgs record is the parse result — immutable, typed container for all parsed valuesWhen generating argument parsing code, adapt these parts for the specific application:
Args record fields — match the fields to the application's parsed result shapeparseArgs switch cases — add a case for each enum constantprintUsage()package declarations matching the target packageLog.stop() from zcl for fatal errors (missing values, unknown options)Log.user() from zcl for usage/help outputList.copyOf() for immutable positional argument lists in the Args record-verbose, not --verbose) for consistencytools
Generic, composable Java 25 code conventions — modern syntax, code style, naming, visibility, structure, methods, streams, exceptions, and documentation rules that apply across all Java contexts (single-file scripts, CLI apps, MicroProfile/Jakarta EE servers, libraries). Technology-neutral within the Java world; meant to be composed with context-specific skills (e.g. `java-cli-script`, `java-cli-app`, `microprofile-server`, `bce`). Use when writing, generating, or reviewing Java code anywhere the composed skill does not already specify style. Triggers on "Java conventions", "Java style", "Java code style", "modern Java", "Java 25", "idiomatic Java", or any request to write or review Java code where context-specific skills do not already cover style.
tools
Generic, composable architecture rules for the Boundary-Control-Entity (BCE/ECB) pattern — business components, layer responsibilities, package structure, and cross-component relationships. Technology-neutral; meant to be composed with language- or framework-specific skills (e.g. microprofile-server, web-components, aws-cdk, java-cli-app). Use when creating, generating, scaffolding, writing, or reviewing code organized as business components with boundary/control/entity layers. Triggers on "BCE", "ECB", "Boundary-Control-Entity", "business component", "BC layout", "BC structure", "boundary layer", "control layer", "entity layer", or requests to organize, package, refactor, or review code along BCE lines.
tools
Create zero-dependency, single-file executable Java scripts for system-wide use via PATH. Use when asked to create a single-file Java shell script, system utility, PATH-installed Java tool, or shebang-launched Java program without the .java extension. Triggers on "Java script", "Java utility", "PATH script", "system script", or requests for single-file Java programs installed in /usr/local/bin or similar PATH directories. Not for multi-file Java applications — use java-cli-app for those.
development
Architecture and coding rules for long-running Java MicroProfile / Jakarta EE server applications — BCE layering, business components (BC), JAX-RS resources, CDI, JSON-P, testing (unit/integration/system), and Maven project structure. Use when creating, generating, scaffolding, writing, or reviewing code, resources, entities, boundaries, or business components in MicroProfile server projects. Not for serverless deployments.