Skip to content

Commit 964d4c6

Browse files
author
annavied_microsoft
committed
add writeWarnings flag on server class
1 parent f557fe7 commit 964d4c6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/code/FindHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
206206
// Set network credentials via passed in credentials, AzArtifacts CredentialProvider, or SecretManagement.
207207
_networkCredential = currentRepository.SetNetworkCredentials(_networkCredential, _cmdletPassedIn);
208208

209-
ServerApiCall currentServer = ServerFactory.GetServer(currentRepository, _cmdletPassedIn, _networkCredential);
209+
bool shouldReportErrorForEachRepo = !suppressErrors && !_repositoryNameContainsWildcard;
210+
bool shouldWriteWarningsForRepo = !shouldReportErrorForEachRepo; // Only write warnings for a repository if we are not writing errors for each repository.
211+
212+
ServerApiCall currentServer = ServerFactory.GetServer(currentRepository, _cmdletPassedIn, _networkCredential, writeWarnings: shouldWriteWarningsForRepo);
210213
if (currentServer == null)
211214
{
212215
// this indicates that PSRepositoryInfo.APIVersion = PSRepositoryInfo.APIVersion.unknown
@@ -222,7 +225,6 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
222225
ResponseUtil currentResponseUtil = ResponseUtilFactory.GetResponseUtil(currentRepository);
223226
_cmdletPassedIn.WriteDebug($"Searching through repository '{currentRepository.Name}'");
224227

225-
bool shouldReportErrorForEachRepo = !suppressErrors && !_repositoryNameContainsWildcard;
226228
foreach (PSResourceInfo currentPkg in SearchByNames(currentServer, currentResponseUtil, currentRepository, shouldReportErrorForEachRepo))
227229
{
228230
if (currentPkg == null)

src/code/LocalServerApiCalls.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ internal class LocalServerAPICalls : ServerApiCall
2424
private readonly PSCmdlet _cmdletPassedIn;
2525
private readonly FindResponseType _localServerFindResponseType = FindResponseType.ResponseHashtable;
2626
private readonly string _fileTypeKey = "filetype";
27+
private readonly bool _writeWarnings = false;
2728

2829
#endregion
2930

3031
#region Constructor
3132

32-
public LocalServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, NetworkCredential networkCredential) : base (repository, networkCredential)
33+
public LocalServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, NetworkCredential networkCredential, bool writeWarnings = false) : base (repository, networkCredential)
3334
{
3435
this.Repository = repository;
3536
_cmdletPassedIn = cmdletPassedIn;
37+
_writeWarnings = writeWarnings;
3638
}
3739

3840
#endregion
@@ -270,7 +272,11 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu
270272
}
271273
catch (Exception e)
272274
{
273-
_cmdletPassedIn.WriteWarning($"Unable to resolve repository source '{Repository.Uri.LocalPath}' due to exception: {e.Message}");
275+
if (_writeWarnings)
276+
{
277+
_cmdletPassedIn.WriteWarning($"Unable to resolve repository source '{Repository.Uri.LocalPath}' due to exception: {e.Message}");
278+
}
279+
274280
errRecord = new ErrorRecord(
275281
exception: e,
276282
"FileAccessFailure",

src/code/ServerFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static string UserAgentString()
3030

3131
internal class ServerFactory
3232
{
33-
public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, NetworkCredential networkCredential)
33+
public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, NetworkCredential networkCredential, bool writeWarnings = false)
3434
{
3535
PSRepositoryInfo.APIVersion repoApiVersion = repository.ApiVersion;
3636
ServerApiCall currentServer = null;
@@ -47,7 +47,7 @@ public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdl
4747
break;
4848

4949
case PSRepositoryInfo.APIVersion.Local:
50-
currentServer = new LocalServerAPICalls(repository, cmdletPassedIn, networkCredential);
50+
currentServer = new LocalServerAPICalls(repository, cmdletPassedIn, networkCredential, writeWarnings);
5151
break;
5252

5353
case PSRepositoryInfo.APIVersion.NugetServer:

0 commit comments

Comments
 (0)