Skip to content

Commit

Permalink
Release of v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lipkau committed Jan 22, 2018
2 parents 8b70bb9 + 357ec5a commit 5170623
Show file tree
Hide file tree
Showing 21 changed files with 601 additions and 588 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Ignore configuration files
*.ini
*.conf
*.config
config.xml

# Ignore all files beginning with a dot (.)
.*
# except for git files
!.gitattributes
!.gitignore
!.github/
!.vscode/

# Ignore Release directory generated by local builds
Release/
Tools/
# ConfluencePS/en-US/
TestResult.xml

#######
Expand Down
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "0.2.0",
"configurations": [{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Pester Tests",
"script": ".\\.env.ps1",
"script": "Invoke-Pester",
"args": [],
"cwd": "${workspaceRoot}"
},
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch (current file)",
"script": "${file}",
"args": [],
"cwd": "${file}"
},
{
"type": "PowerShell",
"request": "attach",
"name": "PowerShell Attach to Host Process",
"processId": "${command.PickPSHostProcess}",
"runspaceId": 1
},
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Interactive Session",
"cwd": "${workspaceRoot}"
}
]
}
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.encoding": "utf8",
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.tabSize": 4,
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1",
"powershell.codeFormatting.openBraceOnSameLine": true,
"powershell.codeFormatting.newLineAfterOpenBrace": true,
"powershell.codeFormatting.newLineAfterCloseBrace": true,
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
"powershell.codeFormatting.whitespaceAroundOperator": true,
"powershell.codeFormatting.whitespaceAfterSeparator": true,
"[markdown]": {
"editor.wordwrap": "on",
"editor.renderWhitespace": "all",
"editor.acceptSuggestionOnEnter": false,
"editor.rulers": [80],
"editor.trimAutoWhitespace": false
},
}
97 changes: 97 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// A task runner that invokes Pester to run all Pester tests under the
// current workspace folder.
// NOTE: This Test task runner requires an updated version of Pester (>=4.0.3)
// in order for the problemMatcher to find failed test information (message, line, file).
// If you don't have that version, you can update Pester from the PowerShell Gallery
// with this command:
//
// PS C:\> Update-Module Pester
//
// If that gives an error like:
// "Module 'Pester' was not installed by using Install-Module, so it cannot be updated."
// then execute:
//
// PS C:\> Install-Module Pester -Scope CurrentUser -Force
//
// NOTE: The Clean, Build and Publish tasks require PSake. PSake can be installed
// from the PowerShell Gallery with this command:
//
// PS C:\> Install-Module PSake -Scope CurrentUser -Force
//
// Available variables which can be used inside of strings:
// ${workspaceFolder} the path of the workspace folder that contains the tasks.json file
// ${workspaceFolderBasename} the name of the workspace folder that contains the tasks.json file without any slashes (/)
// ${file} the current opened file
// ${relativeFile} the current opened file relative to the workspace folder containing the file
// ${fileBasename} the current opened file's basename
// ${fileBasenameNoExtension} the current opened file's basename without the extension
// ${fileDirname} the current opened file's dirname
// ${fileExtname} the current opened file's extension
// ${cwd} the task runner's current working directory on startup
// ${lineNumber} the current selected line number in the active file
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-Command"
]
}
}
},
"linux": {
"options": {
"shell": {
"executable": "/usr/bin/pwsh",
"args": [
"-NoProfile",
"-Command"
]
}
}
},
"osx": {
"options": {
"shell": {
"executable": "/usr/local/bin/pwsh",
"args": [
"-NoProfile",
"-Command"
]
}
}
},
"tasks": [
{
"label": "Clean",
"type": "shell",
"command": "Invoke-Build -task Clean"
},
{
"label": "Build",
"type": "shell",
"command": "Invoke-Build -task Build",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Test",
"type": "shell",
"command": "Invoke-Pester -PesterOption @{IncludeVSCodeMarker=$true}",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [
"$pester"
]
}
]
}
116 changes: 57 additions & 59 deletions PSIni/Functions/Add-IniComment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ Function Add-IniComment {
.Outputs
System.Collections.Specialized.OrderedDictionary
.Parameter FilePath
Specifies the path to the input file.
.Parameter InputObject
Specifies the Hashtable to be modified. Enter a variable that contains the objects or type a command or expression that gets the objects.
.Parameter CommentChar
Specify what character should be used to comment out entries.
Note: This parameter is a char array to maintain compatibility with the other functions.
However, only the first character is used to comment out entries.
Default: ";"
.Parameter Keys
String array of one or more keys to limit the changes to, separated by a comma. Optional.
.Parameter Sections
String array of one or more sections to limit the changes to, separated by a comma.
Surrounding section names with square brackets is not necessary but is supported.
Ini keys that do not have a defined section can be modified by specifying '_' (underscore) for the section.
.Example
$ini = Add-IniComment -FilePath "C:\myinifile.ini" -Sections 'Printers' -Keys 'Headers','Footers'
-----------
Expand Down Expand Up @@ -83,91 +63,109 @@ Function Add-IniComment {
)]
Param
(
[Parameter(ParameterSetName="File",Mandatory=$True,Position=0)]
# Specifies the path to the input file.
[Parameter( Position = 0, Mandatory, ParameterSetName = "File" )]
[ValidateNotNullOrEmpty()]
[String]$FilePath,
[String]
$FilePath,

[Parameter(ParameterSetName="Object",Mandatory=$True,ValueFromPipeline=$True)]
# Specifies the Hashtable to be modified. Enter a variable that contains the objects or type a command or expression that gets the objects.
[Parameter( Mandatory, ValueFromPipeline, ParameterSetName = "Object" )]
[ValidateNotNullOrEmpty()]
[System.Collections.IDictionary]$InputObject,
[System.Collections.IDictionary]
$InputObject,

[Parameter(Mandatory = $True)]
# String array of one or more keys to limit the changes to, separated by a comma. Optional.
[Parameter( Mandatory )]
[ValidateNotNullOrEmpty()]
[String[]]$Keys,

[char[]]$CommentChar = @(";"),

[String[]]
$Keys,

# Specify what character should be used to comment out entries.
# Note: This parameter is a char array to maintain compatibility with the other functions.
# However, only the first character is used to comment out entries.
# Default: ";"
[char[]]
$CommentChar = @(";"),

# String array of one or more sections to limit the changes to, separated by a comma.
# Surrounding section names with square brackets is not necessary but is supported.
# Ini keys that do not have a defined section can be modified by specifying '_' (underscore) for the section.
[ValidateNotNullOrEmpty()]
[String[]]$Sections
[String[]]
$Sections
)

