winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ExportCommand.cpp (2561B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "ExportCommand.h"
      5 #include "Workflows/CompletionFlow.h"
      6 #include "Workflows/ImportExportFlow.h"
      7 #include "Workflows/WorkflowBase.h"
      8 #include "Resources.h"
      9 
     10 namespace AppInstaller::CLI
     11 {
     12     using namespace AppInstaller::CLI::Workflow;
     13     using namespace std::string_view_literals;
     14 
     15     std::vector<Argument> ExportCommand::GetArguments() const
     16     {
     17         return {
     18             Argument{ Execution::Args::Type::OutputFile, Resource::String::OutputFileArgumentDescription, ArgumentType::Positional, true },
     19             Argument{ Execution::Args::Type::Source, Resource::String::ExportSourceArgumentDescription, ArgumentType::Standard },
     20             Argument{ Execution::Args::Type::IncludeVersions, Resource::String::ExportIncludeVersionsArgumentDescription, ArgumentType::Flag },
     21             Argument::ForType(Execution::Args::Type::AcceptSourceAgreements),
     22         };
     23     }
     24 
     25     Resource::LocString ExportCommand::ShortDescription() const
     26     {
     27         return { Resource::String::ExportCommandShortDescription };
     28     }
     29 
     30     Resource::LocString ExportCommand::LongDescription() const
     31     {
     32         return { Resource::String::ExportCommandLongDescription };
     33     }
     34 
     35     void ExportCommand::Complete(Execution::Context& context, Execution::Args::Type valueType) const
     36     {
     37         if (valueType == Execution::Args::Type::OutputFile)
     38         {
     39             // Intentionally output nothing to allow pass through to filesystem.
     40             return;
     41         }
     42 
     43         if (valueType == Execution::Args::Type::Source)
     44         {
     45             context << Workflow::CompleteSourceName;
     46             return;
     47         }
     48     }
     49 
     50     Utility::LocIndView ExportCommand::HelpLink() const
     51     {
     52         return "https://aka.ms/winget-command-export"_liv;
     53     }
     54 
     55     void ExportCommand::ExecuteInternal(Execution::Context& context) const
     56     {
     57         context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning);
     58 
     59         context <<
     60             Workflow::ReportExecutionStage(ExecutionStage::Discovery) <<
     61             Workflow::OpenSource() <<
     62             Workflow::OpenCompositeSource(Repository::PredefinedSource::Installed) <<
     63             Workflow::SearchSourceForMany <<
     64             Workflow::HandleSearchResultFailures <<
     65             Workflow::EnsureMatchesFromSearchResult(OperationType::Export) <<
     66             Workflow::SelectVersionsToExport <<
     67             Workflow::ReportExecutionStage(ExecutionStage::Execution) <<
     68             Workflow::WriteImportFile;
     69     }
     70 }