ValidateCommand.cpp (3002B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "ValidateCommand.h" 5 #include "Workflows/WorkflowBase.h" 6 #include "Workflows/DependenciesFlow.h" 7 #include "Resources.h" 8 #include <winget/ManifestYamlParser.h> 9 10 namespace AppInstaller::CLI 11 { 12 using namespace std::string_view_literals; 13 using namespace AppInstaller::Manifest; 14 15 std::vector<Argument> ValidateCommand::GetArguments() const 16 { 17 return { 18 Argument::ForType(Execution::Args::Type::ValidateManifest), 19 }; 20 } 21 22 Resource::LocString ValidateCommand::ShortDescription() const 23 { 24 return Resource::LocString{ Resource::String::ValidateCommandShortDescription }; 25 } 26 27 Resource::LocString ValidateCommand::LongDescription() const 28 { 29 return Resource::LocString{ Resource::String::ValidateCommandLongDescription }; 30 } 31 32 Utility::LocIndView ValidateCommand::HelpLink() const 33 { 34 return "https://aka.ms/winget-command-validate"_liv; 35 } 36 37 void ValidateCommand::ExecuteInternal(Execution::Context& context) const 38 { 39 context << 40 Workflow::VerifyPath(Execution::Args::Type::ValidateManifest) << 41 [](Execution::Context& context) 42 { 43 auto inputFile = Utility::ConvertToUTF16(context.Args.GetArg(Execution::Args::Type::ValidateManifest)); 44 45 try 46 { 47 ManifestValidateOption validateOption; 48 validateOption.FullValidation = true; 49 validateOption.SchemaHeaderValidationAsWarning = true; 50 validateOption.ThrowOnWarning = !(context.Args.Contains(Execution::Args::Type::IgnoreWarnings)); 51 auto manifest = YamlParser::CreateFromPath(inputFile, validateOption); 52 53 context.Add<Execution::Data::Manifest>(manifest); 54 context << 55 Workflow::GetInstallersDependenciesFromManifest << 56 Workflow::ReportDependencies(Resource::String::ValidateCommandReportDependencies); 57 58 context.Reporter.Info() << Resource::String::ManifestValidationSuccess << std::endl; 59 } 60 catch (const ManifestException& e) 61 { 62 HRESULT hr = S_OK; 63 if (e.IsWarningOnly()) 64 { 65 context.Reporter.Warn() << Resource::String::ManifestValidationWarning << std::endl; 66 hr = APPINSTALLER_CLI_ERROR_MANIFEST_VALIDATION_WARNING; 67 } 68 else 69 { 70 context.Reporter.Error() << Resource::String::ManifestValidationFail << std::endl; 71 hr = APPINSTALLER_CLI_ERROR_MANIFEST_VALIDATION_FAILURE; 72 } 73 74 context.Reporter.Info() << e.GetManifestErrorMessage() << std::endl; 75 AICLI_TERMINATE_CONTEXT(hr); 76 } 77 }; 78 } 79 }