Run artifact

workspace/targets/Quakes/blueprint/FEATURE-Options.md

FEATURE: Options

FieldValue
Version20261025 V1
DescriptionParses and validates the command, its options, and the file argument, raising a usage error for any malformed invocation.
Depends OnFEATURE-CliFoundation.md
Providesparse_args

Purpose

cli.options.parse_args(argv) -> Parsed turns the argument list into a validated Parsed record or raises cli.errors.UsageError. UsageError is defined in cli/errors.py (see FEATURE-ExitCodes.md); this story creates the module with both exception classes if it does not exist yet. The dispatcher maps UsageError to exit code 2.

Grammar

quakes fetch --start <YYYY-MM-DD> --end <YYYY-MM-DD> [--min-mag <m>] --out <file>
quakes summary [--min-mag <m>] <file>
quakes top [--min-mag <m>] [--n <count>] <file>
quakes daily [--min-mag <m>] <file>
quakes regions [--min-mag <m>] <file>
quakes near --lat <deg> --lon <deg> --radius <km> [--min-mag <m>] <file>

Programmatic Acceptance

=== AC options-valid-summary ===
Intent: A valid summary invocation parses into the expected command, filter, and file.

from cli.options import parse_args

path = "quakes-file.geojson" parsed = parse_args(["summary", "--min-mag", "5.5", path]) assert parsed.command == "summary" assert parsed.min_mag == 5.5 assert parsed.file == path === END AC options-valid-summary ===

=== AC options-defaults ===
Intent: top defaults n to 10, reports default min_mag to None, and fetch defaults min_mag to 2.5.

from cli.options import parse_args

path = "quakes-file.geojson" top = parse_args(["top", path]) assert top.n == 10 assert top.min_mag is None fetch = parse_args(["fetch", "--start", "2025-01-01", "--end", "2025-01-08", "--out", path]) assert fetch.min_mag == 2.5 === END AC options-defaults ===

=== AC options-any-order ===
Intent: Options may appear in any order and produce the same parsed values.

from cli.options import parse_args

path = "quakes-file.geojson" a = parse_args(["top", "--n", "3", "--min-mag", "5.1", path]) b = parse_args(["top", "--min-mag", "5.1", "--n", "3", path]) assert a.n == b.n == 3 assert a.min_mag == b.min_mag == 5.1 assert a.file == b.file == path === END AC options-any-order ===

=== AC options-near-valid ===
Intent: near parses its three required options, accepting the range boundaries and negative decimals.

from cli.options import parse_args

path = "quakes-file.geojson" parsed = parse_args(["near", "--lat", "90", "--lon", "-180", "--radius", "0.5", path]) assert parsed.lat == 90.0 assert parsed.lon == -180.0 assert parsed.radius == 0.5 negative = parse_args(["summary", "--min-mag", "-1", path]) assert negative.min_mag == -1.0 === END AC options-near-valid ===

=== AC options-fetch-valid ===
Intent: fetch parses start, end, out, and an explicit min-mag.

from cli.options import parse_args

start, end, out = "2025-01-01", "2025-01-08", "feed.geojson" parsed = parse_args(["fetch", "--start", start, "--end", end, "--min-mag", "5", "--out", out]) assert parsed.command == "fetch" assert parsed.start == start assert parsed.end == end assert parsed.out == out assert parsed.min_mag == 5.0 === END AC options-fetch-valid ===

=== AC options-usage-errors ===
Intent: Every malformed invocation raises UsageError.

from cli.errors import UsageError from cli.options import parse_args

f = "quakes-file.geojson" bad = [ [], ["frobnicate", f], ["near", "--lat", "27.72", "--lon", "85.32", f], ["near", "--lat", "95", "--lon", "0", "--radius", "10", f], ["near", "--lat", "0", "--lon", "181", "--radius", "10", f], ["near", "--lat", "0", "--lon", "0", "--radius", "0", f], ["top", "--n", "0", f], ["top", "--n", "2.5", f], ["summary", "--min-mag", "big", f], ["summary", "--min-mag", "5.", f], ["summary", "--min-mag", ".5", f], ["summary", "--n", "3", f], ["summary"], ["summary", f, f], ["summary", "--min-mag", f], ["summary", "--min-mag", "5", "--min-mag", "6", f], ["fetch", "--start", "2025-01-01", "--end", "2025-01-08"], ["fetch", "--start", "2025-01-01", "--out", f], ["fetch", "--start", "2025-01-01", "--end", "2025-01-08", "--out", f, f], ["fetch", "--start", "yesterday", "--end", "2025-01-08", "--out", f], ] for argv in bad: try: parse_args(list(argv)) except UsageError: continue raise AssertionError(f"no UsageError for {argv}") === END AC options-usage-errors ===

=== AC options-exit-two ===
Intent: Through the executable entry point, an unknown command and a missing command both exit 2.

from cli.testing import cli_runner

code_unknown, out_unknown, _ = cli_runner("frobnicate", "quakes-file.geojson") code_none, out_none, _ = cli_runner() assert code_unknown == 2 assert code_none == 2 assert out_unknown == "" assert out_none == "" === END AC options-exit-two ===

User Acceptance

Guardrails