Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f7ec554
WIP package resource property definition
JohnMcPMS Apr 1, 2025
a8efbae
Package resource property parity
JohnMcPMS Apr 2, 2025
6391e1b
Localization for property descriptions
JohnMcPMS Apr 2, 2025
71c6e8f
Get maybe implemented?
JohnMcPMS Apr 3, 2025
fe3139e
working on test; refactoring to use COM code for update availability
JohnMcPMS Apr 10, 2025
d2aff39
Move ManifestComparator; package resource ready for set action impl
JohnMcPMS Apr 15, 2025
4f3f27a
package resource CC; working on making input better
JohnMcPMS Apr 15, 2025
9e2c111
Use input handle type to determine if we should attempt to read from it
JohnMcPMS Apr 16, 2025
b5f1a04
Merge from master
JohnMcPMS Apr 16, 2025
7e4c8c8
Change name of refactored method to match updates
JohnMcPMS Apr 16, 2025
e522095
Revert solution change
JohnMcPMS Apr 16, 2025
468b6d5
Add E2E tests for package resource
JohnMcPMS Apr 17, 2025
7f9820e
Fix copy-pasta property name; use package resource to ensure cleanup
JohnMcPMS Apr 17, 2025
2b46b16
Test fixes
JohnMcPMS Apr 17, 2025
1ad6b70
Test fixes
JohnMcPMS Apr 21, 2025
62f6aee
Add more logging; add correlation param
JohnMcPMS Apr 21, 2025
b80d0e7
Work on test fixes
JohnMcPMS Apr 22, 2025
073d30c
Remove scope from resource
JohnMcPMS Apr 22, 2025
0a0d4ba
Fix for reinstall and set output not expecting useLatest; more loggin…
JohnMcPMS Apr 23, 2025
a2c2284
Ignore latest more, given empty input rather than null so that the pi…
JohnMcPMS Apr 23, 2025
116124d
Non-empty required
JohnMcPMS Apr 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AppInstallerCLICore/AppInstallerCLICore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
<ClInclude Include="Commands\DscCommand.h" />
<ClInclude Include="Commands\DscCommandBase.h" />
<ClInclude Include="Commands\DscComposableObject.h" />
<ClInclude Include="Commands\DscPackageResource.h" />
<ClInclude Include="Commands\DscTestFileResource.h" />
<ClInclude Include="Commands\DscTestJsonResource.h" />
<ClInclude Include="Commands\ErrorCommand.h" />
Expand Down Expand Up @@ -369,7 +370,6 @@
<ClInclude Include="Workflows\SettingsFlow.h" />
<ClInclude Include="Workflows\ShellExecuteInstallerHandler.h" />
<ClInclude Include="Workflows\InstallFlow.h" />
<ClInclude Include="Workflows\ManifestComparator.h" />
<ClInclude Include="Workflows\ResumeFlow.h" />
<ClInclude Include="Workflows\ShowFlow.h" />
<ClInclude Include="Workflows\SourceFlow.h" />
Expand All @@ -391,6 +391,7 @@
<ClCompile Include="Commands\DscCommand.cpp" />
<ClCompile Include="Commands\DscCommandBase.cpp" />
<ClCompile Include="Commands\DscComposableObject.cpp" />
<ClCompile Include="Commands\DscPackageResource.cpp" />
<ClCompile Include="Commands\DscTestFileResource.cpp" />
<ClCompile Include="Commands\DscTestJsonResource.cpp" />
<ClCompile Include="Commands\ErrorCommand.cpp" />
Expand Down Expand Up @@ -456,7 +457,6 @@
<ClCompile Include="Workflows\SettingsFlow.cpp" />
<ClCompile Include="Workflows\ShellExecuteInstallerHandler.cpp" />
<ClCompile Include="Workflows\InstallFlow.cpp" />
<ClCompile Include="Workflows\ManifestComparator.cpp" />
<ClCompile Include="Workflows\ResumeFlow.cpp" />
<ClCompile Include="Workflows\ShowFlow.cpp" />
<ClCompile Include="Workflows\SourceFlow.cpp" />
Expand Down
12 changes: 6 additions & 6 deletions src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<ClInclude Include="Workflows\InstallFlow.h">
<Filter>Workflows</Filter>
</ClInclude>
<ClInclude Include="Workflows\ManifestComparator.h">
<Filter>Workflows</Filter>
</ClInclude>
<ClInclude Include="Workflows\ShellExecuteInstallerHandler.h">
<Filter>Workflows</Filter>
</ClInclude>
Expand Down Expand Up @@ -284,6 +281,9 @@
<ClInclude Include="Commands\DscTestJsonResource.h">
<Filter>Commands\Configuration</Filter>
</ClInclude>
<ClInclude Include="Commands\DscPackageResource.h">
<Filter>Commands\Configuration</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
Expand All @@ -301,9 +301,6 @@
<ClCompile Include="Core.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Workflows\ManifestComparator.cpp">
<Filter>Workflows</Filter>
</ClCompile>
<ClCompile Include="Workflows\ShellExecuteInstallerHandler.cpp">
<Filter>Workflows</Filter>
</ClCompile>
Expand Down Expand Up @@ -535,6 +532,9 @@
<ClCompile Include="Commands\DscTestJsonResource.cpp">
<Filter>Commands\Configuration</Filter>
</ClCompile>
<ClCompile Include="Commands\DscPackageResource.cpp">
<Filter>Commands\Configuration</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ namespace AppInstaller::CLI
return { type, "force"_liv, ArgTypeCategory::CopyFlagToSubContext };
case Execution::Args::Type::OutputFile:
return { type, "output"_liv, 'o' };
case Execution::Args::Type::Correlation:
return { type, "correlation"_liv };

