diff --git a/src/AppInstallerCLICore/Command.cpp b/src/AppInstallerCLICore/Command.cpp
index d0988c10aa..8d7eb8b719 100644
--- a/src/AppInstallerCLICore/Command.cpp
+++ b/src/AppInstallerCLICore/Command.cpp
@@ -675,6 +675,22 @@ namespace AppInstaller::CLI
throw CommandException(Resource::String::HeaderArgumentNotApplicableWithoutSource, Argument::ForType(Execution::Args::Type::CustomHeader).Name());
}
+ if (execArgs.Contains(Execution::Args::Type::Count))
+ {
+ try
+ {
+ int countRequested = std::stoi(std::string(execArgs.GetArg(Execution::Args::Type::Count)));
+ if (countRequested < 1 || countRequested > 1000)
+ {
+ throw CommandException(Resource::String::CountOutOfBoundsError);
+ }
+ }
+ catch (...)
+ {
+ throw CommandException(Resource::String::CountOutOfBoundsError);
+ }
+ }
+
ValidateArgumentsInternal(execArgs);
}
diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h
index a006b24259..84d3c907ca 100644
--- a/src/AppInstallerCLICore/Resources.h
+++ b/src/AppInstallerCLICore/Resources.h
@@ -43,6 +43,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(CompleteCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(CompleteCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(CountArgumentDescription);
+ WINGET_DEFINE_RESOURCE_STRINGID(CountOutOfBoundsError);
WINGET_DEFINE_RESOURCE_STRINGID(DisabledByGroupPolicy);
WINGET_DEFINE_RESOURCE_STRINGID(Done);
WINGET_DEFINE_RESOURCE_STRINGID(ExactArgumentDescription);
diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
index df63107237..afdfabd198 100644
--- a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
+++ b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
@@ -167,7 +167,7 @@
Enables context sensitive command line completion
- Show no more than specified number of results
+ Show no more than specified number of results (between 1 and 1000)
Done
@@ -1190,4 +1190,7 @@ Please specify one of them using the `--source` option to proceed.
Ignore package versions in import file
-
\ No newline at end of file
+
+ The requested number of results must be between 1 and 1000.
+
+