commit 082b9907644244c8697b4cdd4616ea111f15b73a parent 2f5008223fa939c3b5dbe8c29ddd3cb484ef96c0 Author: Kaleb Luedtke <jluedtk@jci.com> Date: Mon, 26 Sep 2022 22:59:32 -0500 Add experimental argument to open logs folder (#2510) Diffstat:
16 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt @@ -359,6 +359,7 @@ SETTINGMAPPING SHCONTF SHGDN Shlobj +SHOWNORMAL sid SIGNATUREHASH Sku diff --git a/doc/Settings.md b/doc/Settings.md @@ -231,6 +231,17 @@ You can enable the feature as shown below. "directMSI": true }, ``` + +### openLogsArgument + +This feature enables the Windows Package Manager to open the default logs folder after execution by passing the `--open-logs` argument with any command. +You can enable the feature as shown below. + +```json + "experimentalFeatures": { + "openLogsArgument": true + }, +``` ### Dependencies Experimental feature with the aim of managing dependencies, as of now it only shows package dependency information. You can enable the feature as shown below. diff --git a/schemas/JSON/settings/settings.schema.0.2.json b/schemas/JSON/settings/settings.schema.0.2.json @@ -208,6 +208,11 @@ "description": "Enable support for installing zip packages.", "type": "boolean", "default": false + }, + "openLogsArgument": { + "description": "Enable argument to open default logs location", + "type": "boolean", + "default": false } } } diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp @@ -97,6 +97,8 @@ namespace AppInstaller::CLI return Argument{ "wait", NoAlias, Args::Type::Wait, Resource::String::WaitArgumentDescription, ArgumentType::Flag, false }; case Args::Type::ProductCode: return Argument{ "product-code", NoAlias, Args::Type::ProductCode, Resource::String::ProductCodeArgumentDescription, ArgumentType::Standard, false }; + case Args::Type::OpenLogs: + return Argument{ "open-logs", NoAlias, "logs", Args::Type::OpenLogs, Resource::String::OpenLogsArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::OpenLogsArgument}; default: THROW_HR(E_UNEXPECTED); } @@ -106,6 +108,7 @@ namespace AppInstaller::CLI { args.push_back(ForType(Args::Type::Help)); args.push_back(ForType(Args::Type::Wait)); + args.push_back(ForType(Args::Type::OpenLogs)); args.push_back(ForType(Args::Type::NoVT)); args.push_back(ForType(Args::Type::RainbowStyle)); args.push_back(ForType(Args::Type::RetroStyle)); diff --git a/src/AppInstallerCLICore/Command.cpp b/src/AppInstallerCLICore/Command.cpp @@ -643,7 +643,11 @@ namespace AppInstaller::CLI return; } - for (const auto& arg : GetArguments()) + // Common arguments need to be validated with command arguments, as there may be common arguments blocked by Experimental Feature or Group Policy + auto allArgs = GetArguments(); + Argument::GetCommon(allArgs); + + for (const auto& arg : allArgs) { if (!Settings::GroupPolicies().IsEnabled(arg.GroupPolicy()) && execArgs.Contains(arg.ExecArgType())) { @@ -836,6 +840,13 @@ namespace AppInstaller::CLI ExecuteInternal(context); } + if (context.Args.Contains(Execution::Args::Type::OpenLogs)) + { + // TODO: Consider possibly adding functionality that if the context contains 'Execution::Args::Type::Log' to open the path provided for the log + // The above was omitted initially as a security precaution to ensure that user input to '--log' wouldn't be passed directly to ShellExecute + ShellExecute(NULL, NULL, Runtime::GetPathTo(Runtime::PathName::DefaultLogLocation).wstring().c_str(), NULL, NULL, SW_SHOWNORMAL); + } + if (context.Args.Contains(Execution::Args::Type::Wait)) { context.Reporter.PromptForEnter(); @@ -885,6 +896,7 @@ namespace AppInstaller::CLI std::vector<Argument> Command::GetVisibleArguments() const { auto arguments = GetArguments(); + Argument::GetCommon(arguments); arguments.erase( std::remove_if( diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp @@ -161,6 +161,11 @@ namespace AppInstaller::CLI ExecuteInternal(context); } + if (context.Args.Contains(Execution::Args::Type::OpenLogs)) + { + ShellExecute(NULL, NULL, Runtime::GetPathTo(Runtime::PathName::DefaultLogLocation).wstring().c_str(), NULL, NULL, SW_SHOWNORMAL); + } + if (context.Args.Contains(Execution::Args::Type::Wait)) { context.Reporter.PromptForEnter(); diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h @@ -95,6 +95,7 @@ namespace AppInstaller::CLI::Execution VerboseLogs, // Increases winget logging level to verbose DisableInteractivity, // Disable interactive prompts Wait, // Prompts the user to press any key before exiting + OpenLogs, // Opens the default logs directory after executing the command DependencySource, // Index source to be queried against for finding dependencies CustomHeader, // Optional Rest source header diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h @@ -212,6 +212,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(Notes); WINGET_DEFINE_RESOURCE_STRINGID(NoUninstallInfoFound); WINGET_DEFINE_RESOURCE_STRINGID(NoVTArgumentDescription); + WINGET_DEFINE_RESOURCE_STRINGID(OpenLogsArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(OpenSourceFailedNoMatch); WINGET_DEFINE_RESOURCE_STRINGID(OpenSourceFailedNoMatchHelp); WINGET_DEFINE_RESOURCE_STRINGID(OpenSourceFailedNoSourceDefined); diff --git a/src/AppInstallerCLIE2ETests/BaseCommand.cs b/src/AppInstallerCLIE2ETests/BaseCommand.cs @@ -56,6 +56,7 @@ namespace AppInstallerCLIE2ETests ConfigureFeature("dependencies", status); ConfigureFeature("directMSI", status); ConfigureFeature("zipInstall", status); + ConfigureFeature("openLogsArgument", status); } } } diff --git a/src/AppInstallerCLIE2ETests/FeaturesCommand.cs b/src/AppInstallerCLIE2ETests/FeaturesCommand.cs @@ -34,6 +34,7 @@ namespace AppInstallerCLIE2ETests ConfigureFeature("experimentalArg", true); ConfigureFeature("experimentalCmd", true); ConfigureFeature("directMSI", true); + ConfigureFeature("openLogsArgument", true); var result = TestCommon.RunAICLICommand("features", ""); Assert.True(result.StdOut.Contains("Enabled")); } diff --git a/src/AppInstallerCLIE2ETests/SetUpFixture.cs b/src/AppInstallerCLIE2ETests/SetUpFixture.cs @@ -211,6 +211,7 @@ namespace AppInstallerCLIE2ETests experimentalCmd = false, dependencies = false, directMSI = false, + openLogsArgument = false, }, debugging = new { diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -408,6 +408,9 @@ They can be configured through the settings file 'winget settings'.</value> <value>Disables VirtualTerminal display</value> <comment>{Locked="VirtualTerminal"}</comment> </data> + <data name="OpenLogsArgumentDescription" xml:space="preserve"> + <value>Open the default logs location</value> + </data> <data name="Options" xml:space="preserve"> <value>options</value> <comment>Options to change how a command works</comment> diff --git a/src/AppInstallerCommonCore/ExperimentalFeature.cpp b/src/AppInstallerCommonCore/ExperimentalFeature.cpp @@ -44,6 +44,8 @@ namespace AppInstaller::Settings return userSettings.Get<Setting::EFDirectMSI>(); case ExperimentalFeature::Feature::ZipInstall: return userSettings.Get<Setting::EFZipInstall>(); + case ExperimentalFeature::Feature::OpenLogsArgument: + return userSettings.Get<Setting::EFOpenLogsArgument>(); default: THROW_HR(E_UNEXPECTED); } @@ -77,6 +79,8 @@ namespace AppInstaller::Settings return ExperimentalFeature{ "Direct MSI Installation", "directMSI", "https://aka.ms/winget-settings", Feature::DirectMSI }; case Feature::ZipInstall: return ExperimentalFeature{ "Zip Installation", "zipInstall", "https://aka.ms/winget-settings", Feature::ZipInstall }; + case Feature::OpenLogsArgument: + return ExperimentalFeature{ "Open Logs Argument", "openLogsArgument", "https://aka.ms/winget-settings", Feature::OpenLogsArgument }; default: THROW_HR(E_UNEXPECTED); } diff --git a/src/AppInstallerCommonCore/Public/winget/ExperimentalFeature.h b/src/AppInstallerCommonCore/Public/winget/ExperimentalFeature.h @@ -24,6 +24,7 @@ namespace AppInstaller::Settings // Before making DirectMSI non-experimental, it should be part of manifest validation. DirectMSI = 0x2, ZipInstall = 0x4, + OpenLogsArgument = 0x8, Max, // This MUST always be after all experimental features // Features listed after Max will not be shown with the features command diff --git a/src/AppInstallerCommonCore/Public/winget/UserSettings.h b/src/AppInstallerCommonCore/Public/winget/UserSettings.h @@ -78,6 +78,7 @@ namespace AppInstaller::Settings EFDependencies, EFDirectMSI, EFZipInstall, + EFOpenLogsArgument, // Telemetry TelemetryDisable, // Install behavior @@ -146,6 +147,7 @@ namespace AppInstaller::Settings SETTINGMAPPING_SPECIALIZATION(Setting::EFDependencies, bool, bool, false, ".experimentalFeatures.dependencies"sv); SETTINGMAPPING_SPECIALIZATION(Setting::EFDirectMSI, bool, bool, false, ".experimentalFeatures.directMSI"sv); SETTINGMAPPING_SPECIALIZATION(Setting::EFZipInstall, bool, bool, false, ".experimentalFeatures.zipInstall"sv); + SETTINGMAPPING_SPECIALIZATION(Setting::EFOpenLogsArgument, bool, bool, false, ".experimentalFeatures.openLogsArgument"sv); // Telemetry SETTINGMAPPING_SPECIALIZATION(Setting::TelemetryDisable, bool, bool, false, ".telemetry.disable"sv); // Install behavior diff --git a/src/AppInstallerCommonCore/UserSettings.cpp b/src/AppInstallerCommonCore/UserSettings.cpp @@ -248,6 +248,7 @@ namespace AppInstaller::Settings WINGET_VALIDATE_PASS_THROUGH(EFDependencies) WINGET_VALIDATE_PASS_THROUGH(EFDirectMSI) WINGET_VALIDATE_PASS_THROUGH(EFZipInstall) + WINGET_VALIDATE_PASS_THROUGH(EFOpenLogsArgument) WINGET_VALIDATE_PASS_THROUGH(TelemetryDisable) WINGET_VALIDATE_PASS_THROUGH(InteractivityDisable) WINGET_VALIDATE_PASS_THROUGH(EnableSelfInitiatedMinidump)