case Execution::Args::Type::DependencySource:
return { type, "dependency-source"_liv, ArgTypeCategory::ExtendedSource };
Expand Down Expand Up @@ -468,6 +470,8 @@ namespace AppInstaller::CLI
return Argument{ type, Resource::String::NoProxyArgumentDescription, ArgumentType::Flag, TogglePolicy::Policy::ProxyCommandLineOptions, BoolAdminSetting::ProxyCommandLineOptions };
case Args::Type::Family:
return Argument{ type, Resource::String::FontFamilyNameArgumentDescription, ArgumentType::Positional, false };
case Args::Type::Correlation:
return Argument{ type, Resource::String::CorrelationArgumentDescription, ArgumentType::Standard, Argument::Visibility::Hidden };
default:
THROW_HR(E_UNEXPECTED);
}
Expand All @@ -486,6 +490,7 @@ namespace AppInstaller::CLI
args.emplace_back(Args::Type::DisableInteractivity, Resource::String::DisableInteractivityArgumentDescription, ArgumentType::Flag, false);
args.push_back(ForType(Args::Type::Proxy));
args.push_back(ForType(Args::Type::NoProxy));
args.push_back(ForType(Args::Type::Correlation));
}

std::string Argument::GetUsageString() const
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCLICore/Commands/DscCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
#include "pch.h"
#include "DscCommand.h"
#include "DscPackageResource.h"

