winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 564072464413a7afb4942328b1c16d4e68750cc7
parent 5c5826e44c58b44e385ad1794ebc4f4983cb401f
Author: Easton Pillay <easton@planeteaston.com>
Date:   Fri,  5 Nov 2021 15:50:47 -0500

Added an option to select architecture to install. (#1666)

Adds an option, `--architecture`, to `winget install`. This option allows the user to (you guessed it) tell winget what architecture they want to install. If the architecture isn't available, winget does the same thing it would do if there wasn't a installer entry for the user's platform (No applicable installer error). The user is only allowed to provide architectures their system can run (if they ask for arm64 on x64, a `CommandException` is thrown). 
Diffstat:
Msrc/AppInstallerCLICore/Commands/InstallCommand.cpp | 15+++++++++++++++
Msrc/AppInstallerCLICore/ExecutionArgs.h | 1+
Msrc/AppInstallerCLICore/Resources.h | 1+
Msrc/AppInstallerCLICore/Workflows/WorkflowBase.cpp | 5++++-
Msrc/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw | 6+++++-
5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/AppInstallerCLICore/Commands/InstallCommand.cpp b/src/AppInstallerCLICore/Commands/InstallCommand.cpp @@ -17,6 +17,7 @@ namespace AppInstaller::CLI namespace { constexpr Utility::LocIndView s_ArgumentName_Scope = "scope"_liv; + constexpr Utility::LocIndView s_ArgumentName_Architecture = "architecture"_liv; } std::vector<Argument> InstallCommand::GetArguments() const @@ -31,6 +32,7 @@ namespace AppInstaller::CLI Argument::ForType(Args::Type::Channel), Argument::ForType(Args::Type::Source), Argument{ s_ArgumentName_Scope, Argument::NoAlias, Args::Type::InstallScope, Resource::String::InstallScopeDescription, ArgumentType::Standard, Argument::Visibility::Help }, + Argument{ s_ArgumentName_Architecture, 'a', Args::Type::InstallArchitecture, Resource::String::InstallArchitectureArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help}, Argument::ForType(Args::Type::Exact), Argument::ForType(Args::Type::Interactive), Argument::ForType(Args::Type::Silent), @@ -111,6 +113,19 @@ namespace AppInstaller::CLI throw CommandException(Resource::String::InvalidArgumentValueError, s_ArgumentName_Scope, { "user"_lis, "machine"_lis }); } } + if (execArgs.Contains(Args::Type::InstallArchitecture)) + { + Utility::Architecture selectedArch = Utility::ConvertToArchitectureEnum(std::string(execArgs.GetArg(Args::Type::InstallArchitecture))); + if ((selectedArch == Utility::Architecture::Unknown) || (Utility::IsApplicableArchitecture(selectedArch) == Utility::InapplicableArchitecture)) + { + std::vector<Utility::LocIndString> applicableArchitectures; + for (Utility::Architecture i : Utility::GetApplicableArchitectures()) + { + applicableArchitectures.emplace_back(Utility::ToString(i)); + } + throw CommandException(Resource::String::InvalidArgumentValueError, s_ArgumentName_Architecture, std::forward<std::vector<Utility::LocIndString>>((applicableArchitectures))); + } + } if (execArgs.Contains(Args::Type::Locale)) { diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h @@ -38,6 +38,7 @@ namespace AppInstaller::CLI::Execution Override, //Override args are (and the only args) directly passed to installer InstallLocation, InstallScope, + InstallArchitecture, HashOverride, // Ignore hash mismatches AcceptPackageAgreements, // Accept all license agreements for packages diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h @@ -105,6 +105,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ImportSearchFailed); WINGET_DEFINE_RESOURCE_STRINGID(ImportSourceNotInstalled); WINGET_DEFINE_RESOURCE_STRINGID(InstallAndUpgradeCommandsReportDependencies); + WINGET_DEFINE_RESOURCE_STRINGID(InstallArchitectureArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(InstallationAbandoned); WINGET_DEFINE_RESOURCE_STRINGID(InstallationDisclaimer1); WINGET_DEFINE_RESOURCE_STRINGID(InstallationDisclaimer2); diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp b/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp @@ -966,7 +966,10 @@ namespace AppInstaller::CLI::Workflow { installationMetadata = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata(); } - + if (context.Args.Contains(Execution::Args::Type::InstallArchitecture)) + { + context.Add<Execution::Data::AllowedArchitectures>({ Utility::ConvertToArchitectureEnum(std::string(context.Args.GetArg(Execution::Args::Type::InstallArchitecture))) }); + } ManifestComparator manifestComparator(context, installationMetadata); context.Add<Execution::Data::Installer>(manifestComparator.GetPreferredInstaller(context.Get<Execution::Data::Manifest>())); } diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -1236,4 +1236,7 @@ Please specify one of them using the `--source` option to proceed.</value> <data name="CountOutOfBoundsError" xml:space="preserve"> <value>The requested number of results must be between 1 and 1000.</value> </data> -</root> + <data name="InstallArchitectureArgumentDescription" xml:space="preserve"> + <value>Select the architecture to install</value> + </data> +</root>+ \ No newline at end of file