-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CLI: Initialize template support #40195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AmelBawa-msft
wants to merge
15
commits into
feature/wsl-for-apps
Choose a base branch
from
user/amelbawa/format-template
base: feature/wsl-for-apps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+323
−52
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1d2b390
Init template support
AmelBawa-msft 6189485
Clang format
AmelBawa-msft 90f800f
Addressed comments
AmelBawa-msft 1b06ed8
Code enhancement
AmelBawa-msft e3fdd17
Code enhancement
AmelBawa-msft f331dbb
Include render.go
AmelBawa-msft 99fb198
COde enhancement
AmelBawa-msft 3304aaa
code enhancement
AmelBawa-msft b254595
Clang format
AmelBawa-msft 5dc677e
optimize
AmelBawa-msft 000d50d
Added render
AmelBawa-msft 8682170
Addressed comments
AmelBawa-msft 45e804a
Addressed comments
AmelBawa-msft 78872a9
Added tests
AmelBawa-msft b46d656
Clang format
AmelBawa-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| TemplateRenderer.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of the Go template renderer. | ||
|
|
||
|
AmelBawa-msft marked this conversation as resolved.
|
||
| --*/ | ||
|
|
||
| #include "TemplateRenderer.h" | ||
| #include <string> | ||
|
|
||
| // Forward-declare the Go template renderer functions (exported from render.dll). | ||
| // We declare these directly instead of including the cgo-generated render.h | ||
| // to avoid Go boilerplate types that don't compile cleanly with MSVC. | ||
| extern "C" { | ||
| int TryRenderGoTemplate(const char* templateStr, const char* jsonData, char** output); | ||
| void FreeGoString(char* ptr); | ||
| } | ||
|
|
||
| namespace wsl::windows::wslc::core { | ||
|
|
||
| using namespace wsl::shared::string; | ||
|
|
||
| TemplateRenderer::RenderResult TemplateRenderer::TryRender(const std::string& templateStr, const std::string& jsonData, std::wstring& output) | ||
| { | ||
| try | ||
| { | ||
| char* rawOutput = nullptr; | ||
| auto success = TryRenderGoTemplate(templateStr.c_str(), jsonData.c_str(), &rawOutput); | ||
|
|
||
|
AmelBawa-msft marked this conversation as resolved.
|
||
| std::string result(rawOutput ? rawOutput : ""); | ||
| FreeGoString(rawOutput); | ||
|
|
||
| output = MultiByteToWide(result); | ||
| return static_cast<RenderResult>(success); | ||
| } | ||
| catch (const std::exception& ex) | ||
| { | ||
| output = MultiByteToWide(ex.what()); | ||
| return RenderResult::Fail_Unknown; | ||
| } | ||
| } | ||
|
|
||
| void TemplateRenderer::Render(const std::string& templateStr, const std::string& jsonData, std::wstring& output) | ||
| { | ||
| switch (TryRender(templateStr, jsonData, output)) | ||
| { | ||
| case RenderResult::Success: | ||
| return; | ||
| case RenderResult::Fail_NullPointer: | ||
| THROW_HR(E_POINTER); | ||
| case RenderResult::Fail_ParseJSON: | ||
| case RenderResult::Fail_ParseTemplate: | ||
| case RenderResult::Fail_ExecuteTemplate: | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, output); | ||
| case RenderResult::Fail_Unknown: | ||
| default: | ||
| THROW_HR(E_UNEXPECTED); | ||
| } | ||
| } | ||
|
|
||
| } // namespace wsl::windows::wslc::core | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| TemplateRenderer.h | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains the interface for rendering Go templates with JSON data. | ||
|
|
||
| --*/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace wsl::windows::wslc::core { | ||
|
|
||
| struct TemplateRenderer | ||
| { | ||
| enum class RenderResult | ||
| { | ||
| Success = 0, | ||
| Fail_NullPointer = 1, | ||
| Fail_ParseJSON = 2, | ||
| Fail_ParseTemplate = 3, | ||
| Fail_ExecuteTemplate = 4, | ||
|
|
||
| // All other failures | ||
| Fail_Unknown = -1, | ||
| }; | ||
|
|
||
| static RenderResult TryRender(const std::string& templateStr, const std::string& jsonData, std::wstring& output); | ||
| static void Render(const std::string& templateStr, const std::string& jsonData, std::wstring& output); | ||
| }; | ||
|
|
||
| } // namespace wsl::windows::wslc::core |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| LIBRARY render | ||
|
|
||
| EXPORTS | ||
| TryRenderGoTemplate | ||
| FreeGoString | ||
|
AmelBawa-msft marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.