Skip to content

Self-packaging #5: flapi pack / info / unpack subcommands #45

Closed

Description

@jrosskopf

Part of epic #40. Depends on #1, #2, #3.

Goal

Add the actual user-facing CLI: flapi pack, flapi info,
flapi unpack. The flapi binary becomes its own packager — the same
artifact runs the server and builds new bundled binaries.

Scope

argparse subcommands

Today src/main.cpp:269-304 has a flat argparse setup with no
subcommands. This sub-issue introduces subcommands while preserving
the zero-subcommand "run the server" default for backwards
compatibility.

flapi pack --in <config-dir> --out <new-binary>

  • Copy the running binary's bytes to <new-binary>.
  • Strip any trailing ZIP from the copy first (re-pack idempotence
    — spike lesson; do NOT touch the running binary).
  • Read the config tree via LocalFileProvider.
  • Enforce the default secret exclude list:
    *.env, secrets/*, *.pem, *.key → exit non-zero with a clear
    message if any input file matches. Override only via
    --allow-secrets (testing).
  • Rewrite paths inside YAML to embed://... where they reference
    files inside the bundle, so the same YAML works both unpacked and
    bundled.
  • Stamp entries with SOURCE_DATE_EPOCH (fall back to 0), sort
    deterministically.
  • Append the archive to <new-binary> (Linux/Windows). macOS flows
    into Offset parameter along with limit causes incorrect response #8's reserved-segment path.

flapi info

flapi unpack --to <dir>

Red tests

Catch2 unit tests (test/cpp/pack_test.cpp):

  1. pack → info round-trip lists the same entries as the input dir.
  2. *.env in input → pack exits non-zero, no output file written.
  3. --allow-secrets overrides the exclude list (for tests only).
  4. YAML path rewriting: a YAML pointing to ./data/foo.csv becomes
    embed://data/foo.csv in the bundled copy.

Integration tests live in #6, but a minimal driver test here that
execs the built debug binary and verifies a fresh pack → unpack
round-trip is also acceptable.

Green criteria

  • All red tests pass.
  • make integration-test still green.
  • Backwards compatibility: ./flapi -c flapi.yaml (no subcommand)
    still launches the server.

Files

  • New: src/pack.{hpp,cpp}, test/cpp/pack_test.cpp
  • Modified: src/main.cpp (subparser support, dispatch)

Notes

Activity

  1. added
    enhancement
    on May 21, 2026
  2. added a commit that references this issue on May 22, 2026
    e49ce46
  3. added a commit that references this issue on May 22, 2026
    5b9bc92
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions