SearchCommand.cpp (3735B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "SearchCommand.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::Execution; 12 using namespace AppInstaller::CLI::Workflow; 13 using namespace std::string_view_literals; 14 15 std::vector<Argument> SearchCommand::GetArguments() const 16 { 17 return { 18 Argument::ForType(Execution::Args::Type::Query), 19 Argument::ForType(Execution::Args::Type::Id), 20 Argument::ForType(Execution::Args::Type::Name), 21 Argument::ForType(Execution::Args::Type::Moniker), 22 Argument::ForType(Execution::Args::Type::Tag), 23 Argument::ForType(Execution::Args::Type::Command), 24 Argument::ForType(Execution::Args::Type::Source), 25 Argument::ForType(Execution::Args::Type::Count), 26 Argument::ForType(Execution::Args::Type::Exact), 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::ForType(Execution::Args::Type::ListVersions), 32 }; 33 } 34 35 Resource::LocString SearchCommand::ShortDescription() const 36 { 37 return { Resource::String::SearchCommandShortDescription }; 38 } 39 40 Resource::LocString SearchCommand::LongDescription() const 41 { 42 return { Resource::String::SearchCommandLongDescription }; 43 } 44 45 void SearchCommand::Complete(Execution::Context& context, Execution::Args::Type valueType) const 46 { 47 switch (valueType) 48 { 49 case Execution::Args::Type::Query: 50 context << 51 Workflow::OpenSource() << 52 Workflow::RequireCompletionWordNonEmpty << 53 Workflow::SearchSourceForManyCompletion << 54 Workflow::CompleteWithMatchedField; 55 break; 56 case Execution::Args::Type::Id: 57 case Execution::Args::Type::Name: 58 case Execution::Args::Type::Moniker: 59 case Execution::Args::Type::Tag: 60 case Execution::Args::Type::Command: 61 case Execution::Args::Type::Source: 62 context << 63 Workflow::CompleteWithSingleSemanticsForValue(valueType); 64 break; 65 } 66 } 67 68 Utility::LocIndView SearchCommand::HelpLink() const 69 { 70 return "https://aka.ms/winget-command-search"_liv; 71 } 72 73 void SearchCommand::ValidateArgumentsInternal(Args& execArgs) const 74 { 75 Argument::ValidateCommonArguments(execArgs); 76 } 77 78 void SearchCommand::ExecuteInternal(Context& context) const 79 { 80 context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning); 81 82 context << 83 Workflow::OpenSource() << 84 Workflow::SearchSourceForMany << 85 Workflow::HandleSearchResultFailures; 86 87 if (context.Args.Contains(Execution::Args::Type::ListVersions)) 88 { 89 context << 90 Workflow::EnsureOneMatchFromSearchResult(OperationType::Search) << 91 Workflow::ReportPackageIdentity << 92 Workflow::ShowAppVersions; 93 } 94 else 95 { 96 context << 97 Workflow::EnsureMatchesFromSearchResult(OperationType::Search) << 98 Workflow::ReportSearchResult; 99 } 100 101 } 102 }