ShowCommand.cpp (4389B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "ShowCommand.h" 5 #include "Workflows/ShowFlow.h" 6 #include "Workflows/CompletionFlow.h" 7 #include "Workflows/WorkflowBase.h" 8 #include "Resources.h" 9 10 namespace AppInstaller::CLI 11 { 12 using namespace AppInstaller::CLI::Execution; 13 using namespace AppInstaller::CLI::Workflow; 14 15 std::vector<Argument> ShowCommand::GetArguments() const 16 { 17 return { 18 Argument::ForType(Execution::Args::Type::Query), 19 // The manifest argument from Argument::ForType can be blocked by Group Policy but we don't want that here 20 Argument{ Execution::Args::Type::Manifest, Resource::String::ManifestArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help }, 21 Argument::ForType(Execution::Args::Type::Id), 22 Argument::ForType(Execution::Args::Type::Name), 23 Argument::ForType(Execution::Args::Type::Moniker), 24 Argument::ForType(Execution::Args::Type::Version), 25 Argument::ForType(Execution::Args::Type::Channel), 26 Argument::ForType(Execution::Args::Type::Source), 27 Argument::ForType(Execution::Args::Type::Exact), 28 Argument{ Args::Type::InstallScope, Resource::String::InstallScopeDescription, ArgumentType::Standard, Argument::Visibility::Help }, 29 Argument::ForType(Execution::Args::Type::InstallerArchitecture), 30 Argument::ForType(Execution::Args::Type::InstallerType), 31 Argument::ForType(Execution::Args::Type::Locale), 32 Argument::ForType(Execution::Args::Type::ListVersions), 33 Argument::ForType(Execution::Args::Type::CustomHeader), 34 Argument::ForType(Execution::Args::Type::AuthenticationMode), 35 Argument::ForType(Execution::Args::Type::AuthenticationAccount), 36 Argument::ForType(Execution::Args::Type::AcceptSourceAgreements), 37 }; 38 } 39 40 Resource::LocString ShowCommand::ShortDescription() const 41 { 42 return { Resource::String::ShowCommandShortDescription }; 43 } 44 45 Resource::LocString ShowCommand::LongDescription() const 46 { 47 return { Resource::String::ShowCommandLongDescription }; 48 } 49 50 void ShowCommand::Complete(Execution::Context& context, Execution::Args::Type valueType) const 51 { 52 switch (valueType) 53 { 54 case Args::Type::InstallerArchitecture: 55 case Args::Type::Locale: 56 // May well move to CompleteWithSingleSemanticsForValue, 57 // but for now output nothing. 58 context << 59 Workflow::CompleteWithEmptySet; 60 break; 61 default: 62 context << 63 Workflow::CompleteWithSingleSemanticsForValue(valueType); 64 } 65 } 66 67 Utility::LocIndView ShowCommand::HelpLink() const 68 { 69 return "https://aka.ms/winget-command-show"_liv; 70 } 71 72 void ShowCommand::ValidateArgumentsInternal(Args& execArgs) const 73 { 74 Argument::ValidateCommonArguments(execArgs); 75 } 76 77 void ShowCommand::ExecuteInternal(Execution::Context& context) const 78 { 79 context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning); 80 81 if (context.Args.Contains(Execution::Args::Type::ListVersions)) 82 { 83 if (context.Args.Contains(Execution::Args::Type::Manifest)) 84 { 85 context << 86 Workflow::GetManifestFromArg << 87 Workflow::ReportManifestIdentity << 88 Workflow::ShowManifestVersion; 89 } 90 else 91 { 92 context << 93 Workflow::OpenSource() << 94 Workflow::SearchSourceForSingle << 95 Workflow::HandleSearchResultFailures << 96 Workflow::EnsureOneMatchFromSearchResult(OperationType::Show) << 97 Workflow::ReportPackageIdentity << 98 Workflow::ShowAppVersions; 99 } 100 } 101 else 102 { 103 context << 104 GetManifest( /* considerPins */ false) << 105 Workflow::ReportManifestIdentity << 106 Workflow::SelectInstaller << 107 Workflow::ShowManifestInfo; 108 } 109 } 110 }