Skip to content

Extract a testable CLI app runner #69

Description

@apstndb

Deferred from local repository review cleanup.

Problem

main.go currently combines flag parsing, validation, timestamp-bound selection, statement classification, Spanner client setup, execution mode routing, output selection, tracing, and gRPC logging. This makes CLI-routing behavior hard to unit-test without reaching into _main, global os.Args, os.Stdout, and live Spanner paths.

There are also parallel mode switches for normal jq/json/yaml output, CSV output, and partition-query checks. That makes it easy for flags to be accepted on paths where they are later ignored.

Proposed work

Extract small, testable layers without changing user-visible behavior:

  • cmd/execspansql or a minimal root main.go for process exit handling.
  • An app runner such as Run(ctx, Config, IO, ClientFactory) error.
  • A Spanner execution layer for statement classification, timestamp-bound selection, transaction mode, query options, and partition-query checks.
  • Output sinks for jq JSON/YAML, CSV, and future JSONL/stats side channels.
  • Observability setup for tracing and gRPC logging.

This should be incremental. First extract seams that let issue #63 cover routing behavior, then collapse duplicated mode dispatch.

Acceptance criteria

  • CLI behavior remains compatible except for separately documented validation fixes.
  • Unit tests cover DML classification, timestamp-bound selection, help/flag validation, tracing setup, and log-grpc mode selection without requiring live Spanner.
  • Integration tests continue to cover actual emulator-backed execution paths.
  • Adding a new output format requires changing one output-routing area rather than every execution-mode switch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions