Skip to content

Commit

Permalink
Fix string id
Browse files Browse the repository at this point in the history
  • Loading branch information
florelis committed Feb 27, 2024
1 parent 8a11d7c commit 3172238
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ namespace AppInstaller::CLI
return { type, "enable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::EnableDisable };
case Execution::Args::Type::AdminSettingDisable:
return { type, "disable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::EnableDisable };
case Execution::Args::Type::SettingName:
return { type, "setting"_liv };
case Execution::Args::Type::SettingValue:
return { type, "value"_liv };

// Upgrade command
case Execution::Args::Type::All:
Expand Down
95 changes: 95 additions & 0 deletions src/AppInstallerCLICore/Commands/SettingsCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace AppInstaller::CLI
{
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
std::make_unique<SettingsExportCommand>(FullName()),
std::make_unique<SettingsSetCommand>(FullName()),
std::make_unique<SettingsResetCommand>(FullName()),
});
}

Expand Down Expand Up @@ -109,4 +111,97 @@ namespace AppInstaller::CLI
context <<
Workflow::ExportSettings;
}

std::vector<Argument> SettingsSetCommand::GetArguments() const
{
return {
Argument { Execution::Args::Type::SettingName, Resource::String::SettingNameArgumentDescription, ArgumentType::Positional, true },
Argument { Execution::Args::Type::SettingValue, Resource::String::SettingValueArgumentDescription, ArgumentType::Positional, true },
};
}

Resource::LocString SettingsSetCommand::ShortDescription() const
{
return { Resource::String::SettingsSetCommandShortDescription };
}

Resource::LocString SettingsSetCommand::LongDescription() const
{
return { Resource::String::SettingsSetCommandLongDescription };
}

Utility::LocIndView SettingsSetCommand::HelpLink() const
{
return s_SettingsCommand_HelpLink;
}

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

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

if (execArgs.Contains(Execution::Args::Type::AdminSettingEnable) && StringAdminSetting::Unknown == StringToStringAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName)))
{
throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::SettingName).Name, validOptions));
}
}

void SettingsSetCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
Workflow::EnsureRunningAsAdmin <<
Workflow::SetAdminSetting;
}

std::vector<Argument> SettingsResetCommand::GetArguments() const
{
return {
Argument { Execution::Args::Type::SettingName, Resource::String::SettingNameArgumentDescription, ArgumentType::Positional, true },
};
}

Resource::LocString SettingsResetCommand::ShortDescription() const
{
return { Resource::String::SettingsResetCommandShortDescription };
}

Resource::LocString SettingsResetCommand::LongDescription() const
{
return { Resource::String::SettingsResetCommandLongDescription };
}

Utility::LocIndView SettingsResetCommand::HelpLink() const
{
return s_SettingsCommand_HelpLink;
}

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

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

if (execArgs.Contains(Execution::Args::Type::AdminSettingEnable) && StringAdminSetting::Unknown == StringToStringAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName)))
{
throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::SettingName).Name, validOptions));
}
}

void SettingsResetCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
Workflow::EnsureRunningAsAdmin <<
Workflow::ResetAdminSetting;
}
}
32 changes: 32 additions & 0 deletions src/AppInstallerCLICore/Commands/SettingsCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,36 @@ namespace AppInstaller::CLI
protected:
void ExecuteInternal(Execution::Context& context) const override;
};

struct SettingsSetCommand final : public Command
{
SettingsSetCommand(std::string_view parent) : Command("set", {}, parent, Settings::TogglePolicy::Policy::Settings) {}

std::vector<Argument> GetArguments() const override;

virtual Resource::LocString ShortDescription() const override;
virtual Resource::LocString LongDescription() const override;

Utility::LocIndView HelpLink() const override;

protected:
void ValidateArgumentsInternal(Execution::Args& execArgs) const override;
void ExecuteInternal(Execution::Context& context) const override;
};

struct SettingsResetCommand final : public Command
{
SettingsResetCommand(std::string_view parent) : Command("reset", {}, parent, Settings::TogglePolicy::Policy::Settings) {}

std::vector<Argument> GetArguments() const override;

virtual Resource::LocString ShortDescription() const override;
virtual Resource::LocString LongDescription() const override;

Utility::LocIndView HelpLink() const override;

protected:
void ValidateArgumentsInternal(Execution::Args& execArgs) const override;
void ExecuteInternal(Execution::Context& context) const override;
};
}
2 changes: 2 additions & 0 deletions src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace AppInstaller::CLI::Execution
// Setting Command
AdminSettingEnable,
AdminSettingDisable,
SettingName,
SettingValue,