Begin
{
Begin {
Write-Debug "PsBoundParameters:"
$PSBoundParameters.GetEnumerator() | ForEach-Object { Write-Debug $_ }
if ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }
if ($PSBoundParameters['Debug']) {
$DebugPreference = 'Continue'
}
Write-Debug "DebugPreference: $DebugPreference"

Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"
}
# Comment out the specified keys in the list, either in the specified section or in all sections.
Process
{

Process {
# Get the ini from either a file or object passed in.
if ($PSCmdlet.ParameterSetName -eq 'File') { $content = Get-IniContent $FilePath }
if ($PSCmdlet.ParameterSetName -eq 'Object') { $content = $InputObject }

# Specific section(s) were requested.
if ($Sections)
{
foreach ($section in $Sections)
{
if ($Sections) {
foreach ($section in $Sections) {
# Get rid of whitespace and section brackets.
$section = $section.Trim() -replace '[][]',''
$section = $section.Trim() -replace '[][]', ''

Write-Debug ("Processing '{0}' section." -f $section)

foreach ($key in $Keys)
{
foreach ($key in $Keys) {
Write-Debug ("Processing '{0}' key." -f $key)

$key = $key.Trim()

if ($content[$section]) { $currentValue = $content[$section][$key] }
else
{
if ($content[$section]) {
$currentValue = $content[$section][$key]
}
else {
Write-Verbose ("$($MyInvocation.MyCommand.Name):: '{0}' section does not exist." -f $section)
# Break out of the loop after this, because we don't want to check further keys for this non-existent section.
break
}

if ($currentValue) { Convert-IniEntryToComment $content $key $section $CommentChar }
else { Write-Verbose ("$($MyInvocation.MyCommand.Name):: '[{0}][{1}]' does not exist." -f $section, $key) }
if ($currentValue) {
Convert-IniEntryToComment $content $key $section $CommentChar
}
else {
Write-Verbose ("$($MyInvocation.MyCommand.Name):: '[{0}][{1}]' does not exist." -f $section, $key)
}
}
}
}
else # No section supplied, go through the entire ini since changes apply to all sections.
{
foreach ($item in $content.GetEnumerator())
{
else {
# No section supplied, go through the entire ini since changes apply to all sections.
foreach ($item in $content.GetEnumerator()) {
$section = $item.key
Write-Debug ("Processing '{0}' section." -f $section)

foreach ($key in $Keys)
{
foreach ($key in $Keys) {
$key = $key.Trim()
Write-Debug ("Processing '{0}' key." -f $key)

if ($content[$section][$key]) { Convert-IniEntryToComment $content $key $section $CommentChar }
else { Write-Verbose ("$($MyInvocation.MyCommand.Name):: '[{0}][{1}]' does not exist." -f $section, $key) }
if ($content[$section][$key]) {
Convert-IniEntryToComment $content $key $section $CommentChar
}
else {
Write-Verbose ("$($MyInvocation.MyCommand.Name):: '[{0}][{1}]' does not exist." -f $section, $key)
}
}
}
}

return $content
Write-Output $content
}
End
{
End {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"
}
}
Expand Down
Loading

0 comments on commit 5170623

Please sign in to comment.