diff --git a/src/AppInstallerCLICore/Commands/DumpJsonCommand.cpp b/src/AppInstallerCLICore/Commands/DumpJsonCommand.cpp new file mode 100644 index 0000000000..7028e37f79 --- /dev/null +++ b/src/AppInstallerCLICore/Commands/DumpJsonCommand.cpp @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#include "pch.h" +#include "DumpJsonCommand.h" +#include "Workflows/CompletionFlow.h" +#include "Workflows/ImportExportFlow.h" +#include "Workflows/WorkflowBase.h" +#include "Resources.h" + +namespace AppInstaller::CLI +{ + using namespace std::string_view_literals; + + std::vector DumpJsonCommand::GetArguments() const + { + return { + Argument{ "output", 'o', Execution::Args::Type::OutputFile, Resource::String::OutputFileArgumentDescription, ArgumentType::Positional, true }, + Argument{ "source", 's', Execution::Args::Type::Source, Resource::String::ExportSourceArgumentDescription, ArgumentType::Standard }, + Argument{ "include-versions", Argument::NoAlias, Execution::Args::Type::IncludeVersions, Resource::String::ExportIncludeVersionsArgumentDescription, ArgumentType::Flag }, + Argument::ForType(Execution::Args::Type::AcceptSourceAgreements), + }; + } + + Resource::LocString DumpJsonCommand::ShortDescription() const + { + return { Resource::String::DumpJsonCommandShortDescription }; + } + + Resource::LocString DumpJsonCommand::LongDescription() const + { + return { Resource::String::DumpJsonCommandLongDescription }; + } + + void DumpJsonCommand::Complete(Execution::Context& context, Execution::Args::Type valueType) const + { + if (valueType == Execution::Args::Type::OutputFile) + { + // Intentionally output nothing to allow pass through to filesystem. + return; + } + + if (valueType == Execution::Args::Type::Source) + { + context << Workflow::CompleteSourceName; + return; + } + } + + std::string DumpJsonCommand::HelpLink() const + { + // TODO: Link? + return ""; + } + + void DumpJsonCommand::ExecuteInternal(Execution::Context& context) const + { + context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning); + + context << + Workflow::ReportExecutionStage(Workflow::ExecutionStage::Discovery) << + Workflow::OpenSource() << + Workflow::SearchSourceForMany << + Workflow::HandleSearchResultFailures << + Workflow::SelectVersionsToExport << + Workflow::ReportExecutionStage(Workflow::ExecutionStage::Execution) << + Workflow::WriteImportFile; + } +} diff --git a/src/AppInstallerCLICore/Commands/DumpJsonCommand.h b/src/AppInstallerCLICore/Commands/DumpJsonCommand.h new file mode 100644 index 0000000000..de4021b8a6 --- /dev/null +++ b/src/AppInstallerCLICore/Commands/DumpJsonCommand.h @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +#pragma once +#include "Command.h" + +namespace AppInstaller::CLI +{ + + struct DumpJsonCommand final : public Command + { + DumpJsonCommand(std::string_view parent) : Command("dump-json", parent) {} + + std::vector GetArguments() const override; + + Resource::LocString ShortDescription() const override; + Resource::LocString LongDescription() const override; + + void Complete(Execution::Context& context, Execution::Args::Type valueType) const override; + + std::string HelpLink() const override; + + protected: + void ValidateArgumentsInternal(Execution::Args& execArgs) const override; + void ExecuteInternal(Execution::Context& context) const override; + }; +} diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp index ebf081e4df..c033edfe24 100644 --- a/src/AppInstallerCLICore/Commands/RootCommand.cpp +++ b/src/AppInstallerCLICore/Commands/RootCommand.cpp @@ -18,6 +18,7 @@ #include "CompleteCommand.h" #include "ExportCommand.h" #include "ImportCommand.h" +#include "DumpJsonCommand.h" #include "PinCommand.h" #include "Resources.h" @@ -128,6 +129,7 @@ namespace AppInstaller::CLI std::make_unique(FullName()), std::make_unique(FullName()), std::make_unique(FullName()), + std::make_unique(FullName()), std::make_unique(FullName()), }); }