Skip to content

chore: add CLI `fetch` boilerplate

Matthew Clarkson requested to merge cli-fetch-boilerplate into main

Sets up the harness for hosting nested CLI commands with go-flags1.

Each command will be defined in a separate go file.

The structured logging is set up with the JSON outputter.

That can be controlled with --log-level=<error|warn|info|debug>

The bazel-git fetch usage mirrors an extreme subset of git fetch but includes the --reference argument to provide references the tool can use to find a single SHA when a server does not advertise the SHA.

The tool does nothing more that output the fetch arguments to the debug logging channel.

Try it out with:

go run \
  ./cmd/bazel-git \
    --log-level debug \
    fetch \
    --reference one \
    --reference two \
    abc def

The output should be:

{
  "time": "2024-02-02T14:35:14.478250053Z",
  "level": "DEBUG",
  "msg": "fetch",
  "FetchCommand": {
    "RecurseSubmodules": false,
    "References": [
      "one",
      "two"
    ],
    "Args": {
      "Remote": "abc",
      "Committish": [
        "def"
      ]
    }
  }
}

Merge request reports