Skip to content

Replace WriteDebug() with WriteVerbose() #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 4, 2021
Merged
8 changes: 4 additions & 4 deletions src/code/FindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
PSRepositoryInfo psGalleryScripts = new PSRepositoryInfo(_psGalleryScriptsRepoName, psGalleryScriptsUrl, repositoriesToSearch[i].Priority, false);
if (_type == ResourceType.None)
{
_cmdletPassedIn.WriteDebug("Null Type provided, so add PSGalleryScripts repository");
_cmdletPassedIn.WriteVerbose("Null Type provided, so add PSGalleryScripts repository");
repositoriesToSearch.Insert(i + 1, psGalleryScripts);
}
else if (_type != ResourceType.None && _type == ResourceType.Script)
{
_cmdletPassedIn.WriteDebug("Type Script provided, so add PSGalleryScripts and remove PSGallery (Modules only)");
_cmdletPassedIn.WriteVerbose("Type Script provided, so add PSGalleryScripts and remove PSGallery (Modules only)");
repositoriesToSearch.Insert(i + 1, psGalleryScripts);
repositoriesToSearch.RemoveAt(i); // remove PSGallery
}
Expand All @@ -124,7 +124,7 @@ public IEnumerable<PSResourceInfo> FindByResourceName(

for (int i = 0; i < repositoriesToSearch.Count && _pkgsLeftToFind.Any(); i++)
{
_cmdletPassedIn.WriteDebug(string.Format("Searching in repository {0}", repositoriesToSearch[i].Name));
_cmdletPassedIn.WriteVerbose(string.Format("Searching in repository {0}", repositoriesToSearch[i].Name));
foreach (var pkg in SearchFromRepository(
repositoryName: repositoriesToSearch[i].Name,
repositoryUrl: repositoriesToSearch[i].Url))
Expand Down Expand Up @@ -224,7 +224,7 @@ public IEnumerable<PSResourceInfo> SearchAcrossNamesInRepository(
{
if (String.IsNullOrWhiteSpace(pkgName))
{
_cmdletPassedIn.WriteDebug(String.Format("Package name: {0} provided was null or whitespace, so name was skipped in search.",
_cmdletPassedIn.WriteVerbose(String.Format("Package name: {0} provided was null or whitespace, so name was skipped in search.",
pkgName == null ? "null string" : pkgName));
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/code/GetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public IEnumerable<String> FilterPkgPathsByVersion(VersionRange versionRange, Li
// if no version is specified, just get the latest version
foreach (string pkgPath in dirsToSearch)
{
_cmdletPassedIn.WriteDebug(string.Format("Searching through package path: '{0}'", pkgPath));
_cmdletPassedIn.WriteVerbose(string.Format("Searching through package path: '{0}'", pkgPath));

// if this is a module directory
if (Directory.Exists(pkgPath))
{
// search modules paths
// ./Modules/Test-Module/1.0.0
// ./Modules/Test-Module/2.0.0
_cmdletPassedIn.WriteDebug(string.Format("Searching through package path: '{0}'", pkgPath));
_cmdletPassedIn.WriteVerbose(string.Format("Searching through package path: '{0}'", pkgPath));

string[] versionsDirs = Utils.GetSubDirectories(pkgPath);

Expand All @@ -111,7 +111,7 @@ public IEnumerable<String> FilterPkgPathsByVersion(VersionRange versionRange, Li

foreach (string versionPath in versionsDirs)
{
_cmdletPassedIn.WriteDebug(string.Format("Searching through package version path: '{0}'", versionPath));
_cmdletPassedIn.WriteVerbose(string.Format("Searching through package version path: '{0}'", versionPath));
DirectoryInfo dirInfo = new DirectoryInfo(versionPath);

// if the version is not valid, we'll just skip it and output a debug message
Expand Down
6 changes: 3 additions & 3 deletions src/code/GetInstalledPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected override void BeginProcessing()
_pathsToSearch = new List<string>();
if (Path != null)
{
WriteDebug(string.Format("Provided path is: '{0}'", Path));
WriteVerbose(string.Format("Provided path is: '{0}'", Path));

var resolvedPaths = SessionState.Path.GetResolvedPSPathFromPSPath(Path);
if (resolvedPaths.Count != 1)
Expand All @@ -85,7 +85,7 @@ protected override void BeginProcessing()
}

var resolvedPath = resolvedPaths[0].Path;
WriteDebug(string.Format("Provided resolved path is '{0}'", resolvedPath));
WriteVerbose(string.Format("Provided resolved path is '{0}'", resolvedPath));

var versionPaths = Utils.GetSubDirectories(resolvedPath);
if (versionPaths.Length == 0)
Expand All @@ -110,7 +110,7 @@ protected override void BeginProcessing()

protected override void ProcessRecord()
{
WriteDebug("Entering GetInstalledPSResource");
WriteVerbose("Entering GetInstalledPSResource");

var namesToSearch = Utils.ProcessNameWildcards(Name, out string[] errorMsgs, out bool _);
foreach (string error in errorMsgs)
Expand Down
4 changes: 2 additions & 2 deletions src/code/GetPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void BeginProcessing()
{
try
{
WriteDebug("Calling API to check repository store exists in non-corrupted state");
WriteVerbose("Calling API to check repository store exists in non-corrupted state");
RepositorySettings.CheckRepositoryStore();
}
catch (PSInvalidOperationException e)
Expand All @@ -56,7 +56,7 @@ protected override void BeginProcessing()
protected override void ProcessRecord()
{
string nameArrayAsString = (Name == null || !Name.Any() || string.Equals(Name[0], "*") || Name[0] == null) ? "all" : string.Join(", ", Name);
WriteDebug(String.Format("reading repository: {0}. Calling Read() API now", nameArrayAsString));
WriteVerbose(String.Format("reading repository: {0}. Calling Read() API now", nameArrayAsString));
List<PSRepositoryInfo> items = RepositorySettings.Read(Name, out string[] errorList);

// handle non-terminating errors
Expand Down
50 changes: 25 additions & 25 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void InstallPackages(
bool includeXML,
List<string> pathsToInstallPkg)
{
_cmdletPassedIn.WriteDebug(string.Format("Parameters passed in >>> Name: '{0}'; Version: '{1}'; Prerelease: '{2}'; Repository: '{3}'; " +
_cmdletPassedIn.WriteVerbose(string.Format("Parameters passed in >>> Name: '{0}'; Version: '{1}'; Prerelease: '{2}'; Repository: '{3}'; " +
"AcceptLicense: '{4}'; Quiet: '{5}'; Reinstall: '{6}'; TrustRepository: '{7}'; NoClobber: '{8}';",
string.Join(",", names),
(versionRange != null ? versionRange.OriginalString : string.Empty),
Expand Down Expand Up @@ -124,13 +124,13 @@ public void ProcessRepositories(string[] packageNames, string[] repository, bool

var sourceTrusted = false;
string repoName = repo.Name;
_cmdletPassedIn.WriteDebug(string.Format("Attempting to search for packages in '{0}'", repoName));
_cmdletPassedIn.WriteVerbose(string.Format("Attempting to search for packages in '{0}'", repoName));

// Source is only trusted if it's set at the repository level to be trusted, -TrustRepository flag is true, -Force flag is true
// OR the user issues trust interactively via console.
if (repo.Trusted == false && !trustRepository && !_force)
{
_cmdletPassedIn.WriteDebug("Checking if untrusted repository should be used");
_cmdletPassedIn.WriteVerbose("Checking if untrusted repository should be used");

if (!(yesToAll || noToAll))
{
Expand All @@ -146,7 +146,7 @@ public void ProcessRepositories(string[] packageNames, string[] repository, bool

if (sourceTrusted || yesToAll)
{
_cmdletPassedIn.WriteDebug("Untrusted repository accepted as trusted source.");
_cmdletPassedIn.WriteVerbose("Untrusted repository accepted as trusted source.");

// If it can't find the pkg in one repository, it'll look for it in the next repo in the list
var isLocalRepo = repo.Url.AbsoluteUri.StartsWith(Uri.UriSchemeFile + Uri.SchemeDelimiter, StringComparison.OrdinalIgnoreCase);
Expand Down Expand Up @@ -279,7 +279,7 @@ private List<string> InstallPackage(IEnumerable<PSResourceInfo> pkgsToInstall, s

if (!NuGetVersion.TryParse(createFullVersion, out NuGetVersion pkgVersion))
{
_cmdletPassedIn.WriteDebug(string.Format("Error parsing package '{0}' version '{1}' into a NuGetVersion", p.Name, p.Version.ToString()));
_cmdletPassedIn.WriteVerbose(string.Format("Error parsing package '{0}' version '{1}' into a NuGetVersion", p.Name, p.Version.ToString()));
continue;
}
var pkgIdentity = new PackageIdentity(p.Name, pkgVersion);
Expand Down Expand Up @@ -350,7 +350,7 @@ private List<string> InstallPackage(IEnumerable<PSResourceInfo> pkgsToInstall, s
}
catch (Exception e)
{
_cmdletPassedIn.WriteDebug(string.Format("Error attempting download: '{0}'", e.Message));
_cmdletPassedIn.WriteVerbose(string.Format("Error attempting download: '{0}'", e.Message));
}
finally
{
Expand All @@ -359,7 +359,7 @@ private List<string> InstallPackage(IEnumerable<PSResourceInfo> pkgsToInstall, s
}
}

_cmdletPassedIn.WriteDebug(string.Format("Successfully able to download package from source to: '{0}'", tempInstallPath));
_cmdletPassedIn.WriteVerbose(string.Format("Successfully able to download package from source to: '{0}'", tempInstallPath));

// Prompt if module requires license acceptance (need to read info license acceptance info from the module manifest)
// pkgIdentity.Version.Version gets the version without metadata or release labels.
Expand Down Expand Up @@ -426,12 +426,12 @@ private List<string> InstallPackage(IEnumerable<PSResourceInfo> pkgsToInstall, s
}
catch (Exception e)
{
_cmdletPassedIn.WriteDebug(string.Format("Unable to successfully install package '{0}': '{1}'", p.Name, e.Message));
_cmdletPassedIn.WriteVerbose(string.Format("Unable to successfully install package '{0}': '{1}'", p.Name, e.Message));
}
finally
{
// Delete the temp directory and all its contents
_cmdletPassedIn.WriteDebug(string.Format("Attempting to delete '{0}'", tempInstallPath));
_cmdletPassedIn.WriteVerbose(string.Format("Attempting to delete '{0}'", tempInstallPath));
if (Directory.Exists(tempInstallPath))
{
Directory.Delete(tempInstallPath, true);
Expand Down Expand Up @@ -551,32 +551,32 @@ private void DeleteExtraneousFiles(string tempInstallPath, PackageIdentity pkgId
// Unforunately have to check if each file exists because it may or may not be there
if (File.Exists(nupkgSHAToDelete))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting '{0}'", nupkgSHAToDelete));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting '{0}'", nupkgSHAToDelete));
File.Delete(nupkgSHAToDelete);
}
if (File.Exists(nuspecToDelete))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting '{0}'", nuspecToDelete));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting '{0}'", nuspecToDelete));
File.Delete(nuspecToDelete);
}
if (File.Exists(nupkgToDelete))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting '{0}'", nupkgToDelete));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting '{0}'", nupkgToDelete));
File.Delete(nupkgToDelete);
}
if (File.Exists(contentTypesToDelete))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting '{0}'", contentTypesToDelete));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting '{0}'", contentTypesToDelete));
File.Delete(contentTypesToDelete);
}
if (Directory.Exists(relsDirToDelete))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting '{0}'", relsDirToDelete));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting '{0}'", relsDirToDelete));
Directory.Delete(relsDirToDelete, true);
}
if (Directory.Exists(packageDirToDelete))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting '{0}'", packageDirToDelete));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting '{0}'", packageDirToDelete));
Directory.Delete(packageDirToDelete, true);
}
}
Expand Down Expand Up @@ -611,50 +611,50 @@ private void MoveFilesIntoInstallPath(
{
// Need to delete old xml files because there can only be 1 per script
var scriptXML = p.Name + "_InstalledScriptInfo.xml";
_cmdletPassedIn.WriteDebug(string.Format("Checking if path '{0}' exists: ", File.Exists(Path.Combine(installPath, "InstalledScriptInfos", scriptXML))));
_cmdletPassedIn.WriteVerbose(string.Format("Checking if path '{0}' exists: ", File.Exists(Path.Combine(installPath, "InstalledScriptInfos", scriptXML))));
if (File.Exists(Path.Combine(installPath, "InstalledScriptInfos", scriptXML)))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting script metadata XML"));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting script metadata XML"));
File.Delete(Path.Combine(installPath, "InstalledScriptInfos", scriptXML));
}

_cmdletPassedIn.WriteDebug(string.Format("Moving '{0}' to '{1}'", Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, "InstalledScriptInfos", scriptXML)));
_cmdletPassedIn.WriteVerbose(string.Format("Moving '{0}' to '{1}'", Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, "InstalledScriptInfos", scriptXML)));
Utils.MoveFiles(Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, "InstalledScriptInfos", scriptXML));

// Need to delete old script file, if that exists
_cmdletPassedIn.WriteDebug(string.Format("Checking if path '{0}' exists: ", File.Exists(Path.Combine(finalModuleVersionDir, p.Name + ".ps1"))));
_cmdletPassedIn.WriteVerbose(string.Format("Checking if path '{0}' exists: ", File.Exists(Path.Combine(finalModuleVersionDir, p.Name + ".ps1"))));
if (File.Exists(Path.Combine(finalModuleVersionDir, p.Name + ".ps1")))
{
_cmdletPassedIn.WriteDebug(string.Format("Deleting script file"));
_cmdletPassedIn.WriteVerbose(string.Format("Deleting script file"));
File.Delete(Path.Combine(finalModuleVersionDir, p.Name + ".ps1"));
}
}

_cmdletPassedIn.WriteDebug(string.Format("Moving '{0}' to '{1}'", scriptPath, Path.Combine(finalModuleVersionDir, p.Name + ".ps1")));
_cmdletPassedIn.WriteVerbose(string.Format("Moving '{0}' to '{1}'", scriptPath, Path.Combine(finalModuleVersionDir, p.Name + ".ps1")));
Utils.MoveFiles(scriptPath, Path.Combine(finalModuleVersionDir, p.Name + ".ps1"));
}
else
{
// If new path does not exist
if (!Directory.Exists(newPathParent))
{
_cmdletPassedIn.WriteDebug(string.Format("Attempting to move '{0}' to '{1}'", tempModuleVersionDir, finalModuleVersionDir));
_cmdletPassedIn.WriteVerbose(string.Format("Attempting to move '{0}' to '{1}'", tempModuleVersionDir, finalModuleVersionDir));
Directory.CreateDirectory(newPathParent);
Utils.MoveDirectory(tempModuleVersionDir, finalModuleVersionDir);
}
else
{
_cmdletPassedIn.WriteDebug(string.Format("Temporary module version directory is: '{0}'", tempModuleVersionDir));
_cmdletPassedIn.WriteVerbose(string.Format("Temporary module version directory is: '{0}'", tempModuleVersionDir));

// At this point if
if (Directory.Exists(finalModuleVersionDir))
{
// Delete the directory path before replacing it with the new module
_cmdletPassedIn.WriteDebug(string.Format("Attempting to delete '{0}'", finalModuleVersionDir));
_cmdletPassedIn.WriteVerbose(string.Format("Attempting to delete '{0}'", finalModuleVersionDir));
Directory.Delete(finalModuleVersionDir, true);
}

_cmdletPassedIn.WriteDebug(string.Format("Attempting to move '{0}' to '{1}'", tempModuleVersionDir, finalModuleVersionDir));
_cmdletPassedIn.WriteVerbose(string.Format("Attempting to move '{0}' to '{1}'", tempModuleVersionDir, finalModuleVersionDir));
Utils.MoveDirectory(tempModuleVersionDir, finalModuleVersionDir);
}
}
Expand Down
Loading