Skip to content

Commit

Permalink
Re-format everything
Browse files Browse the repository at this point in the history
To ensure consistent style throughout the project, I've done the
following to all *.ps1 files and module files:

Format document in VS Code with the following codeFormatting settings:

// Places open brace on the same line as its associated statement.

"powershell.codeFormatting.openBraceOnSameLine": true,

  // Adds a
newline (line break) after an open brace.

"powershell.codeFormatting.newLineAfterOpenBrace": true,

  // Adds a
newline (line break) after a closing brace.

"powershell.codeFormatting.newLineAfterCloseBrace": true,

  // Adds a
space between a keyword and its associated scriptblock expression.

"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,

  // Adds
a space between a keyword (if, elseif, while, switch, etc) and its
associated conditional expression.

"powershell.codeFormatting.whitespaceBeforeOpenParen": true,

  // Adds
spaces before and after an operator ('=', '+', '-', etc.).

"powershell.codeFormatting.whitespaceAroundOperator": true,

  // Adds a
space after a separator (',' and ';').

"powershell.codeFormatting.whitespaceAfterSeparator": true,

  // Does
not reformat one-line code blocks, such as "if (...) {...} else {...}".

"powershell.codeFormatting.ignoreOneLineBlock": true,

  // Align
assignment statements in a hashtable or a DSC Configuration.

"powershell.codeFormatting.alignPropertyValuePairs": true,

Remove trailing tabs
Replace leading tabs with 4 spaces

String literals and here-strings intentionally left completely
unchanged.
  • Loading branch information
IISResetMe committed Jan 2, 2018
1 parent 6fbc5fd commit 9d3aece
Show file tree
Hide file tree
Showing 472 changed files with 64,405 additions and 64,186 deletions.
184 changes: 92 additions & 92 deletions bin/library.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,99 +36,99 @@ Mostly for developers working on the library.

#region Test whether the module had already been imported
if (([System.Management.Automation.PSTypeName]'Sqlcollaborative.Dbatools.Configuration.Config').Type) {
# No need to load the library again, if the module was once already imported.
Write-Verbose -Message "Library already loaded, will not load again"
$ImportLibrary = $false
# No need to load the library again, if the module was once already imported.
Write-Verbose -Message "Library already loaded, will not load again"
$ImportLibrary = $false
}
else {
Write-Verbose -Message "Library not present already, will import"
$ImportLibrary = $true
Write-Verbose -Message "Library not present already, will import"
$ImportLibrary = $true
}
#endregion Test whether the module had already been imported

