Skip to content

Commit a4255ff

Browse files
authored
Implement -Quiet param for Install and Update -PSResource (#561)
1 parent d9e1db9 commit a4255ff

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/code/InstallHelper.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -326,31 +326,35 @@ private List<PSResourceInfo> InstallPackage(
326326

327327
_cmdletPassedIn.WriteVerbose(string.Format("Begin installing package: '{0}'", pkg.Name));
328328

329-
int activityId = 0;
330-
string activity = "";
331-
string statusDescription = "";
332-
333-
if (pkgNamesToInstall.ToList().Contains(pkg.Name, StringComparer.InvariantCultureIgnoreCase))
334-
{
335-
// Installing parent package (one whose name was passed in to install)
336-
activityId = 0;
337-
activity = string.Format("Installing {0}...", pkg.Name);
338-
statusDescription = string.Format("{0}% Complete:", Math.Round(((double) totalPkgsCount/totalPkgs) * 100), 2);
339-
currentPkgNumOfDependentPkgs = pkg.Dependencies.Count();
340-
dependentPkgCount = 1;
341-
}
342-
else
329+
// Will suppress progress bar if -Quiet is passed in
330+
if (!_quiet)
343331
{
344-
// Installing dependent package
345-
activityId = 1;
346-
activity = string.Format("Installing dependent package {0}...", pkg.Name);
347-
statusDescription = string.Format("{0}% Complete:", Math.Round(((double) dependentPkgCount/currentPkgNumOfDependentPkgs) * 100), 2);
348-
dependentPkgCount++;
332+
int activityId = 0;
333+
string activity = "";
334+
string statusDescription = "";
335+
336+
if (pkgNamesToInstall.ToList().Contains(pkg.Name, StringComparer.InvariantCultureIgnoreCase))
337+
{
338+
// Installing parent package (one whose name was passed in to install)
339+
activityId = 0;
340+
activity = string.Format("Installing {0}...", pkg.Name);
341+
statusDescription = string.Format("{0}% Complete:", Math.Round(((double)totalPkgsCount / totalPkgs) * 100), 2);
342+
currentPkgNumOfDependentPkgs = pkg.Dependencies.Count();
343+
dependentPkgCount = 1;
344+
}
345+
else
346+
{
347+
// Installing dependent package
348+
activityId = 1;
349+
activity = string.Format("Installing dependent package {0}...", pkg.Name);
350+
statusDescription = string.Format("{0}% Complete:", Math.Round(((double)dependentPkgCount / currentPkgNumOfDependentPkgs) * 100), 2);
351+
dependentPkgCount++;
352+
}
353+
354+
var progressRecord = new ProgressRecord(activityId, activity, statusDescription);
355+
_cmdletPassedIn.WriteProgress(progressRecord);
349356
}
350357

351-
var progressRecord = new ProgressRecord(activityId, activity, statusDescription);
352-
_cmdletPassedIn.WriteProgress(progressRecord);
353-
354358
// Create PackageIdentity in order to download
355359
string createFullVersion = pkg.Version.ToString();
356360
if (pkg.IsPrerelease)

src/code/SavePSResource.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ public string Path
134134
[Parameter]
135135
public SwitchParameter SkipDependencyCheck { get; set; }
136136

137+
/// <summary>
138+
/// Suppresses progress information.
139+
/// </summary>
140+
[Parameter(ParameterSetName = NameParameterSet)]
141+
[Parameter(ParameterSetName = InputObjectParameterSet)]
142+
public SwitchParameter Quiet { get; set; }
143+
137144
#endregion
138145

139146
#region Method overrides
@@ -246,7 +253,7 @@ private void ProcessSaveHelper(string[] pkgNames, bool pkgPrerelease, string[] p
246253
prerelease: pkgPrerelease,
247254
repository: pkgRepository,
248255
acceptLicense: true,
249-
quiet: true,
256+
quiet: Quiet,
250257
reinstall: true,
251258
force: false,
252259
trustRepository: TrustRepository,

0 commit comments

Comments
 (0)