// Upgrade command
All, // Used in Update command to update all installed packages to latest
Expand Down
16 changes: 13 additions & 3 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,16 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotFound);
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSpecified);
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSupported);
WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers);
WINGET_DEFINE_RESOURCE_STRINGID(NoAdminRepairForUserScopePackage);
WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers);
WINGET_DEFINE_RESOURCE_STRINGID(NoExperimentalFeaturesMessage);
WINGET_DEFINE_RESOURCE_STRINGID(NoInstalledPackageFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoPackageFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoPackageSelectionArgumentProvided);
WINGET_DEFINE_RESOURCE_STRINGID(NoPackagesFoundInImportFile);
WINGET_DEFINE_RESOURCE_STRINGID(NoProxyArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(Notes);
WINGET_DEFINE_RESOURCE_STRINGID(NoRepairInfoFound);
WINGET_DEFINE_RESOURCE_STRINGID(Notes);
WINGET_DEFINE_RESOURCE_STRINGID(NoUninstallInfoFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoUpgradeArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(NoVTArgumentDescription);
Expand Down Expand Up @@ -439,6 +439,8 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(ReportIdentityFound);
WINGET_DEFINE_RESOURCE_STRINGID(RequiredArgError);
WINGET_DEFINE_RESOURCE_STRINGID(ReservedFilenameError);
WINGET_DEFINE_RESOURCE_STRINGID(ResetAdminSettingFailed);
WINGET_DEFINE_RESOURCE_STRINGID(ResetAdminSettingSucceeded);
WINGET_DEFINE_RESOURCE_STRINGID(ResumeCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ResumeCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ResumeIdArgumentDescription);
Expand All @@ -459,14 +461,22 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(SearchTruncated);
WINGET_DEFINE_RESOURCE_STRINGID(SearchVersion);
WINGET_DEFINE_RESOURCE_STRINGID(SeeLineAndColumn);
WINGET_DEFINE_RESOURCE_STRINGID(SetAdminSettingFailed);
WINGET_DEFINE_RESOURCE_STRINGID(SetAdminSettingSucceeded);
WINGET_DEFINE_RESOURCE_STRINGID(SettingLoadFailure);
WINGET_DEFINE_RESOURCE_STRINGID(SettingNameArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsExportCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsExportCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsResetCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsResetCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsSetCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsSetCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarningField);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarnings);
WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarningValue);
WINGET_DEFINE_RESOURCE_STRINGID(SettingValueArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ShowChannel);
WINGET_DEFINE_RESOURCE_STRINGID(ShowCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ShowCommandShortDescription);
Expand Down Expand Up @@ -591,8 +601,8 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(UpdateNotApplicableReason);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeAvailableForPinned);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByPinCount);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByManifest);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByPinCount);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(UpgradeDifferentInstallTechnology);
Expand Down
29 changes: 29 additions & 0 deletions src/AppInstallerCLICore/Workflows/SettingsFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ namespace AppInstaller::CLI::Workflow
}
}

void SetAdminSetting(Execution::Context& context)
{
auto adminSettingName = context.Args.GetArg(Execution::Args::Type::SettingName);
auto adminSettingValue = context.Args.GetArg(Execution::Args::Type::SettingValue);
StringAdminSetting adminSetting = Settings::StringToStringAdminSetting(adminSettingName);
if (Settings::SetAdminSetting(adminSetting, adminSettingValue))
{
context.Reporter.Info() << Resource::String::SetAdminSettingSucceeded(AdminSettingToString(adminSetting), LocIndString{ adminSettingValue }) << std::endl;
}
else
{
context.Reporter.Error() << Resource::String::SetAdminSettingFailed(AdminSettingToString(adminSetting)) << 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))
{
context.Reporter.Info() << Resource::String::ResetAdminSettingSucceeded(AdminSettingToString(adminSetting)) << std::endl;
}
else
{
context.Reporter.Error() << Resource::String::ResetAdminSettingFailed(AdminSettingToString(adminSetting)) << std::endl;
}
}

