Skip to content

Commit dfaa17e

Browse files
committed
feat: add --ignore-unavailable option to install command
1 parent 6b3bc96 commit dfaa17e

6 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/AppInstallerCLICore/Argument.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ namespace AppInstaller::CLI
420420
return Argument{ type, Resource::String::DependenciesOnlyArgumentDescription, ArgumentType::Flag, false };
421421
case Args::Type::IgnoreLocalArchiveMalwareScan:
422422
return Argument{ type, Resource::String::IgnoreLocalArchiveMalwareScanArgumentDescription, ArgumentType::Flag, Settings::TogglePolicy::Policy::LocalArchiveMalwareScanOverride, Settings::BoolAdminSetting::LocalArchiveMalwareScanOverride };
423+
case Args::Type::IgnoreUnavailable:
424+
return Argument{ type, Resource::String::IgnoreUnavailableArgumentDescription, ArgumentType::Flag };
423425
case Args::Type::SourceName:
424426
return Argument{ type, Resource::String::SourceNameArgumentDescription, ArgumentType::Positional, false };
425427
case Args::Type::SourceArg:

src/AppInstallerCLICore/Commands/ImportCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace AppInstaller::CLI
1717
{
1818
return {
1919
Argument{ Execution::Args::Type::ImportFile, Resource::String::ImportFileArgumentDescription, ArgumentType::Positional, true },
20-
Argument{ Execution::Args::Type::IgnoreUnavailable, Resource::String::ImportIgnoreUnavailableArgumentDescription, ArgumentType::Flag },
20+
Argument::ForType(Execution::Args::Type::IgnoreUnavailable),
2121
Argument{ Execution::Args::Type::IgnoreVersions, Resource::String::ImportIgnorePackageVersionsArgumentDescription, ArgumentType::Flag },
2222
Argument::ForType(Execution::Args::Type::NoUpgrade),
2323
Argument::ForType(Execution::Args::Type::AcceptPackageAgreements),

src/AppInstallerCLICore/Commands/InstallCommand.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace AppInstaller::CLI
5858
Argument::ForType(Args::Type::UninstallPrevious),
5959
Argument::ForType(Args::Type::Force),
6060
Argument{ Args::Type::IncludeUnknown, Resource::String::IncludeUnknownArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden},
61+
Argument::ForType(Args::Type::IgnoreUnavailable),
6162
};
6263
}
6364

src/AppInstallerCLICore/Resources.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ namespace AppInstaller::CLI::Resource
353353
WINGET_DEFINE_RESOURCE_STRINGID(IdArgumentDescription);
354354
WINGET_DEFINE_RESOURCE_STRINGID(IgnoreLocalArchiveMalwareScanArgumentDescription);
355355
WINGET_DEFINE_RESOURCE_STRINGID(IgnoreResumeLimitArgumentDescription);
356+
WINGET_DEFINE_RESOURCE_STRINGID(IgnoreUnavailableArgumentDescription);
356357
WINGET_DEFINE_RESOURCE_STRINGID(IgnoreWarningsArgumentDescription);
357358
WINGET_DEFINE_RESOURCE_STRINGID(ImportCommandLongDescription);
358359
WINGET_DEFINE_RESOURCE_STRINGID(ImportCommandReportDependencies);
359360
WINGET_DEFINE_RESOURCE_STRINGID(ImportCommandShortDescription);
360361
WINGET_DEFINE_RESOURCE_STRINGID(ImportFileArgumentDescription);
361362
WINGET_DEFINE_RESOURCE_STRINGID(ImportFileHasInvalidSchema);
362363
WINGET_DEFINE_RESOURCE_STRINGID(ImportIgnorePackageVersionsArgumentDescription);
363-
WINGET_DEFINE_RESOURCE_STRINGID(ImportIgnoreUnavailableArgumentDescription);
364364
WINGET_DEFINE_RESOURCE_STRINGID(ImportInstallFailed);
365365
WINGET_DEFINE_RESOURCE_STRINGID(ImportSourceNotInstalled);
366366
WINGET_DEFINE_RESOURCE_STRINGID(IncludePinnedArgumentDescription);

src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ They can be configured through the settings file 'winget settings'.</value>
894894
<value>Package is already installed: {0}</value>
895895
<comment>{Locked="{0}"} Message displayed to inform the user that an application package is already installed. {0} is a placeholder replaced by the package identifier or search query.</comment>
896896
</data>
897-
<data name="ImportIgnoreUnavailableArgumentDescription" xml:space="preserve">
897+
<data name="IgnoreUnavailableArgumentDescription" xml:space="preserve">
898898
<value>Ignore unavailable packages</value>
899899
</data>
900900
<data name="ExportIncludeVersionsArgumentDescription" xml:space="preserve">

src/AppInstallerCLITests/InstallFlow.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ TEST_CASE("InstallFlow_UnsupportedArguments_Error", "[InstallFlow][workflow]")
234234
install.Execute(context);
235235
INFO(installOutput.str());
236236

237-
// Verify unsupported arguments error message is shown
237+
// Verify unsupported arguments error message is shown
238238
REQUIRE(context.GetTerminationHR() == APPINSTALLER_CLI_ERROR_UNSUPPORTED_ARGUMENT);
239239
REQUIRE(!std::filesystem::exists(installResultPath.GetPath()));
240240
REQUIRE(installOutput.str().find(Resource::LocString(Resource::String::UnsupportedArgument).get()) != std::string::npos);
@@ -1343,6 +1343,29 @@ TEST_CASE("InstallFlow_InstallMultiple_SearchFailed", "[InstallFlow][workflow][M
13431343
REQUIRE_TERMINATED_WITH(context, APPINSTALLER_CLI_ERROR_NOT_ALL_QUERIES_FOUND_SINGLE);
13441344
}
13451345

1346+
TEST_CASE("InstallFlow_InstallMultiple_IgnoreUnavailable", "[InstallFlow][workflow][MultiQuery]")
1347+
{
1348+
TestCommon::TempFile exeInstallResultPath("TestExeInstalled.txt");
1349+
1350+
std::ostringstream installOutput;
1351+
TestContext context{ installOutput, std::cin };
1352+
auto previousThreadGlobals = context.SetForCurrentThread();
1353+
OverrideForShellExecute(context);
1354+
OverrideForOpenSource(context, CreateTestSource({ TSR::TestInstaller_Exe }), true);
1355+
context.Args.AddArg(Execution::Args::Type::MultiQuery, TSR::TestInstaller_Exe.Query);
1356+
context.Args.AddArg(Execution::Args::Type::MultiQuery, TSR::TestInstaller_Msix.Query);
1357+
context.Args.AddArg(Execution::Args::Type::IgnoreUnavailable);
1358+
1359+
InstallCommand installCommand({});
1360+
installCommand.Execute(context);
1361+
INFO(installOutput.str());
1362+
1363+
// Verify the available package was installed despite the missing one,
1364+
// and the unavailable package was reported as not found.
1365+
REQUIRE(std::filesystem::exists(exeInstallResultPath.GetPath()));
1366+
REQUIRE(installOutput.str().find(Resource::LocString(Resource::String::MultiQueryPackageNotFound(LocIndString{ TSR::TestInstaller_Msix.Query })).get()) != std::string::npos);
1367+
}
1368+
13461369
TEST_CASE("InstallFlow_InstallAcquiresLock", "[InstallFlow][workflow]")
13471370
{
13481371
TestCommon::TempFile installResultPath("TestExeInstalled.txt");

0 commit comments

Comments
 (0)