Skip to content

Commit

Permalink
Reset bool admin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
florelis committed Mar 11, 2024
1 parent 25facf1 commit e0fdcf7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/AppInstallerCLICore/Commands/SettingsCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,23 @@ namespace AppInstaller::CLI

void SettingsResetCommand::ValidateArgumentsInternal(Execution::Args& execArgs) const
{
// Get admin setting string for all available options except Unknown
// Get admin setting string for all available options except Unknown.
// We accept both bool and string settings
std::vector<Utility::LocIndString> adminSettingList;
for (auto setting : GetAllSequentialEnumValues(BoolAdminSetting::Unknown))
{
adminSettingList.emplace_back(AdminSettingToString(setting));
}
for (auto setting : GetAllSequentialEnumValues(StringAdminSetting::Unknown))
{
adminSettingList.emplace_back(AdminSettingToString(setting));
}

Utility::LocIndString validOptions = Join(", "_liv, adminSettingList);

if (execArgs.Contains(Execution::Args::Type::SettingName) && StringAdminSetting::Unknown == StringToStringAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName)))
if (execArgs.Contains(Execution::Args::Type::SettingName)
&& StringAdminSetting::Unknown == StringToStringAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName))
&& BoolAdminSetting::Unknown == StringToBoolAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName)))
{
throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::SettingName).Name, validOptions));
}
Expand Down
19 changes: 12 additions & 7 deletions src/AppInstallerCLICore/Workflows/SettingsFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,30 @@ namespace AppInstaller::CLI::Workflow
StringAdminSetting adminSetting = Settings::StringToStringAdminSetting(adminSettingName);
if (Settings::SetAdminSetting(adminSetting, adminSettingValue))
{
context.Reporter.Info() << Resource::String::SetAdminSettingSucceeded(AdminSettingToString(adminSetting), LocIndString{ adminSettingValue }) << std::endl;
context.Reporter.Info() << Resource::String::SetAdminSettingSucceeded(adminSettingName, LocIndString{ adminSettingValue }) << std::endl;
}
else
{
context.Reporter.Error() << Resource::String::SetAdminSettingFailed(AdminSettingToString(adminSetting)) << std::endl;
context.Reporter.Error() << Resource::String::SetAdminSettingFailed(adminSettingName) << std::endl;
}
}

void ResetAdminSetting(Execution::Context& context)
{
auto adminSettingName = context.Args.GetArg(Execution::Args::Type::SettingName);
StringAdminSetting adminSetting = Settings::StringToStringAdminSetting(adminSettingName);
if (Settings::ResetAdminSetting(adminSetting))

// Try as both bool and string setting as we don't know the type
auto boolAdminSetting = Settings::StringToBoolAdminSetting(adminSettingName);
auto stringAdminSetting = Settings::StringToStringAdminSetting(adminSettingName);

if ((boolAdminSetting != Settings::BoolAdminSetting::Unknown && Settings::DisableAdminSetting(boolAdminSetting))
|| (stringAdminSetting != Settings::StringAdminSetting::Unknown && Settings::ResetAdminSetting(stringAdminSetting)))
{
context.Reporter.Info() << Resource::String::ResetAdminSettingSucceeded(AdminSettingToString(adminSetting)) << std::endl;
context.Reporter.Info() << Resource::String::ResetAdminSettingSucceeded(adminSettingName) << std::endl;
}
else
else if (stringAdminSetting != Settings::StringAdminSetting::Unknown)
{
context.Reporter.Error() << Resource::String::ResetAdminSettingFailed(AdminSettingToString(adminSetting)) << std::endl;
context.Reporter.Error() << Resource::String::ResetAdminSettingFailed(adminSettingName) << std::endl;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "WorkflowBase.h"
#include "ExecutionContext.h"
#include "ManifestComparator.h"
#include "DownloadFlow.h"
#include "PromptFlow.h"
#include "TableOutput.h"
#include <winget/ExperimentalFeature.h>
Expand All @@ -13,7 +12,6 @@
#include <winget/PinningData.h>
#include <winget/Runtime.h>
#include <winget/PackageVersionSelection.h>
#include <winget/GroupPolicy.h>

using namespace std::string_literals;
using namespace AppInstaller::Utility::literals;
Expand Down

0 comments on commit e0fdcf7

Please sign in to comment.