Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implementing paths * ran against Invoke-DbatoolsFormatter * put that back, then add after * add commands * fix up params, add test * named it properly
- Loading branch information
1 parent
9a2de55
commit 1f4f89f
Showing
13 changed files
with
199 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,31 @@ | ||
function Get-DbatoolsPath { | ||
<# | ||
.SYNOPSIS | ||
Access a configured path. | ||
.DESCRIPTION | ||
Access a configured path. | ||
Paths can be configured using Set-DbatoolsPath or using the configuration system. | ||
To register a path using the configuration system create a setting key named like this: | ||
"Path.Managed.<PathName>" | ||
For example the following setting points at the temp path: | ||
"Path.Managed.Temp" | ||
.PARAMETER Name | ||
Name of the path to retrieve. | ||
.EXAMPLE | ||
PS C:\> Get-DbatoolsPath -Name 'temp' | ||
Returns the temp path. | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter(Mandatory = $true, Position = 0)] | ||
[string]$Name | ||
) | ||
|
||
process { | ||
Get-DbatoolsConfigValue -FullName "Path.Managed.$Name" | ||
} | ||
} |
This file contains 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 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,48 @@ | ||
function Set-DbatoolsPath { | ||
<# | ||
.SYNOPSIS | ||
Configures or updates a path under a name. | ||
.DESCRIPTION | ||
Configures or updates a path under a name. | ||
The path can be persisted using the "-Register" command. | ||
Paths setup like this can be retrieved using Get-DbatoolsPath. | ||
.PARAMETER Name | ||
Name the path should be stored under. | ||
.PARAMETER Path | ||
The path that should be returned under the name. | ||
.PARAMETER Register | ||
Registering a path in order for it to persist across sessions. | ||
.PARAMETER Scope | ||
The configuration scope it should be registered under. | ||
Defaults to UserDefault. | ||
Configuration scopes are the default locations configurations are being stored at. | ||
.EXAMPLE | ||
PS C:\> Set-DbatoolsPath -Name 'temp' -Path 'C:\temp' | ||
Configures C:\temp as the current temp path. (does not override $env:temp !) | ||
#> | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] | ||
[CmdletBinding(DefaultParameterSetName = 'Default')] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string]$Name, | ||
[Parameter(Mandatory = $true)] | ||
[string]$Path, | ||
[Parameter(ParameterSetName = 'Register', Mandatory = $true)] | ||
[switch]$Register, | ||
[Parameter(ParameterSetName = 'Register')] | ||
[Sqlcollaborative.Dbatools.Configuration.ConfigScope] | ||
$Scope = [Sqlcollaborative.Dbatools.Configuration.ConfigScope]::UserDefault | ||
) | ||
|
||
process { | ||
Set-DbatoolsConfig -FullName "Path.Managed.$Name" -Value $Path | ||
if ($Register) { Register-DbatoolsConfig -FullName "Path.Managed.$Name" -Scope $Scope } | ||
} | ||
} |
This file contains 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 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 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 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,23 @@ | ||
#region Tepp Data return: Path | ||
$ScriptBlock = { | ||
param ( | ||
$commandName, | ||
|
||
$parameterName, | ||
|
||
$wordToComplete, | ||
|
||
$commandAst, | ||
|
||
$fakeBoundParameter | ||
) | ||
|
||
|
||
foreach ($name in (([Sqlcollaborative.Dbatools.Configuration.ConfigurationHost]::Configurations.Values | Where-Object FullName -like "path.managed.*").FullName -replace '^path\.managed\.')) { | ||
if ($name -notlike "$wordToComplete*") { continue } | ||
New-DbaTeppCompletionResult -CompletionText $name -ToolTip $name | ||
} | ||
} | ||
|
||
Register-DbaTeppScriptblock -ScriptBlock $ScriptBlock -Name path | ||
#endregion Tepp Data return: Path |
This file contains 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 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,14 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
. "$PSScriptRoot\constants.ps1" | ||
|
||
Describe "$CommandName Unit Tests" -Tag 'UnitTests' { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } | ||
[object[]]$knownParameters = 'Name' | ||
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters | ||
It "Should only contain our specific parameters" { | ||
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 | ||
} | ||
} | ||
} |
This file contains 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,14 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
. "$PSScriptRoot\constants.ps1" | ||
|
||
Describe "$CommandName Unit Tests" -Tag 'UnitTests' { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } | ||
[object[]]$knownParameters = 'Name', 'Path', 'Register', 'Scope' | ||
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters | ||
It "Should only contain our specific parameters" { | ||
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 | ||
} | ||
} | ||
} |