-
Notifications
You must be signed in to change notification settings - Fork 98
Refactor SetPSResourceRepository cmdlet #359
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
PaulHigin
merged 17 commits into
PowerShell:development
from
anamnavi:refactor-setpsresourcerepository
Jun 7, 2021
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
079d596
added implemenation and test for Set
anamnavi 18f3262
remove unnecessary comments
anamnavi 30b2000
add some summary parameter comments
anamnavi ed89e97
remove more comments
anamnavi 2bd5eb3
remove NameParameterSetHelper()
anamnavi e09c530
add test and code for detecting if name key in repositories param is …
anamnavi 946edcc
update help doc for Set
anamnavi 1f8ecfd
fix codacy issues
anamnavi 8530b50
add Debug statements
anamnavi 98e4e8c
add newline at end of SetPSResourceRepository.cs file
anamnavi 4013ee0
used parameterset name const variables instead of parameter set strings
anamnavi 2db9f95
remove Credential parameter
anamnavi bb87f17
remove Proxy and ProxyCredential parameters
anamnavi a1a01d2
remove Credential parameter from help docs as well
anamnavi ea5370f
trim whitespace with Trim(), no param needed
anamnavi cf0e223
order directives alphabetically
anamnavi a3d08ce
remove Priority and URL parameters from pipeline
anamnavi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,10 +114,11 @@ public static PSRepositoryInfo Add(string repoName, Uri repoURL, int repoPriorit | |
/// Updates a repository name, URL, priority, or installation policy | ||
/// Returns: void | ||
/// </summary> | ||
public static void Update(string repoName, Uri repoURL, int repoPriority, bool? repoTrusted) | ||
public static PSRepositoryInfo Update(string repoName, Uri repoURL, int repoPriority, bool? repoTrusted) | ||
{ | ||
Dbg.Assert(!string.IsNullOrEmpty(repoName), "Repository name cannot be null or empty"); | ||
|
||
PSRepositoryInfo updatedRepo; | ||
try | ||
{ | ||
// Open file | ||
|
@@ -132,28 +133,47 @@ public static void Update(string repoName, Uri repoURL, int repoPriority, bool? | |
// Get root of XDocument (XElement) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On line 129, error is not ArgumentException, the argument is valid. Should be ItemNotFoundException error. |
||
var root = doc.Root; | ||
|
||
// A null URL value passed in signifies the URL was not attempted to be set. | ||
// So only set Url attribute if non-null value passed in for repoUrl | ||
if (repoURL != null) | ||
{ | ||
node.Attribute("Url").Value = repoURL.AbsoluteUri; | ||
} | ||
|
||
// A negative Priority value passed in signifies the Priority value was not attempted to be set. | ||
// So only set Priority attribute if non-null value passed in for repoPriority | ||
if (repoPriority >= 0) | ||
{ | ||
node.Attribute("Priority").Value = repoPriority.ToString(); | ||
} | ||
|
||
// A null Trusted value passed in signifies the Trusted value was not attempted to be set. | ||
// So only set Trusted attribute if non-null value passed in for repoTrusted. | ||
if (repoTrusted != null) | ||
{ | ||
node.Attribute("Trusted").Value = repoTrusted.ToString(); | ||
} | ||
|
||
// Create Uri from node Url attribute to create PSRepositoryInfo item to return. | ||
if (!Uri.TryCreate(node.Attribute("Url").Value, UriKind.Absolute, out Uri thisUrl)) | ||
{ | ||
throw new PSInvalidOperationException(String.Format("Unable to read incorrectly formatted URL for repo {0}", repoName)); | ||
} | ||
|
||
updatedRepo = new PSRepositoryInfo(repoName, | ||
thisUrl, | ||
Int32.Parse(node.Attribute("Priority").Value), | ||
Boolean.Parse(node.Attribute("Trusted").Value)); | ||
|
||
// Close the file | ||
root.Save(FullRepositoryPath); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new PSInvalidOperationException(String.Format("Updating to repository store failed: {0}", e.Message)); | ||
} | ||
|
||
return updatedRepo; | ||
} | ||
|
||
/// <summary> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update comment (// Returns: void)