if ($ImportLibrary) {
#region Add Code
try {
$libraryBase = $ExecutionContext.SessionState.Module.ModuleBase + "\bin"
# In strict security mode, only load from the already pre-compiled binary within the module
if ($script:strictSecurityMode) {
if (Test-Path -Path "$libraryBase\dbatools.dll") {
Add-Type -Path "$libraryBase\dbatools.dll" -ErrorAction Stop
}
else {
throw "Library not found, terminating!"
}
}
# Else we prioritize user convenience
else {
$hasProject = Test-Path -Path "$libraryBase\projects\dbatools\dbatools.sln"
$hasCompiledDll = Test-Path -Path "$libraryBase\dbatools.dll"
if ((-not $script:alwaysBuildLibrary) -and $hasCompiledDll -and ([System.Diagnostics.FileVersionInfo]::GetVersionInfo("$libraryBase\dbatools.dll").FileVersion -eq $currentLibraryVersion)) {
$start = Get-Date
try {
Write-Verbose -Message "Found library, trying to copy & import"
Copy-Item -Path "$libraryBase\dbatools.dll" -Destination $script:DllRoot -Force -ErrorAction Stop
Add-Type -Path "$script:DllRoot\dbatools.dll" -ErrorAction Stop
}
catch {
Write-Verbose -Message "Failed to copy&import, attempting to import straight from the module directory"
Add-Type -Path "$libraryBase\dbatools.dll" -ErrorAction Stop
}
Write-Verbose -Message "Total duration: $((Get-Date) - $start)"
}
elseif ($hasProject) {
$start = Get-Date
$system = [Appdomain]::CurrentDomain.GetAssemblies() | Where-Object FullName -like "System, *"
$msbuild = (Resolve-Path "$(Split-Path $system.Location)\..\..\..\..\Framework$(if ([intptr]::Size -eq 8) { "64" })\$($system.ImageRuntimeVersion)\msbuild.exe").Path
switch ($PSVersionTable.PSVersion.Major) {
3 { $msbuildConfiguration = "/p:Configuration=ps3" }
4 { $msbuildConfiguration = "/p:Configuration=ps4" }
default { $msbuildConfiguration = "/p:Configuration=Release" }
}
$msbuildOptions = ""
if ($env:APPVEYOR -eq 'True') {
# This doesn't seem to work. Keep it here for now
$msbuildOptions = '/logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"'
$msbuildConfiguration = '/p:Configuration=Debug'
if (-not (Test-Path "C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll")) {
throw "msbuild logger not found, cannot compile library! Check your .NET installation health, then try again. Path checked: $msbuild"
}
}
if (-not (Test-Path $msbuild)) {
throw "msbuild not found, cannot compile library! Check your .NET installation health, then try again. Path checked: $msbuild"
}
Write-Verbose -Message "Building the library"
& $msbuild "$libraryBase\projects\dbatools\dbatools.sln" $msbuildConfiguration $msbuildOptions
try {
Write-Verbose -Message "Found library, trying to copy & import"
if ($script:alwaysBuildLibrary) { Move-Item -Path "$libraryBase\dbatools.dll" -Destination $script:DllRoot -Force -ErrorAction Stop }
else { Copy-Item -Path "$libraryBase\dbatools.dll" -Destination $script:DllRoot -Force -ErrorAction Stop }
Add-Type -Path "$script:DllRoot\dbatools.dll" -ErrorAction Stop
}
catch {
Write-Verbose -Message "Failed to copy&import, attempting to import straight from the module directory"
Add-Type -Path "$libraryBase\dbatools.dll" -ErrorAction Stop
}
Write-Verbose -Message "Total duration: $((Get-Date) - $start)"
}
else {
throw "No valid dbatools library found! Check your module integrity"
}
}
#region PowerShell TypeData
Update-TypeData -TypeName "Sqlcollaborative.Dbatools.dbaSystem.DbatoolsException" -SerializationDepth 2 -ErrorAction Ignore
Update-TypeData -TypeName "Sqlcollaborative.Dbatools.dbaSystem.DbatoolsExceptionRecord" -SerializationDepth 2 -ErrorAction Ignore
#endregion PowerShell TypeData
}
catch {
#region Warning
Write-Warning @'
#region Add Code
try {
$libraryBase = $ExecutionContext.SessionState.Module.ModuleBase + "\bin"
# In strict security mode, only load from the already pre-compiled binary within the module
if ($script:strictSecurityMode) {
if (Test-Path -Path "$libraryBase\dbatools.dll") {
Add-Type -Path "$libraryBase\dbatools.dll" -ErrorAction Stop
}
else {
throw "Library not found, terminating!"
}
}
# Else we prioritize user convenience
else {
$hasProject = Test-Path -Path "$libraryBase\projects\dbatools\dbatools.sln"
$hasCompiledDll = Test-Path -Path "$libraryBase\dbatools.dll"
if ((-not $script:alwaysBuildLibrary) -and $hasCompiledDll -and ([System.Diagnostics.FileVersionInfo]::GetVersionInfo("$libraryBase\dbatools.dll").FileVersion -eq $currentLibraryVersion)) {
$start = Get-Date
try {
Write-Verbose -Message "Found library, trying to copy & import"
Copy-Item -Path "$libraryBase\dbatools.dll" -Destination $script:DllRoot -Force -ErrorAction Stop
Add-Type -Path "$script:DllRoot\dbatools.dll" -ErrorAction Stop
}
catch {
Write-Verbose -Message "Failed to copy&import, attempting to import straight from the module directory"
Add-Type -Path "$libraryBase\dbatools.dll" -ErrorAction Stop
}
Write-Verbose -Message "Total duration: $((Get-Date) - $start)"
}
elseif ($hasProject) {
$start = Get-Date
$system = [Appdomain]::CurrentDomain.GetAssemblies() | Where-Object FullName -like "System, *"
$msbuild = (Resolve-Path "$(Split-Path $system.Location)\..\..\..\..\Framework$(if ([intptr]::Size -eq 8) { "64" })\$($system.ImageRuntimeVersion)\msbuild.exe").Path
switch ($PSVersionTable.PSVersion.Major) {
3 { $msbuildConfiguration = "/p:Configuration=ps3" }
4 { $msbuildConfiguration = "/p:Configuration=ps4" }
default { $msbuildConfiguration = "/p:Configuration=Release" }
}
$msbuildOptions = ""
if ($env:APPVEYOR -eq 'True') {
# This doesn't seem to work. Keep it here for now
$msbuildOptions = '/logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"'
$msbuildConfiguration = '/p:Configuration=Debug'
if (-not (Test-Path "C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll")) {
throw "msbuild logger not found, cannot compile library! Check your .NET installation health, then try again. Path checked: $msbuild"
}
}
if (-not (Test-Path $msbuild)) {
throw "msbuild not found, cannot compile library! Check your .NET installation health, then try again. Path checked: $msbuild"
}
Write-Verbose -Message "Building the library"
& $msbuild "$libraryBase\projects\dbatools\dbatools.sln" $msbuildConfiguration $msbuildOptions
try {
Write-Verbose -Message "Found library, trying to copy & import"
if ($script:alwaysBuildLibrary) { Move-Item -Path "$libraryBase\dbatools.dll" -Destination $script:DllRoot -Force -ErrorAction Stop }
else { Copy-Item -Path "$libraryBase\dbatools.dll" -Destination $script:DllRoot -Force -ErrorAction Stop }
Add-Type -Path "$script:DllRoot\dbatools.dll" -ErrorAction Stop
}
catch {
Write-Verbose -Message "Failed to copy&import, attempting to import straight from the module directory"
Add-Type -Path "$libraryBase\dbatools.dll" -ErrorAction Stop
}
Write-Verbose -Message "Total duration: $((Get-Date) - $start)"
}
else {
throw "No valid dbatools library found! Check your module integrity"
}
}
#region PowerShell TypeData
Update-TypeData -TypeName "Sqlcollaborative.Dbatools.dbaSystem.DbatoolsException" -SerializationDepth 2 -ErrorAction Ignore
Update-TypeData -TypeName "Sqlcollaborative.Dbatools.dbaSystem.DbatoolsExceptionRecord" -SerializationDepth 2 -ErrorAction Ignore
#endregion PowerShell TypeData
}
catch {
#region Warning
Write-Warning @'
Dear User,
in the name of the dbatools team I apologize for the inconvenience.
Expand All @@ -155,15 +155,15 @@ Friedrich Weinmann
aka "The guy who made most of The Library that Failed to import"
'@
throw
#endregion Warning
}
#endregion Add Code
throw
#endregion Warning
}
#endregion Add Code
}

