feat(kvp): add libazureinit-kvp CLI#309
Conversation
Replace the handwritten libazureinit-kvp argument parser with clap-derived command and option parsing. Keep existing command behavior, including numeric pool aliases, while adding generated help output and validation. Expose the CLI through the library run entrypoint, add a binary main, and expand CLI integration coverage for help, metadata, read/write/load/delete/clear flows, stdin loading, missing keys, and validation errors.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #309 +/- ##
==========================================
+ Coverage 94.78% 95.32% +0.53%
==========================================
Files 19 21 +2
Lines 6348 7076 +728
==========================================
+ Hits 6017 6745 +728
Misses 331 331 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| Some(dir) => KvpPoolStore::new_in(pool, dir, mode), | ||
| None => KvpPoolStore::new(pool, mode), | ||
| } | ||
| .expect("KvpPoolStore construction is currently infallible"); |
There was a problem hiding this comment.
I originally had just a simple ? since it can't fail, but that breaks the cargo-llvm coverage since it introduces a new path that we can't actually hit. This was the alternative solution lol
cjp256
left a comment
There was a problem hiding this comment.
load actually sounds better than populate. maybe we should rename populate too.
i think --yes is overkill for clear. None of this data is sacred and generally overwritten on reboot.
--json will be useful for outputs I think. entries key=value gets awkward if there are newlines unless we encode it, etc.
- Rename KvpPoolStore::populate (and Command::Load) to load. - Drop --yes from clear; --if-stale unchanged. - Add global --json flag with machine-readable output for info, dump, entries, read, delete, delete-multiple, and is-stale. Adds serde_json. - Consolidate tests: merge the two clear dispatch tests into one rstest, fold --json parse assertions into existing globals/defaults tests, and drop redundant JSON tests already covered elsewhere.
Addressed all of these in the latest commit! I was trying to avoid adding too many dependencies to keep the size minimal but I agree that --json would be super helpful to have. I also like |
Summary
Adds a
libazureinit-kvpcommand-line interface around the existing KVP store APIs, supporting development, debugging, and operational workflows against Azure/Hyper-V KVP pool files. The CLI can inspect pool metadata, read/write/delete records, bulk-load records, clear stale data, and check staleness.Adds
clap(derive) as a direct dependency onlibazureinit-kvp.Usage
The CLI operates on one pool at a time. Defaults: pool
guest, safe mode, default Hyper-V KVP directory.Global options (valid with any command):
--pool <POOL>—external/0,guest/1,auto/2,auto-external/3,auto-internal/4--dir <PATH>— pool directory--unsafe— use the full wire-format key/value limits instead of the safe profileCommands
infodumpKEY=VALUE; duplicates preserved.entriesKEY=VALUEper key (last value wins), sorted by key.read <KEY>1if missing.write [--append] <KEY> <VALUE>KEYunless--appendis set.load [--file PATH]KEY=VALUElines (file or stdin).delete <KEY>true/false.clear [--yes] [--if-stale]--yesunless--if-staleis set.is-stale0if stale,1if not.Examples:
Exit codes
0— success1— not found / false status (missing key,is-stale=false)2— usage or validation error3— I/O errorKVP store validation errors surface as CLI errors on stderr.
readof a missing key writes nothing to stderr.Test Coverage