#ifndef AICLI_DISABLE_TEST_HOOKS
#include "DscTestFileResource.h"
Expand All @@ -13,6 +14,7 @@ namespace AppInstaller::CLI
std::vector<std::unique_ptr<Command>> DscCommand::GetCommands() const
{
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
std::make_unique<DscPackageResource>(FullName()),
#ifndef AICLI_DISABLE_TEST_HOOKS
std::make_unique<DscTestFileResource>(FullName()),
std::make_unique<DscTestJsonResource>(FullName()),
Expand Down
33 changes: 24 additions & 9 deletions src/AppInstallerCLICore/Commands/DscCommandBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DscCommandBase.h"
#include "DscCommand.h"
#include <winget/Runtime.h>
#include <winget/StdErrLogger.h>

#define WINGET_DSC_FUNCTION_FOREACH(_macro_) \
_macro_(Get); \
Expand Down Expand Up @@ -201,8 +202,7 @@ namespace AppInstaller::CLI
void DscCommandBase::ExecuteInternal(Execution::Context& context) const
{
context.Reporter.SetChannel(Execution::Reporter::Channel::Json);

// TODO: Consider adding a stderr logger
Logging::StdErrLogger::Add();

#define WINGET_DSC_FUNCTION_ARGUMENT(_function_) \
if (context.Args.Contains(Execution::Args::Type::DscResourceFunction ## _function_)) \
Expand Down Expand Up @@ -266,18 +266,33 @@ namespace AppInstaller::CLI

#undef WINGET_DSC_FUNCTION_METHOD

std::optional<Json::Value> DscCommandBase::GetJsonFromInput(Execution::Context& context) const
std::optional<Json::Value> DscCommandBase::GetJsonFromInput(Execution::Context& context, bool terminateContextOnError) const
{
Json::Value result;
Json::CharReaderBuilder builder;
Json::String errors;
if (!Json::parseFromStream(builder, context.Reporter.RawInputStream(), &result, &errors))
// Don't attempt to read from an interactive stream as this will just block
if (!context.Reporter.InputStreamIsInteractive())
{
AICLI_LOG(CLI, Verbose, << "Reading Json from input stream...");

Json::Value result;
Json::CharReaderBuilder builder;
Json::String errors;
if (Json::parseFromStream(builder, context.Reporter.RawInputStream(), &result, &errors))
{
AICLI_LOG(CLI, Info, << "Json from input stream:\n" << Json::writeString(Json::StreamWriterBuilder{}, result));
return result;
}

AICLI_LOG(CLI, Error, << "Failed to read input JSON: " << errors);
AICLI_TERMINATE_CONTEXT_RETURN(APPINSTALLER_CLI_ERROR_JSON_INVALID_FILE, std::nullopt);
}

return result;
if (terminateContextOnError)
{
AICLI_TERMINATE_CONTEXT_RETURN(APPINSTALLER_CLI_ERROR_JSON_INVALID_FILE, std::nullopt);
}
else
{
return std::nullopt;
}
}

void DscCommandBase::WriteJsonOutputLine(Execution::Context& context, const Json::Value& value) const
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Commands/DscCommandBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace AppInstaller::CLI
virtual void ResourceFunctionManifest(Execution::Context& context) const;

// Parses a JSON object from stdin.
std::optional<Json::Value> GetJsonFromInput(Execution::Context& context) const;
std::optional<Json::Value> GetJsonFromInput(Execution::Context& context, bool terminateContextOnError = true) const;

// Writes the value to the context output.
void WriteJsonOutputLine(Execution::Context& context, const Json::Value& value) const;
Expand Down
56 changes: 53 additions & 3 deletions src/AppInstallerCLICore/Commands/DscComposableObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@

namespace AppInstaller::CLI
{
namespace
{
std::string GetTypeString(Json::ValueType type)
{
switch (type)
{
case Json::nullValue:
return "null";
case Json::intValue:
case Json::uintValue:
case Json::realValue:
return "number";
case Json::stringValue:
return "string";
case Json::booleanValue:
return "boolean";
case Json::arrayValue:
return "array";
case Json::objectValue:
return "object";
default:
THROW_HR(E_UNEXPECTED);
}
}
}

namespace details
{
const Json::Value* GetProperty(const Json::Value& object, std::string_view name)
Expand Down Expand Up @@ -32,7 +58,14 @@ namespace AppInstaller::CLI
return result;
}

void AddPropertySchema(Json::Value& object, std::string_view name, DscComposablePropertyFlag flags, std::string_view type, std::string_view description)
void AddPropertySchema(
Json::Value& object,
std::string_view name,
DscComposablePropertyFlag flags,
Json::ValueType type,
std::string_view description,
const std::vector<std::string>& enumValues,
const std::optional<std::string>& defaultValue)
{
Json::Value& propertiesObject = object["properties"];

Expand All @@ -45,13 +78,30 @@ namespace AppInstaller::CLI

Json::Value property{ Json::ValueType::objectValue };

if (!type.empty())
if (type != Json::ValueType::objectValue)
{
property["type"] = std::string{ type };
property["type"] = GetTypeString(type);
}

property["description"] = std::string{ description };

if (!enumValues.empty())
{
Json::Value enumArray{ Json::ValueType::arrayValue };

for (const std::string& enumValue : enumValues)
{
enumArray.append(enumValue);
}

property["enum"] = std::move(enumArray);
}

if (defaultValue)
{
property["default"] = defaultValue.value();
}

propertiesObject[nameString] = std::move(property);

if (WI_IsFlagSet(flags, DscComposablePropertyFlag::Required))
Expand Down
Loading