Skip to content

Commit

Permalink
Added an option to select architecture to install. (#1666)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jedieaston authored Nov 5, 2021
1 parent 5c5826e commit 5640724
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/AppInstallerCLICore/Commands/InstallCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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))
{
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>()));
}
Expand Down
5 changes: 4 additions & 1 deletion src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 5640724

Please sign in to comment.