-
Notifications
You must be signed in to change notification settings - Fork 98
Script file info cmdlets #602
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
Closed
Closed
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
0d62ecb
parse psScriptInfo comment out to hashtable
anamnavi bd47e2b
merge with changes from master for Utils.cs
anamnavi 7bd8c10
remove extra lines
anamnavi 5db7d3b
set successfullyParsed variable
anamnavi 77e29c6
change TestRequiredResourceFile.json path referenced to not be relative
anamnavi b74077b
skeleton for *-FileScriptInfo cmdlets
anamnavi 92b0eaa
skeleton for PSSCriptFileInfo.cs
anamnavi b684762
PSScriptInfo comment of New-PSScriptFileInfo cmdlet works
anamnavi 6851f09
RequiresString and CommentHelp string now print
anamnavi 653d47c
move moduleSpecification parsing code from Utils to PSScriptFileInfo …
anamnavi da9eb75
commentHelpInfo string works properly now
anamnavi b90caf8
fix typo
anamnavi ddcab1a
ensure Path and PassThru work
anamnavi cacf746
clean up code
anamnavi 7f023cb
test-scriptfileinfo now works; but PSScriptFileInfo constructor takes…
anamnavi 262cc81
TestScriptFileInfo works and Utils creates ModuleSpecification objects
anamnavi 3f4ed6f
Test-ScriptFileInfo now works
anamnavi 04ace4b
add code for Update-ScriptFileInfo; still need to test
anamnavi 015d4cd
add help docs; Update works except for RequiredModules population
anamnavi 22156a2
add comemnts
anamnavi b441874
fix bug where update doesn't retain requiredModules
anamnavi cdd52d6
New-PSScriptFileInfo cmdlet: rename Path to FilePath and make FilePat…
anamnavi f4a205d
update help file for New-PSScriptFileInfo cmdlet
anamnavi b07fab2
Test-PSScriptFileInfo cmdlet: rename Path to FilePath
anamnavi ce1ae07
Update-PSScriptFileInfo cmdlet: change Path to FilePath
anamnavi 4cb3e0f
gets end of file ast content; some duplication issues though still
anamnavi afaeac0
refactor update to pass in regalar argument for original script and o…
anamnavi 70aba50
refactor udpate to use ref variable to pass PSScriptFileInfo
anamnavi 792cc12
ensure update and test work and former validates as a separate step
anamnavi dbe1878
fix for why Test would fail on an updated script
anamnavi 7adeccd
end of file contents are now sucessfully grabbed
anamnavi 3c9867a
Merge branch 'master' of https://github.com/anamnavi/PowerShellGet in…
anamnavi 92dfb7b
revert changes to InstallHelper; add that to separate PR
anamnavi 73e0fe7
change how we write to file to use FileStream
anamnavi 932dfae
clean up code in Test-PSScriptFileInfo
anamnavi 8400d6f
use TryCreateUri instead of TryCreateUrl
anamnavi 0d9c74a
rename PSScriptFileInfo static methods
anamnavi 0fddba4
for Update-PSScriptFileInfo's errors make it clear which errors come …
anamnavi c5213dd
clean up New-PSScriptFileInfo
anamnavi 9b131af
remove unneccessary changes from Utils
anamnavi 200f7b0
Revert change to install test
anamnavi 4aff970
add validation on Description property to not contain <# or #>
anamnavi 3d8eb10
fix typo
anamnavi 3a0eac6
refactor CreateModuleSpecification() to have out variable of type Mod…
anamnavi ac696ac
some changes to script file info cmdlets
anamnavi d49fba4
comment out buggy code
anamnavi 20f3c3c
fix bug in .ps1 file creation that didn't recognize description as va…
anamnavi 74528fa
add tests for New-PSScriptFileInfo
anamnavi c799147
Merge branch 'master' of https://github.com/anamnavi/PowerShellGet in…
anamnavi 4f9810f
fix bug with RequiredMOdules ModuleSpecification(Hashtable) creation …
anamnavi adf3550
pull changes from master, resolve merge conflicts
anamnavi deeaddb
add tests for Test-PSScriptFileInfo
anamnavi 2da70ca
clean up comments in test
anamnavi f58e6ce
clean up code and tests
anamnavi 37aeb37
fix bug in test
anamnavi 8e7b6c2
push changes temporarily
anamnavi b20f73d
remove succcesfullyParsed var
anamnavi a175c69
refactor TryParsePSScript() to use helpers
anamnavi 4cd6fdd
fix bug with RequiredModules
anamnavi d7a9d5b
cmdlets should use new refactored TryParseScriptIntoPSScriptInfo method
anamnavi 529b532
make certain methods private
anamnavi f1cad37
make method internal for update
anamnavi 98ecc51
code review changes
anamnavi a61ba87
add RemoveSignature param to Update
anamnavi 8fc0b9f
fix Description block newline padding bug
anamnavi d7d763b
add tests for RemoveSignature parameter
anamnavi f465015
add try catch around ModuleSpecification constructor call
anamnavi a50251c
clean up code comments
anamnavi 3a6e0a8
use private setters
anamnavi 0632927
incorporating CR feedback
anamnavi d1ee41e
Merge branch 'master' of https://github.com/anamnavi/PowerShellGet in…
anamnavi b758818
fix typo
anamnavi edd0699
make hastable keys insensitive case
anamnavi fed5232
remove help docs for now and include in a separate PR
anamnavi ea3b638
pull in changes from master including tests
anamnavi 6d2d3c3
New-PSScriptFileInfo- add code to resolve non-existant (yet) relative…
anamnavi 2bdc8d8
remove Force parameter from Update
anamnavi 2aaa5c1
remoe unnecessary directives, remove todo comments from tests
anamnavi dae5675
fix bug with ReleaseNotes, PrivateData being on next line than .KEY
anamnavi 59eab74
clean up code comments
anamnavi 2490dd4
refactor commentLine parsing into helper method, and add . to /// lines
anamnavi bfcaa42
code should be in EndProcessing() not ProcessRecord()
anamnavi c21aecf
address PR feedback
anamnavi 7600d14
address more PR feedback
anamnavi 6bdbb86
fix bug with Description property being overriden in metadata hashtable
anamnavi e9765e0
fix todo
anamnavi bf9b21b
Pester TestDrive will clean up folders created there, don't do oursel…
anamnavi 5d1f1a7
add test to Update to ensure old data is not overwritten by update
anamnavi 025438f
add file line reading logic (WIP) for initial review
anamnavi 7d7eea6
line by line parsing works as expected, and added error handling for …
anamnavi c12b11a
notes from design meeting
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 |
---|---|---|
@@ -0,0 +1,259 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Management.Automation; | ||
using Microsoft.PowerShell.Commands; | ||
using Microsoft.PowerShell.PowerShellGet.UtilClasses; | ||
|
||
namespace Microsoft.PowerShell.PowerShellGet.Cmdlets | ||
{ | ||
/// <summary> | ||
/// Creates a new .ps1 file with script information required for publishing a script. | ||
/// </summary> | ||
[Cmdlet(VerbsCommon.New, "PSScriptFileInfo")] | ||
public sealed class NewPSScriptFileInfo : PSCmdlet | ||
{ | ||
#region Parameters | ||
|
||
/// <summary> | ||
/// The path the .ps1 script info file will be created at. | ||
/// </summary> | ||
[Parameter(Position = 0, Mandatory = true)] | ||
[ValidateNotNullOrEmpty] | ||
public string FilePath { get; set; } | ||
|
||
/// <summary> | ||
/// The version of the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string Version { get; set; } | ||
|
||
/// <summary> | ||
/// The author of the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string Author { get; set; } | ||
|
||
/// <summary> | ||
/// The description of the script. | ||
/// </summary> | ||
[Parameter(Mandatory = true)] | ||
[ValidateNotNullOrEmpty()] | ||
public string Description { get; set; } | ||
|
||
/// <summary> | ||
/// A unique identifier for the script. The GUID can be used to distinguish among scripts with the same name. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public Guid Guid { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the company owning the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string CompanyName { get; set; } | ||
|
||
/// <summary> | ||
/// The copyright statement for the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string Copyright { get; set; } | ||
|
||
/// <summary> | ||
/// The list of modules required by the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public Hashtable[] RequiredModules { get; set; } | ||
|
||
/// <summary> | ||
/// The list of external module dependencies taken by this script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string[] ExternalModuleDependencies { get; set; } | ||
|
||
/// <summary> | ||
/// The list of scripts required by the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string[] RequiredScripts { get; set; } | ||
|
||
/// <summary> | ||
/// The list of external script dependencies taken by this script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string[] ExternalScriptDependencies { get; set; } | ||
|
||
/// <summary> | ||
/// The tags associated with the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string[] Tags { get; set; } | ||
|
||
/// <summary> | ||
/// The Uri for the project associated with the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string ProjectUri { get; set; } | ||
|
||
/// <summary> | ||
/// The Uri for the license associated with the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string LicenseUri { get; set; } | ||
|
||
/// <summary> | ||
/// The Uri for the icon associated with the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string IconUri { get; set; } | ||
|
||
/// <summary> | ||
/// The release notes for the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string ReleaseNotes { get; set; } | ||
|
||
/// <summary> | ||
/// The private data associated with the script. | ||
/// </summary> | ||
[Parameter] | ||
[ValidateNotNullOrEmpty()] | ||
public string PrivateData { get; set; } | ||
|
||
/// <summary> | ||
/// If used with Path parameter and .ps1 file specified at the path exists, it rewrites the file. | ||
/// </summary> | ||
[Parameter] | ||
public SwitchParameter Force { get; set; } | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
protected override void EndProcessing() | ||
{ | ||
// validate Uri related parameters passed in as strings | ||
Uri projectUri = null; | ||
if (!String.IsNullOrEmpty(ProjectUri) && !Utils.TryCreateValidUri(uriString: ProjectUri, | ||
cmdletPassedIn: this, | ||
uriResult: out projectUri, | ||
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errorRecord: out ErrorRecord projectErrorRecord)) | ||
{ | ||
ThrowTerminatingError(projectErrorRecord); | ||
} | ||
|
||
Uri licenseUri = null; | ||
if (!String.IsNullOrEmpty(LicenseUri) && !Utils.TryCreateValidUri(uriString: LicenseUri, | ||
cmdletPassedIn: this, | ||
uriResult: out licenseUri, | ||
errorRecord: out ErrorRecord licenseErrorRecord)) | ||
{ | ||
ThrowTerminatingError(licenseErrorRecord); | ||
} | ||
|
||
Uri iconUri = null; | ||
if (!String.IsNullOrEmpty(IconUri) && !Utils.TryCreateValidUri(uriString: IconUri, | ||
cmdletPassedIn: this, | ||
uriResult: out iconUri, | ||
errorRecord: out ErrorRecord iconErrorRecord)) | ||
{ | ||
ThrowTerminatingError(iconErrorRecord); | ||
} | ||
|
||
if (!FilePath.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var exMessage = "Path needs to end with a .ps1 file. Example: C:/Users/john/x/MyScript.ps1"; | ||
var ex = new ArgumentException(exMessage); | ||
var InvalidPathError = new ErrorRecord(ex, "InvalidPath", ErrorCategory.InvalidArgument, null); | ||
ThrowTerminatingError(InvalidPathError); | ||
} | ||
|
||
var resolvedFilePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(FilePath); | ||
if (String.IsNullOrEmpty(resolvedFilePath)) | ||
{ | ||
var exMessage = "Error: Could not resolve provided Path argument into a single path."; | ||
var ex = new PSArgumentException(exMessage); | ||
var InvalidPathArgumentError = new ErrorRecord(ex, "InvalidPathArgumentError", ErrorCategory.InvalidArgument, null); | ||
ThrowTerminatingError(InvalidPathArgumentError); | ||
} | ||
|
||
if (File.Exists(resolvedFilePath) && !Force) | ||
{ | ||
// .ps1 file at specified location already exists and Force parameter isn't used to rewrite the file | ||
var exMessage = ".ps1 file at specified path already exists. Specify a different location or use -Force parameter to overwrite the .ps1 file."; | ||
var ex = new ArgumentException(exMessage); | ||
var ScriptAtPathAlreadyExistsError = new ErrorRecord(ex, "ScriptAtPathAlreadyExists", ErrorCategory.InvalidArgument, null); | ||
ThrowTerminatingError(ScriptAtPathAlreadyExistsError); | ||
} | ||
|
||
ModuleSpecification[] validatedRequiredModuleSpecifications = new ModuleSpecification[]{}; | ||
if (RequiredModules != null && RequiredModules.Length > 0) | ||
{ | ||
if (!Utils.TryCreateModuleSpecification( | ||
moduleSpecHashtables: RequiredModules, | ||
out validatedRequiredModuleSpecifications, | ||
out ErrorRecord[] moduleSpecErrors)) | ||
{ | ||
foreach (ErrorRecord err in moduleSpecErrors) | ||
{ | ||
WriteError(err); | ||
} | ||
|
||
return; | ||
} | ||
} | ||
|
||
PSScriptFileInfo scriptInfo = new PSScriptFileInfo( | ||
version: Version, | ||
guid: Guid, | ||
author: Author, | ||
companyName: CompanyName, | ||
copyright: Copyright, | ||
tags: Tags, | ||
licenseUri: licenseUri, | ||
projectUri: projectUri, | ||
iconUri: iconUri, | ||
requiredModules: validatedRequiredModuleSpecifications, | ||
externalModuleDependencies: ExternalModuleDependencies, | ||
requiredScripts: RequiredScripts, | ||
externalScriptDependencies: ExternalScriptDependencies, | ||
releaseNotes: ReleaseNotes, | ||
privateData: PrivateData, | ||
description: Description, | ||
endOfFileContents: String.Empty); | ||
|
||
if (!scriptInfo.TryCreateScriptFileInfoString( | ||
pSScriptFileString: out string psScriptFileContents, | ||
errors: out ErrorRecord[] errors)) | ||
{ | ||
foreach (ErrorRecord err in errors) | ||
{ | ||
WriteError(err); | ||
} | ||
|
||
return; | ||
} | ||
|
||
File.WriteAllText(resolvedFilePath, psScriptFileContents); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.