CLI: Initialize template support#40195
CLI: Initialize template support#40195AmelBawa-msft wants to merge 15 commits intofeature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds initial “template” output support to the WSLC CLI by introducing a Go-based template renderer (built as a Windows DLL) and wiring it into wslc container list --format ... so users can format container output beyond table and json.
Changes:
- Add
FormatType::Templateand updatecontainer listto render per-container output via a newTemplateRendererbridge. - Introduce a Go
c-sharedDLL (render.dll) exposingRenderGoTemplate/FreeMemory, plus CMake build steps to build/link/copy it. - Relax
--formatparsing so values other thanjson/tablemap to template mode.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/wslc/tools/gotemplate/render.go | Go c-shared implementation that parses JSON and executes a Go text/template. |
| src/windows/wslc/tools/gotemplate/render.def | Export list for the Go-built DLL functions. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Adds FormatType::Template handling for container list to render templates per container. |
| src/windows/wslc/services/ContainerModel.h | Extends FormatType enum with Template. |
| src/windows/wslc/core/TemplateRenderer.h | Declares C++ wrapper API for template rendering. |
| src/windows/wslc/core/TemplateRenderer.cpp | Implements the C++ ↔ Go bridge and error handling. |
| src/windows/wslc/commands/ContainerListCommand.cpp | Removes command-specific format validation (now relies on common validation). |
| src/windows/wslc/commands/ContainerCommand.h | Removes ValidateArgumentsInternal override declaration for container list. |
| src/windows/wslc/arguments/ArgumentValidation.cpp | Changes format parsing to return Template for non-json/table values. |
| src/windows/wslc/CMakeLists.txt | Adds custom build/link/copy steps to build the Go template renderer DLL and link it into wslc. |
| // On failure, *output contains the error message. The caller must free *output with FreeGoString. | ||
| // | ||
| //export TryRenderGoTemplate | ||
| func TryRenderGoTemplate(templateStr *C.char, jsonData *C.char, output **C.char) C.int { |
There was a problem hiding this comment.
This is clever ! If we easily call into a go dll, this makes supporting templates a lot easier.
One thing I'll recommend though is that given that are most likely not going to make changes to that dll very often, would to build it separately in https://github.com/microsoft/WSL-deps and consume via a nuget package, so that we don't need to rebuild it locally on every build
There was a problem hiding this comment.
It will also probably be easier to build the dll in that repo, since we can use msbuild directly and not have to go through cmake
|
FreeGoString(rawOutput) is called unconditionally without null check, and if TryRenderGoTemplate throws, rawOutput leaks. Use a wil::scope_exit for cleanup. |
Summary of the Pull Request
Enable using Go templates from C++
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed