From cfa334e0b03550fe60aaa2c4da70cd22fad041d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Sat, 7 Mar 2026 08:31:58 +0100 Subject: [PATCH 1/5] fix(Test-MyDebug): correct trace condition logic --- include/MyWrite.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 5226eab..1b04866 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -190,7 +190,7 @@ function Test-MyDebug { $flag = $flag.ToLower() $section = $section.ToLower() - $trace = ($flag -like '*all*') -or ( $section -like "*$flag*") + $trace = ($flag -like '*all*') -or ( $flag -like "*$section*") return $trace } From fc9cbff2962006c82f3f4dfb8f43b835610cab6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 09:08:53 +0100 Subject: [PATCH 2/5] feat(MyHandle): add Get-MyHandle function to retrieve GitHub username --- include/MyHandle.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 include/MyHandle.ps1 diff --git a/include/MyHandle.ps1 b/include/MyHandle.ps1 new file mode 100644 index 0000000..88c7269 --- /dev/null +++ b/include/MyHandle.ps1 @@ -0,0 +1,10 @@ +Set-MyInvokeCommandAlias -Alias GetGhHandle -Command 'gh api user --jq ".login"' + +function Get-MyHandle{ + [CmdletBinding()] + param() + + $user = Invoke-MyCommand -Command GetGhHandle + + return $user +} \ No newline at end of file From 0b079323a01ca606815bbed362aeffadab423dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 09:09:04 +0100 Subject: [PATCH 3/5] refactor(logging): enhance debug and verbose logging functions --- include/MyWrite.ps1 | 170 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 133 insertions(+), 37 deletions(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 1b04866..362b909 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -53,15 +53,25 @@ function Write-MyHost { [Parameter()][string]$ForegroundColor = $OUTPUT_COLOR, [Parameter()][switch]$NoNewLine ) + + Write-MyDebug -Section "MyHost" -Message $Message + # Write-Host $message -ForegroundColor $OUTPUT_COLOR Write-ToConsole $message -Color $ForegroundColor -NoNewLine:$NoNewLine } +function Clear-MyHost { + [CmdletBinding()] + param() + + Clear-Host +} + function Write-MyDebug { [CmdletBinding()] [Alias("Write-Debug")] param( - [Parameter(Position = 0)][string]$section, + [Parameter(Position = 0)][string]$section = "none", [Parameter(Position = 1, ValueFromPipeline)][string]$Message, [Parameter(Position = 2)][object]$Object ) @@ -77,7 +87,7 @@ function Write-MyDebug { $timestamp = Get-Date -Format 'HH:mm:ss.fff' # Write on host - $logMessage ="[$timestamp][D][$section] $message" + $logMessage ="[$timestamp][$MODULE_NAME][D][$section] $message" $logMessage | Write-ToConsole -Color $DEBUG_COLOR $logMessage | Write-MyDebugLogging @@ -92,8 +102,7 @@ function Write-MyDebugLogging { process{ - $moduleDebugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" - $loggingFilePath = [System.Environment]::GetEnvironmentVariable($moduleDebugLoggingVarName) + $loggingFilePath = get-DebugLogFile # Check if logging is enabled if ([string]::IsNullOrWhiteSpace( $loggingFilePath )) { @@ -103,14 +112,13 @@ function Write-MyDebugLogging { # Check if file exists # This should always exist as logging checks for parent path to be enabled # It may happen if since enable to execution the parent folder aka loggingFilePath is deleted. - if(-not (Test-Path -Path $loggingFilePath) ){ + if(-not (Test-Path -Path $loggingFilePath -PathType Leaf) ){ Write-Warning "Debug logging file path not accesible : '$loggingFilePath'" return $false } # Write to log file - $logFilePath = Join-Path -Path $loggingFilePath -ChildPath "$($MODULE_NAME)_debug.log" - Add-Content -Path $logFilePath -Value $LogMessage + Add-Content -Path $loggingFilePath -Value $LogMessage } } @@ -135,8 +143,7 @@ function Test-MyVerbose { [Parameter(Position = 0)][string]$section ) - $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" - $flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + $flag = get-VerboseSections if ([string]::IsNullOrWhiteSpace( $flag )) { return $false @@ -157,8 +164,7 @@ function Enable-ModuleNameVerbose{ $flag = $section } - $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag) + set-VerboseSections $flag } Copy-Item -path Function:Enable-ModuleNameVerbose -Destination Function:"Enable-$($MODULE_NAME)Verbose" Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose" @@ -166,8 +172,7 @@ Export-ModuleMember -Function "Enable-$($MODULE_NAME)Verbose" function Disable-ModuleNameVerbose{ param() - $moduleDebugVarName = $MODULE_NAME + "_VERBOSE" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null) + set-VerboseSections $null } Copy-Item -path Function:Disable-ModuleNameVerbose -Destination Function:"Disable-$($MODULE_NAME)Verbose" Export-ModuleMember -Function "Disable-$($MODULE_NAME)Verbose" @@ -178,65 +183,120 @@ function Test-MyDebug { [Parameter()][switch]$Logging ) - # Get the module debug environment variable - $moduleDebugVarName = $MODULE_NAME + "_DEBUG" - $flag = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + function testSection($section,$flags){ + if($flags.Count -eq 0){ + return $false + } + $flags = $flags.ToLower() + $section = $section.ToLower() - # check if debugging is enabled - if ([string]::IsNullOrWhiteSpace( $flag )) { + return ($flags.Contains("all")) -or ( $flags -eq $section) + } + + + $sectionsString = get-DebugSections + + # No configuration means no debug + if([string]::IsNullOrWhiteSpace( $sectionsString )) { return $false } - $flag = $flag.ToLower() - $section = $section.ToLower() + # Get flags from sectionsString + $flags = getSectionsFromSectionsString $sectionsString + + # Add all if allow is empty. + # This mean stat flagsString only contains filters. + $flags.allow = $flags.allow.Count -eq 0 ? @("all") : $flags.allow + + # Get the module debug environment variable + $isAllow = testSection -Section:$section -Flags:$flags.allow + $isFiltered = testSection -Section:$section -Flags:$flags.filter + + $trace = $isAllow -and -not $isFiltered - $trace = ($flag -like '*all*') -or ( $flag -like "*$section*") return $trace } function Enable-ModuleNameDebug{ param( - [Parameter(Position = 0)][string]$section, + [Parameter(Position = 0)][string[]]$Sections, + [Parameter()][string[]]$AddSections, [Parameter()][string]$LoggingFilePath ) # Check if logging file path is provided if( -Not ( [string]::IsNullOrWhiteSpace( $LoggingFilePath )) ) { - if(Test-Path -Path $LoggingFilePath){ - $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" - [System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $LoggingFilePath) + if(Test-Path -Path $LoggingFilePath -PathType Leaf){ + set-LogFile $LoggingFilePath } else { Write-Error "Logging file path '$LoggingFilePath' does not exist. Debug logging will not be enabled." return } } - # Check section value - if( [string]::IsNullOrWhiteSpace( $section )) { - $flag = "all" - } else { - $flag = $section + $sectionsString = $sections -join " " + $addedFlagsString = $AddSections -join " " + + # if no section get value from env and is still mepty set to all + if([string]::IsNullOrWhiteSpace( $sectionsString )) { + $sectionsString = get-DebugSections + if( [string]::IsNullOrWhiteSpace( $sectionsString )) { + $sectionsString = "all" + } + } + + # Add added to sectionsString if provided + if(-Not [string]::IsNullOrWhiteSpace( $addedFlagsString )) { + $sectionsString += " " + $addedFlagsString } - $moduleDebugVarName = $MODULE_NAME + "_DEBUG" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $flag) + set-DebugSections $sectionsString } Copy-Item -path Function:Enable-ModuleNameDebug -Destination Function:"Enable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Enable-$($MODULE_NAME)Debug" +function getSectionsFromSectionsString($sectionsString){ + $sections = @{ + allow = $null + filter = $null + } + + if([string]::IsNullOrWhiteSpace($sectionsString) ){ + $sections.allow = @("all") + return $sections + } + + $list = $sectionsString.Split(" ", [StringSplitOptions]::RemoveEmptyEntries) + + $split = @($list).Where({ $_ -like '-*' }, 'Split') + + $sections.filter = $split[0] | ForEach-Object { $_ -replace '^-', '' } # -> API, Auth + $sections.allow = $split[1] # -> Sync, Cache + + return $sections +} + function Disable-ModuleNameDebug { param() - $moduleDebugVarName = $MODULE_NAME + "_DEBUG" - [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $null) - - $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" - [System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $null) + set-VerboseSections $null } Copy-Item -path Function:Disable-ModuleNameDebug -Destination Function:"Disable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug" +function Get-ModuleNameDebug { + [cmdletbinding()] + param() + + return @{ + Sections = get-DebugSections + LoggingFilePath = get-DebugLogFile + } +} +Copy-Item -path Function:Get-ModuleNameDebug -Destination Function:"Get-$($MODULE_NAME)Debug" +Export-ModuleMember -Function "Get-$($MODULE_NAME)Debug" + function Get-ObjetString { param( [Parameter(ValueFromPipeline, Position = 0)][object]$Object @@ -255,3 +315,39 @@ function Get-ObjetString { return $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue } } + +function get-DebugSections(){ + $moduleDebugVarName = $MODULE_NAME + "_DEBUG" + $sections = [System.Environment]::GetEnvironmentVariable($moduleDebugVarName) + + return $sections +} + +function set-DebugSections($sections){ + $moduleDebugVarName = $MODULE_NAME + "_DEBUG" + [System.Environment]::SetEnvironmentVariable($moduleDebugVarName, $sections) +} + +function get-DebugLogFile(){ + $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" + $logfile = [System.Environment]::GetEnvironmentVariable($moduleDEbugLoggingVarName) + + return $logfile +} + +function set-LogFile($logFilePath){ + $moduleDEbugLoggingVarName = $MODULE_NAME + "_DEBUG_LOGGING_FILEPATH" + [System.Environment]::SetEnvironmentVariable($moduleDEbugLoggingVarName, $logFilePath) +} + +function get-VerboseSections{ + $moduleVerboseVarName = $MODULE_NAME + "_VERBOSE" + $sections = [System.Environment]::GetEnvironmentVariable($moduleVerboseVarName) + + return $sections +} + +function set-VerboseSections($sections){ + $moduleVerboseVarName = $MODULE_NAME + "_VERBOSE" + [System.Environment]::SetEnvironmentVariable($moduleVerboseVarName, $sections) +} \ No newline at end of file From de574946aafa1333af51f8e275527926aab3c652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 09:22:12 +0100 Subject: [PATCH 4/5] refactor(Write-MyDebug): remove redundant parameter declaration --- include/MyWrite.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 668ec6e..93f4e83 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -71,7 +71,6 @@ function Write-MyDebug { [CmdletBinding()] [Alias("Write-Debug")] param( - [Parameter(Position = 0)][string]$section = "none", [Parameter(Position = 0)][string]$section = "none", [Parameter(Position = 1, ValueFromPipeline)][string]$Message, [Parameter(Position = 2)][object]$Object From 344644aecd5ecb47c03061721b12f16d59fdf27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 12 Mar 2026 09:48:30 +0100 Subject: [PATCH 5/5] fix(MyWrite): update debug section handling in Disable-ModuleNameDebug function --- Test/public/MyWrite.test.ps1 | 4 ++-- include/MyWrite.ps1 | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Test/public/MyWrite.test.ps1 b/Test/public/MyWrite.test.ps1 index aafb61d..3f6002c 100644 --- a/Test/public/MyWrite.test.ps1 +++ b/Test/public/MyWrite.test.ps1 @@ -104,7 +104,7 @@ function Test_EnableMyDebug_All{ Invoke-PrivateContext { param($Arguments) - Write-MyDebug -Message $Arguments[0] + Write-MyDebug -Message $Arguments[0] Write-MyDebug -Message $Arguments[1] } -Arguments $text0,$text1 @@ -261,7 +261,7 @@ function Test_EnableMyDebug_All_LoggingFilePath{ function Assert-DbgMsg($Presented,$Section,$Message){ - Assert-IsTrue -Condition ($Presented -match "^\[\d{2}:\d{2}:\d{2}\.\d{3}\]\[D\]\[$Section\] $Message$") + Assert-IsTrue -Condition ($Presented -match "^\[\d{2}:\d{2}:\d{2}\.\d{3}\]\[IncludeHelper\]\[D\]\[$Section\] $Message$") } function Assert-DebugEnv($SectionString,$LoggingFile){ diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 93f4e83..1ecc794 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -280,7 +280,8 @@ function getSectionsFromSectionsString($sectionsString){ function Disable-ModuleNameDebug { param() - set-VerboseSections $null + set-DebugSections $null + set-LogFile $null } Copy-Item -path Function:Disable-ModuleNameDebug -Destination Function:"Disable-$($MODULE_NAME)Debug" Export-ModuleMember -Function "Disable-$($MODULE_NAME)Debug"