Skip to content

Commit

Permalink
Updated imports in dbm1
Browse files Browse the repository at this point in the history
Fixed library import
Changed subordinate call in configurations, because with the new import
$PSScriptRoot is no longer available
Updated Get-GenericArgumentCompleter, in order to support the redesigned
optional files component.
  • Loading branch information
FriedrichWeinmann committed Feb 15, 2017
1 parent ac78fd3 commit 4aebc51
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
31 changes: 16 additions & 15 deletions dbatools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ foreach ($assembly in $assemblies)
# This technique helps a little bit
# https://becomelotr.wordpress.com/2017/02/13/expensive-dot-sourcing/

# Load our own custom library
# Should always come before function imports
. ([scriptblock]::Create([io.file]::ReadAllText("$PSScriptRoot\bin\library.ps1")))

# All internal functions privately available within the toolset
foreach ($function in (Get-ChildItem "$PSScriptRoot\internal\*.ps1"))
{
Expand All @@ -66,24 +70,15 @@ foreach ($function in (Get-ChildItem "$PSScriptRoot\functions\*.ps1"))
. ([scriptblock]::Create([io.file]::ReadAllText($function)))
}

#region Optional / Conditional components
# Only import our own TEPP implementation if the official one isn't available
if (-not (Get-Command -Name New-CompletionResult -ErrorAction Ignore))
{
. ([scriptblock]::Create([io.file]::ReadAllText("$PSScriptRoot\optional\TabExpansionPlusPlus.ps1")))
. ([scriptblock]::Create([io.file]::ReadAllText("$PSScriptRoot\optional\Get-GenericArgumentCompleter.ps1")))
}


# Only import Invoke-SqlCmd2, if the original isn't already available
if (-not (Get-Command -Name Invoke-SqlCmd2 -ErrorAction Ignore -ListImported))
# Run all optional code
# Note: Each optional file must include a conditional governing whether it's run at all.
# Validations were moved into the other files, in order to prevent having to update dbatools.psm1 every time
foreach ($function in (Get-ChildItem "$PSScriptRoot\optional\*.ps1"))
{
. ([scriptblock]::Create([io.file]::ReadAllText("$PSScriptRoot\optional\Invoke-SqlCmd2.ps1")))
. ([scriptblock]::Create([io.file]::ReadAllText($function)))
}
#endregion Optional / Conditional components


# Finally register autocompletion
#region Finally register autocompletion
# Test whether we have Tab Expansion Plus available (used in dynamicparams scripts ran below)
if (Get-Command TabExpansionPlusPlus\Register-ArgumentCompleter -ErrorAction Ignore)
{
Expand All @@ -98,6 +93,12 @@ foreach ($function in (Get-ChildItem "$PSScriptRoot\internal\dynamicparams\*.ps1
{
. ([scriptblock]::Create([io.file]::ReadAllText($function)))
}
#endregion Finally register autocompletion

# Load configuration system
# Should always go last
. ([scriptblock]::Create([io.file]::ReadAllText("$PSScriptRoot\internal\configurations\configuration.ps1")))


# Not supporting the provider path at this time
# if (((Resolve-Path .\).Path).StartsWith("SQLSERVER:\")) { throw "Please change to another drive and reload the module." }
Expand Down
4 changes: 3 additions & 1 deletion internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ if ($var = Get-Variable "dbatools_config" -Scope Global -ErrorAction Ignore)
}
#endregion Implement user profile

$configpath = $ExecutionContext.SessionState.Module.ModuleBase + "\internal\configurations"

# Import other configuration files
foreach ($file in (Get-ChildItem -Path $PSScriptRoot -Exclude "configuration.ps1"))
foreach ($file in (Get-ChildItem -Path $configpath -Exclude "configuration.ps1"))
{
. $file.FullName
}
5 changes: 4 additions & 1 deletion optional/Get-GenericArgumentCompleter.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Function Get-GenericArgumentCompleter
if (-not (Get-Command -Name Register-ArgumentCompleter -ErrorAction Ignore))
{
Function Get-GenericArgumentCompleter
{
param (
[string]$name,
Expand All @@ -23,3 +25,4 @@
}
}
}
}

0 comments on commit 4aebc51

Please sign in to comment.