void OpenUserSetting(Execution::Context& context)
{
// Show warnings only when the setting command is executed.
Expand Down
12 changes: 12 additions & 0 deletions src/AppInstallerCLICore/Workflows/SettingsFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ namespace AppInstaller::CLI::Workflow
// Outputs: None
void DisableAdminSetting(Execution::Context& context);

// Sets the value of an admin setting.
// Required Args: SettingName, SettingValue
// Inputs: None
// Outputs: None
void SetAdminSetting(Execution::Context& context);

// Resets an admin setting to the default.
// Required Args: SettingName
// Inputs: None
// Outputs: None
void ResetAdminSetting(Execution::Context& context);

// Opens the user settings.
// Required Args: None
// Inputs: None
Expand Down
36 changes: 35 additions & 1 deletion src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ Please specify one of them using the --source option to proceed.</value>
<data name="APPINSTALLER_CLI_ERROR_SQLITE_CONNECTION_TERMINATED" xml:space="preserve">
<value>The SQLite connection was terminated to prevent corruption.</value>
</data>
<data name="PolicyEnableWinGetProxyCommandLineOptions" xml:space="preserve">
<data name="PolicyEnableProxyCommandLineOptions" xml:space="preserve">
<value>Enable Windows Package Manager proxy command line options</value>
<comment>Describes a Group Policy that can enable the use of the --proxy option to set a proxy</comment>
</data>
Expand All @@ -2827,4 +2827,38 @@ Please specify one of them using the --source option to proceed.</value>
<data name="NoProxyArgumentDescription" xml:space="preserve">
<value>Disable the use of proxy for this execution</value>
</data>
<data name="ResetAdminSettingFailed" xml:space="preserve">
<value>Cannot reset {0}. This setting is controlled by policy. For more information contact your system administrator.</value>
<comment>{Locked="{0}"} The value will be replaced with the feature name</comment>
</data>
<data name="ResetAdminSettingSucceeded" xml:space="preserve">
<value>Reset admin setting '{0}'.</value>
<comment>{Locked="{0}"} Message displayed after the user resets an admin setting to its default value. Reset is used as verb in past tense. {0} is a placeholder replaced by the setting name.</comment>
</data>
<data name="SetAdminSettingFailed" xml:space="preserve">
<value>Cannot set {0}. This setting is controlled by policy. For more information contact your system administrator.</value>
<comment>{Locked="{0}"} The value will be replaced with the feature name</comment>
</data>
<data name="SetAdminSettingSucceeded" xml:space="preserve">
<value>Set admin setting '{0}' to '{1}'.</value>
<comment>{Locked="{0}"} Message displayed after the user sets the value of an admin setting. Set is used as a verb in past tense. {0} is a placeholder replaced by the setting name. {1} is a placeholder replaced </comment>
</data>
<data name="SettingNameArgumentDescription" xml:space="preserve">
<value>Name of the setting to modify</value>
</data>
<data name="SettingValueArgumentDescription" xml:space="preserve">
<value>Value to set for the setting.</value>
</data>
<data name="SettingsResetCommandLongDescription" xml:space="preserve">
<value>Resets an admin setting to its default value.</value>
</data>
<data name="SettingsResetCommandShortDescription" xml:space="preserve">
<value>Resets an admin setting to its default value.</value>
</data>
<data name="SettingsSetCommandLongDescription" xml:space="preserve">
<value>Sets the value of an admin setting.</value>
</data>
<data name="SettingsSetCommandShortDescription" xml:space="preserve">
<value>Sets the value of an admin setting.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/AppInstallerCommonCore/Public/winget/AdminSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace AppInstaller::Settings
bool EnableAdminSetting(BoolAdminSetting setting);
bool DisableAdminSetting(BoolAdminSetting setting);
bool SetAdminSetting(StringAdminSetting setting, std::string_view value);
bool ResetAdminSetting(StringAdminSetting setting, std::string_view value);
bool ResetAdminSetting(StringAdminSetting setting);

bool IsAdminSettingEnabled(BoolAdminSetting setting);
std::optional<std::string> GetAdminSetting(StringAdminSetting setting);
Expand Down

0 comments on commit 3172238

Please sign in to comment.