commit 4bb67d7692da3aa5c3c7e42c39169f87110e7923
parent 87a0c21b422ce97d50bd1e90affef13d65c5c651
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date: Thu, 2 Apr 2020 17:11:01 -0700
Add manifest validation command (#77)
Diffstat:
7 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj b/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj
@@ -180,6 +180,7 @@
<ClInclude Include="Commands\InstallCommand.h" />
<ClInclude Include="Commands\RootCommand.h" />
<ClInclude Include="Commands\SourceCommand.h" />
+ <ClInclude Include="Commands\ValidateCommand.h" />
<ClInclude Include="ExecutionArgs.h" />
<ClInclude Include="ExecutionContext.h" />
<ClInclude Include="ExecutionReporter.h" />
@@ -208,6 +209,7 @@
<ClCompile Include="Commands\InstallCommand.cpp" />
<ClCompile Include="Commands\RootCommand.cpp" />
<ClCompile Include="Commands\SourceCommand.cpp" />
+ <ClCompile Include="Commands\ValidateCommand.cpp" />
<ClCompile Include="Core.cpp" />
<ClCompile Include="ExecutionReporter.cpp" />
<ClCompile Include="pch.cpp">
diff --git a/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters b/src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters
@@ -102,6 +102,9 @@
<ClInclude Include="Argument.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Commands\ValidateCommand.h">
+ <Filter>Commands</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
@@ -164,6 +167,9 @@
<ClCompile Include="Argument.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Commands\ValidateCommand.cpp">
+ <Filter>Commands</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp
@@ -60,6 +60,8 @@ namespace AppInstaller::CLI
return Argument{ "versions", None, Args::Type::ListVersions, LOCME("Show available versions of the app"), ArgumentType::Flag };
case Args::Type::Help:
return Argument{ "help", APPINSTALLER_CLI_HELP_ARGUMENT_TEXT_CHAR, Args::Type::Help, LOCME("Shows help about the selected command"), ArgumentType::Flag };
+ case Args::Type::ValidateManifest:
+ return Argument{ "manifest", None, Args::Type::ValidateManifest, LOCME("The path to the manifest to be validated"), ArgumentType::Positional, true };
default:
THROW_HR(E_UNEXPECTED);
}
diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp
@@ -9,6 +9,7 @@
#include "SourceCommand.h"
#include "SearchCommand.h"
#include "HashCommand.h"
+#include "ValidateCommand.h"
namespace AppInstaller::CLI
{
@@ -20,6 +21,7 @@ namespace AppInstaller::CLI
std::make_unique<SourceCommand>(FullName()),
std::make_unique<SearchCommand>(FullName()),
std::make_unique<HashCommand>(FullName()),
+ std::make_unique<ValidateCommand>(FullName()),
});
}
diff --git a/src/AppInstallerCLICore/Commands/ValidateCommand.cpp b/src/AppInstallerCLICore/Commands/ValidateCommand.cpp
@@ -0,0 +1,50 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "pch.h"
+#include "ValidateCommand.h"
+#include "Localization.h"
+
+namespace AppInstaller::CLI
+{
+ using namespace std::string_view_literals;
+
+ std::vector<Argument> ValidateCommand::GetArguments() const
+ {
+ return {
+ Argument::ForType(Execution::Args::Type::ValidateManifest),
+ };
+ }
+
+ std::string ValidateCommand::ShortDescription() const
+ {
+ return LOCME("Validates a manifest file");
+ }
+
+ std::string ValidateCommand::GetLongDescription() const
+ {
+ return LOCME("Validates a manifest using a strict set of guidelines. This is intended to enable you to check your manifest before submitting to a repo.");
+ }
+
+ void ValidateCommand::ExecuteInternal(Execution::Context& context) const
+ {
+ auto inputFile = context.Args.GetArg(Execution::Args::Type::ValidateManifest);
+
+ if (!std::filesystem::exists(inputFile))
+ {
+ AICLI_LOG(CLI, Error, << "Input file does not exist. Path: " << inputFile);
+ context.Reporter.Error() << "The input manifest file does not exist. Path: " << inputFile << std::endl;
+ return;
+ }
+
+ try
+ {
+ Manifest::Manifest::CreateFromPath(inputFile, true);
+ context.Reporter.Info() << "Manifest validation succeeded." << std::endl;
+ }
+ catch (const Manifest::ManifestException& e)
+ {
+ context.Reporter.Warn() << "Manifest validation failed." << std::endl;
+ context.Reporter.Warn() << e.GetManifestErrorMessage() << std::endl;
+ }
+ }
+}
diff --git a/src/AppInstallerCLICore/Commands/ValidateCommand.h b/src/AppInstallerCLICore/Commands/ValidateCommand.h
@@ -0,0 +1,20 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#pragma once
+#include "Command.h"
+
+namespace AppInstaller::CLI
+{
+ struct ValidateCommand final : public Command
+ {
+ ValidateCommand(std::string_view parent) : Command("validate", parent) {}
+
+ virtual std::vector<Argument> GetArguments() const override;
+
+ virtual std::string ShortDescription() const override;
+ virtual std::string GetLongDescription() const override;
+
+ protected:
+ void ExecuteInternal(Execution::Context& context) const override;
+ };
+}
diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h
@@ -47,6 +47,9 @@ namespace AppInstaller::CLI::Execution
HashFile,
Msix, // Flag to indicate the input file is msix
+ //Validate Command
+ ValidateManifest,
+
// Other
ListVersions, // Used in Show command to list all available versions of an app
Help, // Show command usage