feat(os-image): add the nvke-os CLI skeleton (#2319)

* feat(os-image): add the nvke-os CLI skeleton

Add nvke-os and nvke-os-node on urfave/cli/v2 with a global -o text|json
flag, a versioned JSON envelope, coded errors mapped to banded exit
statuses, and one slog logger per run with a run ID. Both binaries share
internal/oscli; each main registers only the verbs it ships, so build-only
verbs never reach the node binary. Verbs without declared arguments reject
stray ones. manifest and verify exit with NVKE-OS-E-UNSUPPORTED until their
issues land.

make build now builds and checks the version stamp of all three binaries,
the root VERSION_CMDS lists the two new ones, and THIRD_PARTY_NOTICES.md
covers ./cmd/....

Signed-off-by: ChethanUK <chethanuk@outlook.com>

* refactor(os-image): align the nvke-os CLI with nvkr conventions

Review on #2319 asked the skeleton to follow nvkr rather than define its
own conventions.

- Apply the usage contract to every level of the command tree. An
  unknown subcommand, bad flag or stray argument under a verb with
  subcommands is now a coded usage error (exit 2), not urfave's own
  exit 3, exit 1, or a silently ignored argument.
- Add CodeUnavailable (30) and CodeTimeout (31) with Retryable, and map
  an uncoded error from a cancelled run to CodeTimeout.
- Replace the global -o and the apiVersion/kind envelope with a per-verb
  --format text|json and a flat result carrying schemaVersion.
- Drop the global --log-level/--log-format flags; a verb adds --verbose
  when it has something to log.
- Fail the Makefile version probe when the binary errors or prints
  nothing.
- Count nvke-os and nvke-os-node in README.md and docs/go-workspace.md,
  which fixes docs-check.

Signed-off-by: chethanuk <chethanuk@outlook.com>

* fix(os-image): code every nvke-os failure, including unknown help topics

An unknown help topic bypassed the usage contract: `nvke-os --help
frobnicate` exited 1 uncoded, and `<verb> help frobnicate` under a
grouping verb called os.Exit(3) from inside urfave/cli. A non-usage
uncoded error (a failed stdout write) printed without a code.

Set a no-op ExitErrHandler so Run owns the exit status, map urfave's own
exit errors to CodeUsage, and wrap any other uncoded error in
CodeInternal. Coded errors and the cancellation mapping are unchanged.

Signed-off-by: chethanuk <chethanuk@outlook.com>

---------

Signed-off-by: ChethanUK <chethanuk@outlook.com>
Signed-off-by: chethanuk <chethanuk@outlook.com>
This commit is contained in:
chethanuk
2026-11-25 09:22:41 -08:00
committed by GitHub
parent 5a86a7c13e
commit d625fcfaa8
21 changed files with 852 additions and 27 deletions
+2
View File
@@ -550,7 +550,9 @@ VERSION_CMDS := agent:--version \
capd-reboot-controller:--version \
controller:--version \
management-engine:--version \
nvke-os:--version \
nvke-os-image-check:--version \
nvke-os-node:--version \
nvkectl:version \
operator-api:--version \
tenant-api:--version \
+4 -3
View File
@@ -98,9 +98,10 @@ cd nvke
make build
```
This builds the workspace and writes nine binaries to `bin/`: `agent`,
`updater`, `controller`, `nvkectl`, `capd-reboot-controller`,
`nvke-os-image-check`, `management-engine`, `tenant-api` and `operator-api`. Building does not start a
This builds the workspace and writes eleven binaries to `bin/`: `agent`,
`updater`, `controller`, `nvkectl`, `capd-reboot-controller`, `nvke-os`,
`nvke-os-node`, `nvke-os-image-check`, `management-engine`, `tenant-api` and
`operator-api`. Building does not start a
management plane or create a cluster. The node agent runs on Linux.
The [workspace guide](docs/go-workspace.md) explains the modules and outputs.
+1 -1
View File
@@ -39,7 +39,7 @@ require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
github.com/felixge/httpsnoop v1.1.0 // indirect
+2 -1
View File
@@ -16,8 +16,9 @@ github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1x
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
+3 -2
View File
@@ -34,8 +34,9 @@ make work-check # verify workspace and module manifests
```
`make build` produces `bin/agent`, `bin/capd-reboot-controller`,
`bin/controller`, `bin/management-engine`, `bin/nvke-os-image-check`,
`bin/nvkectl`, `bin/operator-api`, `bin/tenant-api`, and `bin/updater`.
`bin/controller`, `bin/management-engine`, `bin/nvke-os`,
`bin/nvke-os-image-check`, `bin/nvke-os-node`, `bin/nvkectl`,
`bin/operator-api`, `bin/tenant-api`, and `bin/updater`.
## Updating dependencies
+10 -6
View File
@@ -1,7 +1,7 @@
# AGENTS.md — `os-image/`
Reference node OS image (spec + Packer recipe) and the `nvke-os-image-check`
connectivity binary.
Reference node OS image (spec + Packer recipe), the `nvke-os-image-check`
connectivity binary, and the `nvke-os` / `nvke-os-node` CLIs.
**Module path:** `github.com/dsx-ai-factory/nvke/os-image`
@@ -20,7 +20,11 @@ SPEC.md # contract
packer/ # QEMU golden-image build
files/ # units + SPIRE template + first-boot script
cmd/nvke-os-image-check/ # checker entrypoint
cmd/nvke-os/ # image CLI: every verb, including build-only ones
cmd/nvke-os-node/ # node CLI: manifest and verify only
internal/check/ # dial + gRPC reflection / GetKubeadmStatus
internal/oscli/ # shared command layer: usage contract, per-verb --format, exit codes
internal/errors/ # coded errors and their banded exit statuses
```
## Versioning
@@ -36,7 +40,7 @@ qcow2, `make boot-smoke` must pass, then the disk is published to NVCR and S3
(and under its version tag to `ghcr.io/dsx-ai-factory/nvke/os-image-*` only
when the repository variable `NVKE_GITHUB_PUBLISH` names `os-image`). A failed bake or smoke test does not publish.
`make` stamps `nvke-os-image-check` from:
`make` stamps `nvke-os-image-check`, `nvke-os` and `nvke-os-node` from:
```bash
git describe --tags --always --dirty --match 'v*'
@@ -45,14 +49,14 @@ git describe --tags --always --dirty --match 'v*'
## Commands
```bash
make build # stamped bin/nvke-os-image-check, and asserts the stamp took
make build # stamped bin/{nvke-os-image-check,nvke-os,nvke-os-node}, and asserts each stamp took
make compile # type-check every package, no binary
make test
make lint
```
From the repository root, `make build` links the same binary into the
repository's `bin/`, and `make version-check` runs it with `--version`.
From the repository root, `make build` links the same binaries into the
repository's `bin/`, and `make version-check` runs each with `--version`.
## Constraints
+16 -14
View File
@@ -24,7 +24,7 @@ REPO_ROOT ?= $(shell git rev-parse --show-toplevel)
# Every dependency here is public, so these targets can run with GOWORK=off.
GO ?= go
BINARY := bin/nvke-os-image-check
BINARIES := nvke-os-image-check nvke-os nvke-os-node
# Go tool install location (GOPATH/bin, unless GOBIN is set); matches the
# sibling modules.
@@ -58,18 +58,20 @@ GO_TEST_FLAGS ?=
.PHONY: build compile test fmt lint license file-license-check clean boot-smoke run-vm
build: ## Build nvke-os-image-check into bin/.
$(GO) build -ldflags "$(CHECK_LDFLAGS)" -o $(BINARY) ./cmd/nvke-os-image-check
build: ## Build nvke-os-image-check, nvke-os and nvke-os-node into bin/.
@# A wrong -X symbol is silently ignored by the linker, so the only way to
@# know the stamping worked is to ask the binary. Cheap, and it fails loudly.
@out="$$($(BINARY) --version)"; \
case "$$out" in \
*dev*|*unknown*|*v0.0.0*) \
echo "ERROR: nvke-os-image-check was built without version information: $$out"; \
echo " The -X symbol in CHECK_LDFLAGS no longer matches the variable in cmd/nvke-os-image-check."; \
exit 1;; \
*) echo " $$out";; \
esac
@# know the stamping worked is to ask each binary. Cheap, and it fails loudly.
@for b in $(BINARIES); do \
$(GO) build -ldflags "$(CHECK_LDFLAGS)" -o bin/$$b ./cmd/$$b || exit 1; \
out="$$(bin/$$b --version)" || { echo "ERROR: bin/$$b --version failed"; exit 1; }; \
case "$$out" in \
""|*dev*|*unknown*|*v0.0.0*) \
echo "ERROR: $$b was built without version information: $$out"; \
echo " The -X symbol in CHECK_LDFLAGS no longer matches the variable in cmd/$$b."; \
exit 1;; \
*) echo " $$out";; \
esac; \
done
compile: ## Type-check every package, including the ones with no binary.
$(GO) build ./...
@@ -105,7 +107,7 @@ clean:
rm -rf bin
.PHONY: notices
notices: ## Regenerate THIRD_PARTY_NOTICES.md for the nvke-os-image-check binary.
notices: ## Regenerate THIRD_PARTY_NOTICES.md for the os-image binaries.
@# The tool and the script both live in controller/, a sibling of this
@# module. `go-licenses`, not `bin/go-licenses`: the real rule's target is an
@# absolute path, so a relative name does not match it.
@@ -117,7 +119,7 @@ notices: ## Regenerate THIRD_PARTY_NOTICES.md for the nvke-os-image-check binary
@$(MAKE) --no-print-directory -C ../controller go-licenses
@MODULE_ROOT="$(CURDIR)" \
OUTPUT="$(CURDIR)/THIRD_PARTY_NOTICES.md" \
PACKAGES="./cmd/nvke-os-image-check" \
PACKAGES="./cmd/..." \
GO_LICENSES="$(CURDIR)/../controller/bin/go-licenses" \
bash ../controller/hack/generate-notices
+1
View File
@@ -29,6 +29,7 @@ consumers whose other software pins that release — see `UBUNTU_RELEASE` under
| `docs/full-disk-encryption.md` | FDE variant: build, verify, failure modes |
| `demo-fde.sh` | Runs the host-FDE acceptance scenarios against a built image |
| `cmd/nvke-os-image-check` | Connectivity checker (Go) |
| `cmd/nvke-os`, `cmd/nvke-os-node` | Image CLI and its node-side subset (Go, skeleton) |
## Build the OS image
+136
View File
@@ -17,9 +17,13 @@ notices-check` verifies it is up to date.
| Package | License | Module | Source |
|---------|---------|--------|--------|
| `github.com/cpuguy83/go-md2man/v2/md2man` | MIT | `github.com/cpuguy83/go-md2man/v2@v2.0.7` | https://github.com/cpuguy83/go-md2man/blob/v2.0.7/LICENSE.md |
| `github.com/go-jose/go-jose/v4` | Apache-2.0 | `github.com/go-jose/go-jose/v4@v4.1.9` | https://github.com/go-jose/go-jose/blob/v4.1.9/LICENSE |
| `github.com/go-jose/go-jose/v4/json` | BSD-3-Clause | `github.com/go-jose/go-jose/v4@v4.1.9` | https://github.com/go-jose/go-jose/blob/v4.1.9/json/LICENSE |
| `github.com/russross/blackfriday/v2` | BSD-2-Clause | `github.com/russross/blackfriday/v2@v2.1.0` | https://github.com/russross/blackfriday/blob/v2.1.0/LICENSE.txt |
| `github.com/spiffe/go-spiffe/v2` | Apache-2.0 | `github.com/spiffe/go-spiffe/v2@v2.9.0` | https://github.com/spiffe/go-spiffe/blob/v2.9.0/LICENSE |
| `github.com/urfave/cli/v2` | MIT | `github.com/urfave/cli/v2@v2.27.7` | https://github.com/urfave/cli/blob/v2.27.7/LICENSE |
| `github.com/xrash/smetrics` | MIT | `github.com/xrash/smetrics@v0.0.0-20240521201337-686a1a2994c1` | https://github.com/xrash/smetrics/blob/686a1a2994c1/LICENSE |
| `golang.org/x/net` | BSD-3-Clause | `golang.org/x/net@v0.62.0` | https://cs.opensource.google/go/x/net/+/v0.62.0:LICENSE |
| `golang.org/x/sys/unix` | BSD-3-Clause | `golang.org/x/sys@v0.50.0` | https://cs.opensource.google/go/x/sys/+/v0.50.0:LICENSE |
| `golang.org/x/text` | BSD-3-Clause | `golang.org/x/text@v0.44.0` | https://cs.opensource.google/go/x/text/+/v0.44.0:LICENSE |
@@ -29,6 +33,37 @@ notices-check` verifies it is up to date.
## Go Module License Texts
### github.com/cpuguy83/go-md2man/v2/md2man
_MIT — github.com/cpuguy83/go-md2man/v2@v2.0.7_
#### LICENSE.md
```text
The MIT License (MIT)
Copyright (c) 2014 Brian Goff
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
### github.com/go-jose/go-jose/v4
_Apache-2.0 — github.com/go-jose/go-jose/v4@v4.1.9_
@@ -278,6 +313,45 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
### github.com/russross/blackfriday/v2
_BSD-2-Clause — github.com/russross/blackfriday/v2@v2.1.0_
#### LICENSE.txt
```text
Blackfriday is distributed under the Simplified BSD License:
> Copyright © 2011 Russ Ross
> All rights reserved.
>
> Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions
> are met:
>
> 1. Redistributions of source code must retain the above copyright
> notice, this list of conditions and the following disclaimer.
>
> 2. Redistributions in binary form must reproduce the above
> copyright notice, this list of conditions and the following
> disclaimer in the documentation and/or other materials provided with
> the distribution.
>
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
> FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
> COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
> BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
> CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
> ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> POSSIBILITY OF SUCH DAMAGE.
```
### github.com/spiffe/go-spiffe/v2
_Apache-2.0 — github.com/spiffe/go-spiffe/v2@v2.9.0_
@@ -489,6 +563,68 @@ _Apache-2.0 — github.com/spiffe/go-spiffe/v2@v2.9.0_
```
### github.com/urfave/cli/v2
_MIT — github.com/urfave/cli/v2@v2.27.7_
#### LICENSE
```text
MIT License
Copyright (c) 2022 urfave/cli maintainers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
### github.com/xrash/smetrics
_MIT — github.com/xrash/smetrics@v0.0.0-20240521201337-686a1a2994c1_
#### LICENSE
```text
Copyright (C) 2016 Felipe da Cunha Gonçalves
All Rights Reserved.
MIT LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```
### golang.org/x/net
_BSD-3-Clause — golang.org/x/net@v0.62.0_
+30
View File
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// nvke-os-node is the node-side subset of nvke-os: manifest and verify only.
// It links no build-only packages.
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/dsx-ai-factory/nvke/os-image/internal/oscli"
)
// version is set at build time via -X main.version=.
var version = "dev"
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
app := oscli.NewApp("nvke-os-node", "check this node against its OS image lock", version,
oscli.VersionCommand(),
oscli.ManifestCommand(),
oscli.VerifyCommand(),
)
code := oscli.Run(ctx, app, os.Args, os.Stdout, os.Stderr)
stop()
os.Exit(code)
}
+30
View File
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// nvke-os builds and checks the node OS image. Build-only verbs are
// registered here and never in nvke-os-node.
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/dsx-ai-factory/nvke/os-image/internal/oscli"
)
// version is set at build time via -X main.version=.
var version = "dev"
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
app := oscli.NewApp("nvke-os", "build and check the NVKE node OS image", version,
oscli.VersionCommand(),
oscli.ManifestCommand(),
oscli.VerifyCommand(),
)
code := oscli.Run(ctx, app, os.Args, os.Stdout, os.Stderr)
stop()
os.Exit(code)
}
+4
View File
@@ -6,12 +6,16 @@ require (
github.com/dsx-ai-factory/nvke/agent v0.0.0-00010101000000-000000000000
github.com/spiffe/go-spiffe/v2 v2.9.0
github.com/stretchr/testify v1.12.1
github.com/urfave/cli/v2 v2.27.7
google.golang.org/grpc v1.85.0
)
require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/go-jose/go-jose/v4 v4.1.9 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/net v0.62.0 // indirect
golang.org/x/sys v0.50.0 // indirect
+8
View File
@@ -1,15 +1,23 @@
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/go-jose/go-jose/v4 v4.1.9 h1:pKfeQkig1NmgK4hJrZYXLEYURXfoJB61Larw0uIW4gY=
github.com/go-jose/go-jose/v4 v4.1.9/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spiffe/go-spiffe/v2 v2.9.0 h1:g5qTg3qIP1HXV+GzuyEfSJFVxUCpEP5Ui1OINVJHPB4=
github.com/spiffe/go-spiffe/v2 v2.9.0/go.mod h1:w2CLWKLMTX/PPYUEUPv3ltH0RXsw5S8suwNF46w9/Aw=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
+105
View File
@@ -0,0 +1,105 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// Package errors defines nvke-os's coded errors. It follows NVKR's coded-error
// and exit-code contract (NVKR ADR-03): every failure a user can hit carries a
// stable Code, and each Code maps to one distinct, banded process exit status.
// Callers such as NVKR or a CI job branch on the integer, so a published
// status never changes meaning. New codes take the next free integer in their
// band. The shell's 126-165 range is avoided.
//
// Band Purpose Allocated
// 0-3 Semantic (non-error) success 0, internal 1, usage 2
// 10-19 Input / preflight unsupported 10
// 20-29 Build / verify (none yet)
// 30-31 Retryable / transient unavailable 30, timeout 31
// 32-39 Reserved (none yet)
// 40-59 Release / repository (none yet)
package errors
import (
"errors"
"fmt"
)
// Code is a stable, documented error identifier.
type Code string
const (
// CodeInternal is an unexpected internal failure.
CodeInternal Code = "NVKE-OS-E-INTERNAL"
// CodeUsage is invalid command-line usage.
CodeUsage Code = "NVKE-OS-E-USAGE"
// CodeUnsupported is a verb or option this build does not implement yet.
CodeUnsupported Code = "NVKE-OS-E-UNSUPPORTED"
// CodeUnavailable is a dependency that is down or unreachable; retrying
// may succeed.
CodeUnavailable Code = "NVKE-OS-E-UNAVAILABLE"
// CodeTimeout is a run that was cancelled or ran out of time; retrying may
// succeed.
CodeTimeout Code = "NVKE-OS-E-TIMEOUT"
)
// exitCodes is the frozen Code to exit-status map. TestExitCodeContract
// snapshots it.
var exitCodes = map[Code]int{
CodeInternal: 1,
CodeUsage: 2,
CodeUnsupported: 10,
CodeUnavailable: 30,
CodeTimeout: 31,
}
// retryable marks the codes a caller may retry unchanged.
var retryable = map[Code]bool{CodeUnavailable: true, CodeTimeout: true}
// AllCodes lists every declared Code in exit-status order. Go cannot enumerate
// a const block, so a new Code is added here as well as to exitCodes.
var AllCodes = []Code{CodeInternal, CodeUsage, CodeUnsupported, CodeUnavailable, CodeTimeout}
// Error is a coded, wrappable error.
type Error struct {
Code Code
Msg string
Err error
}
func (e *Error) Error() string {
if e.Err != nil {
return fmt.Sprintf("[%s] %s: %v", e.Code, e.Msg, e.Err)
}
return fmt.Sprintf("[%s] %s", e.Code, e.Msg)
}
func (e *Error) Unwrap() error { return e.Err }
// New builds a coded error with a formatted message.
func New(code Code, format string, args ...any) *Error {
return &Error{Code: code, Msg: fmt.Sprintf(format, args...)}
}
// Wrap builds a coded error carrying an underlying cause.
func Wrap(code Code, cause error, format string, args ...any) *Error {
return &Error{Code: code, Msg: fmt.Sprintf(format, args...), Err: cause}
}
// ExitCode returns the process exit status for err: 0 for nil, the mapped
// status for a coded error, and 1 for anything else.
func ExitCode(err error) int {
if err == nil {
return 0
}
var e *Error
if errors.As(err, &e) {
if code, ok := exitCodes[e.Code]; ok {
return code
}
}
return 1
}
// Retryable reports whether err carries a code a caller may retry unchanged.
func Retryable(err error) bool {
var e *Error
return errors.As(err, &e) && retryable[e.Code]
}
+90
View File
@@ -0,0 +1,90 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package errors
import (
stderrors "errors"
"fmt"
"testing"
)
// TestExitCodeContract snapshots the published Code to exit-status map. Every
// code appears once, statuses are distinct and banded, and a change to any
// integer fails here because callers branch on it.
func TestExitCodeContract(t *testing.T) {
snapshot := map[Code]int{
CodeInternal: 1,
CodeUsage: 2,
CodeUnsupported: 10,
CodeUnavailable: 30,
CodeTimeout: 31,
}
if len(AllCodes) != len(snapshot) || len(exitCodes) != len(snapshot) {
t.Fatalf("AllCodes=%d exitCodes=%d snapshot=%d; add a new code to all three", len(AllCodes), len(exitCodes), len(snapshot))
}
seenCode := map[Code]bool{}
seenStatus := map[int]Code{}
for _, c := range AllCodes {
if seenCode[c] {
t.Errorf("%s appears twice in AllCodes", c)
}
seenCode[c] = true
got := ExitCode(New(c, "x"))
if got != snapshot[c] {
t.Errorf("%s exits %d, snapshot says %d", c, got, snapshot[c])
}
if prev, dup := seenStatus[got]; dup {
t.Errorf("exit status %d used by both %s and %s", got, prev, c)
}
seenStatus[got] = c
inBand := got <= 3 || (got >= 10 && got <= 59)
if got == 0 || !inBand {
t.Errorf("%s exits %d, outside every band", c, got)
}
}
}
func TestExitCode(t *testing.T) {
cases := []struct {
name string
err error
want int
}{
{"nil", nil, 0},
{"coded", New(CodeUsage, "x"), 2},
{"wrapped coded", fmt.Errorf("outer: %w", New(CodeUnsupported, "y")), 10},
{"plain", stderrors.New("boom"), 1},
{"unmapped code", &Error{Code: "NVKE-OS-E-NOPE"}, 1},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := ExitCode(tc.err); got != tc.want {
t.Errorf("ExitCode = %d, want %d", got, tc.want)
}
})
}
}
func TestRetryable(t *testing.T) {
cases := []struct {
name string
err error
want bool
}{
{"nil", nil, false},
{"timeout", New(CodeTimeout, "x"), true},
{"unavailable", New(CodeUnavailable, "x"), true},
{"wrapped timeout", fmt.Errorf("outer: %w", New(CodeTimeout, "x")), true},
{"usage", New(CodeUsage, "x"), false},
{"internal", New(CodeInternal, "x"), false},
{"plain", stderrors.New("boom"), false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := Retryable(tc.err); got != tc.want {
t.Errorf("Retryable = %v, want %v", got, tc.want)
}
})
}
}
+118
View File
@@ -0,0 +1,118 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// Package oscli is the command layer shared by nvke-os and nvke-os-node. It
// follows nvkr's CLI conventions: urfave/cli/v2, GNU-style long flags,
// per-command help, and coded errors mapped to banded exit statuses. Commands
// map flags, presentation and errors; behaviour lives in other packages.
package oscli
import (
"context"
"errors"
"fmt"
"io"
"github.com/urfave/cli/v2"
oserr "github.com/dsx-ai-factory/nvke/os-image/internal/errors"
)
// NewApp builds a CLI that keeps nvkr's usage contract at every level of the
// command tree. Each binary passes the verbs it ships, so build-only verbs
// never reach the node binary. Verbs add their own flags (--format, --verbose)
// rather than sharing global ones, as nvkr's do.
func NewApp(name, usage, version string, commands ...*cli.Command) *cli.App {
app := &cli.App{
Name: name,
Usage: usage,
Version: version,
HideHelpCommand: true,
OnUsageError: codedUsageError,
// Run owns the exit status; urfave/cli must not exit the process from
// inside a command (it does for an unknown help topic).
ExitErrHandler: func(*cli.Context, error) {},
Action: func(c *cli.Context) error {
if c.Args().Present() {
return oserr.New(oserr.CodeUsage, "unknown command %q", c.Args().First())
}
return cli.ShowAppHelp(c)
},
Commands: commands,
}
for _, command := range commands {
configureCommandUsage(command)
}
return app
}
// configureCommandUsage applies the usage contract to command and every
// subcommand: a bad flag or a stray argument is a coded usage error, and a verb
// that only groups subcommands rejects an unknown one instead of letting
// urfave/cli exit on its own. Required flags are checked in the action, not
// with urfave's Required, so a missing one is a coded usage error too.
func configureCommandUsage(command *cli.Command) {
command.OnUsageError = codedUsageError
if len(command.Subcommands) > 0 {
if command.Action == nil {
command.Action = func(c *cli.Context) error {
if c.Args().Present() {
return oserr.New(oserr.CodeUsage, "unknown %s subcommand %q", c.Command.Name, c.Args().First())
}
return cli.ShowSubcommandHelp(c)
}
}
for _, child := range command.Subcommands {
configureCommandUsage(child)
}
return
}
// urfave/cli ignores stray arguments; a leaf verb that declares none
// refuses them, as nvkectl's do with cobra.NoArgs.
if command.ArgsUsage == "" {
command.Before = chainRejectArgs(command.Before)
}
}
// Run executes app with args (args[0] is the program name), writes results to
// stdout and diagnostics to stderr, and returns the process exit status. Every
// failure carries a code: an uncoded error from a cancelled or timed-out run
// reports CodeTimeout, so a caller can retry it; urfave/cli's own exit errors
// (an unknown help topic) report CodeUsage; anything else reports CodeInternal.
func Run(ctx context.Context, app *cli.App, args []string, stdout, stderr io.Writer) int {
app.Writer, app.ErrWriter = stdout, stderr
err := app.RunContext(ctx, args)
var coded *oserr.Error
var exitCoder cli.ExitCoder
switch {
case err == nil || errors.As(err, &coded):
case ctx.Err() != nil || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded):
err = oserr.Wrap(oserr.CodeTimeout, err, "run canceled")
case errors.As(err, &exitCoder):
err = oserr.Wrap(oserr.CodeUsage, err, "invalid command usage")
default:
err = oserr.Wrap(oserr.CodeInternal, err, "command failed")
}
if err != nil {
fmt.Fprintf(stderr, "%s: %v\n", app.Name, err)
}
return oserr.ExitCode(err)
}
// chainRejectArgs refuses stray arguments before running the command's own
// Before, if it has one.
func chainRejectArgs(next cli.BeforeFunc) cli.BeforeFunc {
return func(c *cli.Context) error {
if c.Args().Present() {
return oserr.New(oserr.CodeUsage, "%s takes no arguments, got %q", c.Command.Name, c.Args().First())
}
if next != nil {
return next(c)
}
return nil
}
}
func codedUsageError(_ *cli.Context, err error, _ bool) error {
return oserr.Wrap(oserr.CodeUsage, err, "invalid command usage")
}
+181
View File
@@ -0,0 +1,181 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package oscli_test
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
oserr "github.com/dsx-ai-factory/nvke/os-image/internal/errors"
"github.com/dsx-ai-factory/nvke/os-image/internal/oscli"
)
func TestCommandLine(t *testing.T) {
tests := []struct {
name string
args []string
wantExit int
wantStdoutContains []string
wantStderrContains []string
wantStdoutEmpty bool
wantStderrEmpty bool
checkJSON bool
}{
{name: "version prints text", args: []string{"version"}, wantExit: 0, wantStdoutContains: []string{"v1.2.3"}, wantStderrEmpty: true},
{name: "version format json prints flat result", args: []string{"version", "--format", "json"}, wantExit: 0, wantStderrEmpty: true, checkJSON: true},
{name: "version format text prints text", args: []string{"version", "--format", "text"}, wantExit: 0, wantStdoutContains: []string{"nvke-os version v1.2.3"}, wantStderrEmpty: true},
{name: "root version flag prints text", args: []string{"--version"}, wantExit: 0, wantStdoutContains: []string{"v1.2.3"}, wantStderrEmpty: true},
{name: "root help lists commands", args: []string{"--help"}, wantExit: 0, wantStdoutContains: []string{"version", "manifest", "verify"}},
{name: "command help", args: []string{"version", "--help"}, wantExit: 0, wantStdoutContains: []string{"version", "--format"}},
{name: "manifest is unsupported", args: []string{"manifest"}, wantExit: 10, wantStdoutEmpty: true, wantStderrContains: []string{"NVKE-OS-E-UNSUPPORTED"}},
{name: "verify is unsupported", args: []string{"verify"}, wantExit: 10, wantStdoutEmpty: true, wantStderrContains: []string{"NVKE-OS-E-UNSUPPORTED"}},
{name: "unknown format is usage error", args: []string{"version", "--format", "yaml"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "global output flag is gone", args: []string{"-o", "json", "version"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "global log level flag is gone", args: []string{"--log-level", "debug", "version"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "unknown flag is usage error", args: []string{"--no-such-flag", "version"}, wantExit: 2, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "unknown command is usage error", args: []string{"frobnicate"}, wantExit: 2, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "version rejects positional args", args: []string{"version", "typo"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "manifest rejects positional args", args: []string{"manifest", "extra"}, wantExit: 2, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
{name: "help for a known command", args: []string{"--help", "version"}, wantExit: 0, wantStdoutContains: []string{"--format"}},
{name: "help for an unknown command is usage error", args: []string{"--help", "frobnicate"}, wantExit: 2, wantStderrContains: []string{"NVKE-OS-E-USAGE"}},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
app := oscli.NewApp("nvke-os", "test", "v1.2.3", oscli.VersionCommand(), oscli.ManifestCommand(), oscli.VerifyCommand())
var stdout, stderr bytes.Buffer
got := oscli.Run(context.Background(), app, append([]string{"nvke-os"}, tc.args...), &stdout, &stderr)
require.Equal(t, tc.wantExit, got, "stdout=%q stderr=%q", stdout.String(), stderr.String())
for _, s := range tc.wantStdoutContains {
require.Contains(t, stdout.String(), s)
}
for _, s := range tc.wantStderrContains {
require.Contains(t, stderr.String(), s)
}
if tc.wantStdoutEmpty {
require.Empty(t, stdout.String())
}
if tc.wantStderrEmpty {
require.Empty(t, stderr.String())
}
if tc.checkJSON {
var result struct {
SchemaVersion string `json:"schemaVersion"`
Name string `json:"name"`
Version string `json:"version"`
}
dec := json.NewDecoder(&stdout)
dec.DisallowUnknownFields()
require.NoError(t, dec.Decode(&result))
require.False(t, dec.More(), "stdout must hold exactly one JSON object")
require.Equal(t, "os.nvke.dev/version-result/v1", result.SchemaVersion)
require.Equal(t, "nvke-os", result.Name)
require.Equal(t, "v1.2.3", result.Version)
}
})
}
}
func TestCommandWithOwnBeforeStillRejectsArgs(t *testing.T) {
ran := false
command := &cli.Command{
Name: "probe",
Before: func(*cli.Context) error { ran = true; return nil },
Action: func(*cli.Context) error { return nil },
}
app := oscli.NewApp("nvke-os", "test", "v1.2.3", command)
var stdout, stderr bytes.Buffer
got := oscli.Run(context.Background(), app, []string{"nvke-os", "probe", "extra"}, &stdout, &stderr)
require.Equal(t, 2, got, "stderr=%q", stderr.String())
require.Contains(t, stderr.String(), "NVKE-OS-E-USAGE")
require.False(t, ran, "the command's Before must not run on rejected arguments")
}
// A verb with subcommands keeps the usage contract one level down: an unknown
// subcommand, a bad flag or a stray argument is a coded usage error, never
// urfave's own exit or a silently ignored argument.
func TestSubcommandUsageContract(t *testing.T) {
tests := []struct {
name string
args []string
wantExit int
wantRan bool
wantStdoutEmpty bool
wantStderrContains string
}{
{name: "subcommand runs", args: []string{"repo", "add"}, wantExit: 0, wantRan: true},
{name: "parent alone shows help", args: []string{"repo"}, wantExit: 0},
{name: "unknown subcommand is usage error", args: []string{"repo", "frobnicate"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: "NVKE-OS-E-USAGE"},
{name: "unknown subcommand flag is usage error", args: []string{"repo", "add", "--bogus"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: "NVKE-OS-E-USAGE"},
{name: "stray subcommand argument is usage error", args: []string{"repo", "add", "extra"}, wantExit: 2, wantStdoutEmpty: true, wantStderrContains: "NVKE-OS-E-USAGE"},
{name: "help subcommand for a known subcommand", args: []string{"repo", "help", "add"}, wantExit: 0},
{name: "help subcommand for an unknown subcommand is usage error", args: []string{"repo", "help", "frobnicate"}, wantExit: 2, wantStderrContains: "NVKE-OS-E-USAGE"},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ran := false
command := &cli.Command{
Name: "repo",
Subcommands: []*cli.Command{{
Name: "add",
Action: func(*cli.Context) error { ran = true; return nil },
}},
}
app := oscli.NewApp("nvke-os", "test", "v1.2.3", command)
var stdout, stderr bytes.Buffer
got := oscli.Run(context.Background(), app, append([]string{"nvke-os"}, tc.args...), &stdout, &stderr)
require.Equal(t, tc.wantExit, got, "stdout=%q stderr=%q", stdout.String(), stderr.String())
require.Equal(t, tc.wantRan, ran)
if tc.wantStdoutEmpty {
require.Empty(t, stdout.String())
}
require.Contains(t, stderr.String(), tc.wantStderrContains)
})
}
}
// A cancelled or timed-out run reports the retryable timeout status, as NVKR's
// ADR-03 classifies it, unless the verb already returned a coded error.
func TestCancelledRunExitsTimeout(t *testing.T) {
cancelled, cancel := context.WithCancel(context.Background())
cancel()
tests := []struct {
name string
ctx context.Context
err error
wantExit int
wantStderr string
}{
{name: "cancelled context and uncoded error", ctx: cancelled, err: errors.New("interrupted"), wantExit: 31},
{name: "deadline error from the verb", ctx: context.Background(), err: fmt.Errorf("probe: %w", context.DeadlineExceeded), wantExit: 31},
{name: "cancelled context keeps a coded error", ctx: cancelled, err: oserr.New(oserr.CodeUnsupported, "x"), wantExit: 10},
{name: "live context and uncoded error is internal", ctx: context.Background(), err: errors.New("boom"), wantExit: 1, wantStderr: "NVKE-OS-E-INTERNAL"},
{name: "cancelled context and success is success", ctx: cancelled, err: nil, wantExit: 0},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
command := &cli.Command{Name: "probe", Action: func(*cli.Context) error { return tc.err }}
app := oscli.NewApp("nvke-os", "test", "v1.2.3", command)
var stdout, stderr bytes.Buffer
got := oscli.Run(tc.ctx, app, []string{"nvke-os", "probe"}, &stdout, &stderr)
require.Equal(t, tc.wantExit, got, "stderr=%q", stderr.String())
require.Contains(t, stderr.String(), tc.wantStderr)
})
}
}
+22
View File
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package oscli
import (
"github.com/urfave/cli/v2"
oserr "github.com/dsx-ai-factory/nvke/os-image/internal/errors"
)
// ManifestCommand is a placeholder until #2202 lands; it exits with the
// unsupported code.
func ManifestCommand() *cli.Command {
return &cli.Command{
Name: "manifest",
Usage: "list the packages installed in an image or on this node (not implemented yet)",
Action: func(_ *cli.Context) error {
return oserr.New(oserr.CodeUnsupported, "manifest is not implemented yet")
},
}
}
+38
View File
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package oscli
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
oserr "github.com/dsx-ai-factory/nvke/os-image/internal/errors"
)
// formatFlag is the per-verb result format flag, as nvkr's verbs declare it.
func formatFlag() cli.Flag {
return &cli.StringFlag{Name: "format", Value: "text", Usage: "text or json"}
}
// writeResult writes one result to stdout as text, or as result's flat JSON
// object when --format is json. Each JSON result carries its own
// schemaVersion field.
func writeResult(c *cli.Context, result any, text string) error {
switch format := c.String("format"); format {
case "text":
_, err := fmt.Fprintln(c.App.Writer, text)
return err
case "json":
raw, err := json.Marshal(result)
if err != nil {
return oserr.Wrap(oserr.CodeInternal, err, "encoding %s result", c.Command.Name)
}
_, err = fmt.Fprintf(c.App.Writer, "%s\n", raw)
return err
default:
return oserr.New(oserr.CodeUsage, "--format must be text or json, got %q", format)
}
}
+22
View File
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package oscli
import (
"github.com/urfave/cli/v2"
oserr "github.com/dsx-ai-factory/nvke/os-image/internal/errors"
)
// VerifyCommand is a placeholder until #2205 lands; it exits with the
// unsupported code.
func VerifyCommand() *cli.Command {
return &cli.Command{
Name: "verify",
Usage: "compare an image or this node with the lock (not implemented yet)",
Action: func(_ *cli.Context) error {
return oserr.New(oserr.CodeUnsupported, "verify is not implemented yet")
},
}
}
+29
View File
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package oscli
import "github.com/urfave/cli/v2"
// VersionResultSchema versions the version verb's JSON result. A breaking
// change to its shape moves it.
const VersionResultSchema = "os.nvke.dev/version-result/v1"
type versionResult struct {
SchemaVersion string `json:"schemaVersion"`
Name string `json:"name"`
Version string `json:"version"`
}
// VersionCommand prints the binary's stamped version.
func VersionCommand() *cli.Command {
return &cli.Command{
Name: "version",
Usage: "print the version",
Flags: []cli.Flag{formatFlag()},
Action: func(c *cli.Context) error {
result := versionResult{SchemaVersion: VersionResultSchema, Name: c.App.Name, Version: c.App.Version}
return writeResult(c, result, result.Name+" version "+result.Version)
},
}
}