From 0f21da8c5880329fddf4942ac1569c633a561273 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Thu, 12 Jan 2023 21:52:50 -0600 Subject: [PATCH 1/3] Allow Version Listing through 'Winget Search' --- .../Commands/SearchCommand.cpp | 28 +++++++++++++++---- .../Workflows/ShowFlow.cpp | 12 -------- src/AppInstallerCLICore/Workflows/ShowFlow.h | 6 ---- .../Workflows/WorkflowBase.cpp | 12 ++++++++ .../Workflows/WorkflowBase.h | 6 ++++ 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/AppInstallerCLICore/Commands/SearchCommand.cpp b/src/AppInstallerCLICore/Commands/SearchCommand.cpp index abf5f57071..ccb9e604f4 100644 --- a/src/AppInstallerCLICore/Commands/SearchCommand.cpp +++ b/src/AppInstallerCLICore/Commands/SearchCommand.cpp @@ -25,6 +25,7 @@ namespace AppInstaller::CLI Argument::ForType(Execution::Args::Type::Exact), Argument::ForType(Execution::Args::Type::CustomHeader), Argument::ForType(Execution::Args::Type::AcceptSourceAgreements), + Argument::ForType(Execution::Args::Type::ListVersions), }; } @@ -75,11 +76,26 @@ namespace AppInstaller::CLI { context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning); - context << - Workflow::OpenSource() << - Workflow::SearchSourceForMany << - Workflow::HandleSearchResultFailures << - Workflow::EnsureMatchesFromSearchResult(false) << - Workflow::ReportSearchResult; + + if (context.Args.Contains(Execution::Args::Type::ListVersions)) + { + context << + Workflow::OpenSource() << + Workflow::SearchSourceForMany << + Workflow::HandleSearchResultFailures << + Workflow::EnsureOneMatchFromSearchResult(false) << + Workflow::ReportPackageIdentity << + Workflow::ShowAppVersions; + } + else + { + context << + Workflow::OpenSource() << + Workflow::SearchSourceForMany << + Workflow::HandleSearchResultFailures << + Workflow::EnsureMatchesFromSearchResult(false) << + Workflow::ReportSearchResult; + } + } } diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index e3e4820f97..e0c4b743b9 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -224,16 +224,4 @@ namespace AppInstaller::CLI::Workflow table.OutputLine({ manifest.Version, manifest.Channel }); table.Complete(); } - - void ShowAppVersions(Execution::Context& context) - { - auto versions = context.Get()->GetAvailableVersionKeys(); - - Execution::TableOutput<2> table(context.Reporter, { Resource::String::ShowVersion, Resource::String::ShowChannel }); - for (const auto& version : versions) - { - table.OutputLine({ version.Version, version.Channel }); - } - table.Complete(); - } } \ No newline at end of file diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.h b/src/AppInstallerCLICore/Workflows/ShowFlow.h index 58515e6796..39fcff6cb5 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.h +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.h @@ -28,10 +28,4 @@ namespace AppInstaller::CLI::Workflow // Inputs: Manifest // Outputs: None void ShowManifestVersion(Execution::Context& context); - - // Shows all versions for an application. - // Required Args: None - // Inputs: SearchResult [only operates on first match] - // Outputs: None - void ShowAppVersions(Execution::Context& context); } \ No newline at end of file diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp b/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp index 92f93c108d..90e5487c3f 100644 --- a/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp +++ b/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp @@ -1111,6 +1111,18 @@ namespace AppInstaller::CLI::Workflow { context.SetExecutionStage(m_stage); } + + void ShowAppVersions(Execution::Context& context) + { + auto versions = context.Get()->GetAvailableVersionKeys(); + + Execution::TableOutput<2> table(context.Reporter, { Resource::String::ShowVersion, Resource::String::ShowChannel }); + for (const auto& version : versions) + { + table.OutputLine({ version.Version, version.Channel }); + } + table.Complete(); + } } AppInstaller::CLI::Execution::Context& operator<<(AppInstaller::CLI::Execution::Context& context, AppInstaller::CLI::Workflow::WorkflowTask::Func f) diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.h b/src/AppInstallerCLICore/Workflows/WorkflowBase.h index 0c7f9f2d5b..de577c6881 100644 --- a/src/AppInstallerCLICore/Workflows/WorkflowBase.h +++ b/src/AppInstallerCLICore/Workflows/WorkflowBase.h @@ -368,6 +368,12 @@ namespace AppInstaller::CLI::Workflow // Outputs: InstalledPackageVersion void GetInstalledPackageVersion(Execution::Context& context); + // Shows all versions for an application. + // Required Args: None + // Inputs: SearchResult [only operates on first match] + // Outputs: None + void ShowAppVersions(Execution::Context& context); + // Reports execution stage in a workflow // Required Args: ExecutionStage // Inputs: ExecutionStage? From 51ed01ae05c5bbfda4e271390790393ed5e1b6c9 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Mon, 23 Jan 2023 21:22:05 -0600 Subject: [PATCH 2/3] Move common workflows above If-Else --- .../Commands/SearchCommand.cpp | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/AppInstallerCLICore/Commands/SearchCommand.cpp b/src/AppInstallerCLICore/Commands/SearchCommand.cpp index ccb9e604f4..2cdaa61159 100644 --- a/src/AppInstallerCLICore/Commands/SearchCommand.cpp +++ b/src/AppInstallerCLICore/Commands/SearchCommand.cpp @@ -76,26 +76,22 @@ namespace AppInstaller::CLI { context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning); + context << + Workflow::OpenSource() << + Workflow::SearchSourceForMany << + Workflow::HandleSearchResultFailures << + Workflow::EnsureOneMatchFromSearchResult(false); - if (context.Args.Contains(Execution::Args::Type::ListVersions)) - { - context << - Workflow::OpenSource() << - Workflow::SearchSourceForMany << - Workflow::HandleSearchResultFailures << - Workflow::EnsureOneMatchFromSearchResult(false) << + if (context.Args.Contains(Execution::Args::Type::ListVersions)) + { + context << Workflow::ReportPackageIdentity << Workflow::ShowAppVersions; - } - else - { - context << - Workflow::OpenSource() << - Workflow::SearchSourceForMany << - Workflow::HandleSearchResultFailures << - Workflow::EnsureMatchesFromSearchResult(false) << - Workflow::ReportSearchResult; - } + } + else + { + context << Workflow::ReportSearchResult; + } } } From 1034bbd13541c460d7087a068e4cf110f1a44985 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Tue, 24 Jan 2023 13:27:32 -0600 Subject: [PATCH 3/3] Whoops --- src/AppInstallerCLICore/Commands/SearchCommand.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/AppInstallerCLICore/Commands/SearchCommand.cpp b/src/AppInstallerCLICore/Commands/SearchCommand.cpp index 2cdaa61159..fcac27c4df 100644 --- a/src/AppInstallerCLICore/Commands/SearchCommand.cpp +++ b/src/AppInstallerCLICore/Commands/SearchCommand.cpp @@ -79,18 +79,20 @@ namespace AppInstaller::CLI context << Workflow::OpenSource() << Workflow::SearchSourceForMany << - Workflow::HandleSearchResultFailures << - Workflow::EnsureOneMatchFromSearchResult(false); + Workflow::HandleSearchResultFailures; if (context.Args.Contains(Execution::Args::Type::ListVersions)) { context << + Workflow::EnsureOneMatchFromSearchResult(false) << Workflow::ReportPackageIdentity << Workflow::ShowAppVersions; } else { - context << Workflow::ReportSearchResult; + context << + Workflow::EnsureMatchesFromSearchResult(false) << + Workflow::ReportSearchResult; } }