#region Version Warning
if ($currentLibraryVersion -ne ([version](([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object ManifestModule -like "dbatools.dll").CustomAttributes | Where-Object AttributeType -like "System.Reflection.AssemblyFileVersionAttribute").ConstructorArguments.Value)) {
Write-Warning @"
Write-Warning @"
A version missmatch between the dbatools library loaded and the one expected by
this module. This usually happens when you update the dbatools module and use
Remove-Module / Import-Module in order to load the latest version without
Expand Down
31 changes: 15 additions & 16 deletions bin/typealiases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ $TAType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelera

# Define our type aliases
$TypeAliasTable = @{
DbaInstance = "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter"
DbaCmConnectionParameter = "Sqlcollaborative.Dbatools.Parameter.DbaCmConnectionParameter"
DbaInstanceParameter = "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter"
dbargx = "Sqlcollaborative.Dbatools.Utility.RegexHelper"
dbatime = "Sqlcollaborative.Dbatools.Utility.DbaTime"
dbadatetime = "Sqlcollaborative.Dbatools.Utility.DbaDateTime"
dbadate = "Sqlcollaborative.Dbatools.Utility.DbaDate"
dbatimespan = "Sqlcollaborative.Dbatools.Utility.DbaTimeSpan"
prettytimespan = "Sqlcollaborative.Dbatools.Utility.DbaTimeSpanPretty"
dbasize = "Sqlcollaborative.Dbatools.Utility.Size"
dbavalidate = "Sqlcollaborative.Dbatools.Utility.Validation"
DbaMode = "Sqlcollaborative.Dbatools.General.ExecutionMode"
DbaCredential = "Sqlcollaborative.Dbatools.Parameter.DbaCredentialparameter"
DbaCredentialParameter = "Sqlcollaborative.Dbatools.Parameter.DbaCredentialparameter"
DbaInstance = "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter"
DbaCmConnectionParameter = "Sqlcollaborative.Dbatools.Parameter.DbaCmConnectionParameter"
DbaInstanceParameter = "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter"
dbargx = "Sqlcollaborative.Dbatools.Utility.RegexHelper"
dbatime = "Sqlcollaborative.Dbatools.Utility.DbaTime"
dbadatetime = "Sqlcollaborative.Dbatools.Utility.DbaDateTime"
dbadate = "Sqlcollaborative.Dbatools.Utility.DbaDate"
dbatimespan = "Sqlcollaborative.Dbatools.Utility.DbaTimeSpan"
prettytimespan = "Sqlcollaborative.Dbatools.Utility.DbaTimeSpanPretty"
dbasize = "Sqlcollaborative.Dbatools.Utility.Size"
dbavalidate = "Sqlcollaborative.Dbatools.Utility.Validation"
DbaMode = "Sqlcollaborative.Dbatools.General.ExecutionMode"
DbaCredential = "Sqlcollaborative.Dbatools.Parameter.DbaCredentialparameter"
DbaCredentialParameter = "Sqlcollaborative.Dbatools.Parameter.DbaCredentialparameter"
}

# Add all type aliases
foreach($TypeAlias in $TypeAliasTable.Keys)
{
foreach ($TypeAlias in $TypeAliasTable.Keys) {
try {
$TAType::Add($TypeAlias, $TypeAliasTable[$TypeAlias])
}
Expand Down
Loading

0 comments on commit 9d3aece

Please sign in to comment.