winget-cli

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

ListCommand.cpp (4263B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "ListCommand.h"
      5 #include "Workflows/CompletionFlow.h"
      6 #include "Workflows/WorkflowBase.h"
      7 #include "Resources.h"
      8 
      9 namespace AppInstaller::CLI
     10 {
     11     using namespace AppInstaller::CLI::Workflow;
     12     using namespace std::string_view_literals;
     13 
     14     std::vector<Argument> ListCommand::GetArguments() const
     15     {
     16         return {
     17             Argument::ForType(Execution::Args::Type::Query),
     18             Argument::ForType(Execution::Args::Type::Id),
     19             Argument::ForType(Execution::Args::Type::Name),
     20             Argument::ForType(Execution::Args::Type::Moniker),
     21             Argument::ForType(Execution::Args::Type::Source),
     22             Argument::ForType(Execution::Args::Type::Tag),
     23             Argument::ForType(Execution::Args::Type::Command),
     24             Argument::ForType(Execution::Args::Type::Count),
     25             Argument::ForType(Execution::Args::Type::Exact),
     26             Argument{ Execution::Args::Type::InstallScope, Resource::String::InstalledScopeArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help },
     27             Argument::ForType(Execution::Args::Type::CustomHeader),
     28             Argument::ForType(Execution::Args::Type::AuthenticationMode),
     29             Argument::ForType(Execution::Args::Type::AuthenticationAccount),
     30             Argument::ForType(Execution::Args::Type::AcceptSourceAgreements),
     31             Argument{ Execution::Args::Type::Upgrade, Resource::String::UpgradeArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help },
     32             Argument{ Execution::Args::Type::IncludeUnknown, Resource::String::IncludeUnknownInListArgumentDescription, ArgumentType::Flag },
     33             Argument{ Execution::Args::Type::IncludePinned, Resource::String::IncludePinnedInListArgumentDescription, ArgumentType::Flag},
     34         };
     35     }
     36 
     37     Resource::LocString ListCommand::ShortDescription() const
     38     {
     39         return { Resource::String::ListCommandShortDescription };
     40     }
     41 
     42     Resource::LocString ListCommand::LongDescription() const
     43     {
     44         return { Resource::String::ListCommandLongDescription };
     45     }
     46 
     47     void ListCommand::Complete(Execution::Context& context, Execution::Args::Type valueType) const
     48     {
     49         context <<
     50             Workflow::OpenSource() <<
     51             Workflow::OpenCompositeSource(Repository::PredefinedSource::Installed);
     52 
     53         switch (valueType)
     54         {
     55         case Execution::Args::Type::Query:
     56             context <<
     57                 Workflow::RequireCompletionWordNonEmpty <<
     58                 Workflow::SearchSourceForManyCompletion <<
     59                 Workflow::CompleteWithMatchedField;
     60             break;
     61         case Execution::Args::Type::Id:
     62         case Execution::Args::Type::Name:
     63         case Execution::Args::Type::Moniker:
     64         case Execution::Args::Type::Source:
     65         case Execution::Args::Type::Tag:
     66         case Execution::Args::Type::Command:
     67             context <<
     68                 Workflow::CompleteWithSingleSemanticsForValueUsingExistingSource(valueType);
     69             break;
     70         }
     71     }
     72 
     73     Utility::LocIndView ListCommand::HelpLink() const
     74     {
     75         return "https://aka.ms/winget-command-list"_liv;
     76     }
     77 
     78     void ListCommand::ValidateArgumentsInternal(Execution::Args& execArgs) const
     79     {
     80         Argument::ValidateArgumentDependency(execArgs, Execution::Args::Type::IncludeUnknown, Execution::Args::Type::Upgrade);
     81         Argument::ValidateArgumentDependency(execArgs, Execution::Args::Type::IncludePinned, Execution::Args::Type::Upgrade);
     82     }
     83 
     84     void ListCommand::ExecuteInternal(Execution::Context& context) const
     85     {
     86         context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning);
     87 
     88         context <<
     89             Workflow::OpenSource() <<
     90             Workflow::OpenCompositeSource(Workflow::DetermineInstalledSource(context)) <<
     91             Workflow::SearchSourceForMany <<
     92             Workflow::HandleSearchResultFailures <<
     93             Workflow::EnsureMatchesFromSearchResult(OperationType::List) <<
     94             Workflow::ReportListResult(context.Args.Contains(Execution::Args::Type::Upgrade));
     95     }
     96 }