diff --git a/PSWorkItem.psd1 b/PSWorkItem.psd1 index bd34b6a..6d2e514 100644 --- a/PSWorkItem.psd1 +++ b/PSWorkItem.psd1 @@ -4,7 +4,7 @@ @{ RootModule = 'PSWorkItem.psm1' - ModuleVersion = '1.0.1' + ModuleVersion = '1.1.0' CompatiblePSEditions = 'Core' GUID = '4d3ff215-69ea-4fe6-8ad6-97ffc3a15bfb' Author = 'Jeff Hicks' @@ -22,7 +22,8 @@ FormatsToProcess = @( 'formats\psworkitemdatabase.format.ps1xml', 'formats\psworkItem.format.ps1xml', - '.\formats\psworkitemreport.format.ps1xml' + 'formats\psworkitemreport.format.ps1xml', + 'formats\psworkitemcategory.format.ps1xml' ) FunctionsToExport = @( 'Get-PSWorkItem', @@ -39,7 +40,9 @@ 'Get-PSWorkItemDatabase', 'Get-PSWorkItemData', 'Get-PSWorkItemReport', - 'Update-PSWorkItemDatabase' + 'Update-PSWorkItemDatabase', + 'Update-PSWorkItemPreferences', + 'Set-PSWorkItemCategory' ) CmdletsToExport = @() VariablesToExport = @() diff --git a/PSWorkItem.psm1 b/PSWorkItem.psm1 index 12306a8..298d462 100644 --- a/PSWorkItem.psm1 +++ b/PSWorkItem.psm1 @@ -68,15 +68,7 @@ class PSWorkItemDatabase { #endregion -#make this variable global instead of exporting so that I don't have to use Export-ModuleMember 7/28/2022 JDH -$global:PSWorkItemPath = Join-Path -Path $HOME -ChildPath "PSWorkItem.db" - -<# -Default categories when creating a new database file. -This will be a module-scoped variable -#> - -$PSWorkItemDefaultCategories = "Work", "Personal", "Project", "Other" +#region settings and configuration #a global hashtable used for formatting PSWorkItems $global:PSWorkItemCategory = @{ @@ -84,6 +76,25 @@ $global:PSWorkItemCategory = @{ "Personal" = $PSStyle.Foreground.Green } +#import and use the preference file if found +$PreferencePath = Join-Path -Path $HOME -ChildPath ".psworkitempref.json" +If (Test-Path $PreferencePath) { + $importPref = Get-Content $PreferencePath | ConvertFrom-Json + $global:PSWorkItemPath = $importPref.Path + $importPref.categories.foreach({$PSWorkItemCategory[$_.category]=$_.ansi}) +} +else { + #make this variable global instead of exporting so that I don't have to use Export-ModuleMember 7/28/2022 JDH + $global:PSWorkItemPath = Join-Path -Path $HOME -ChildPath "PSWorkItem.db" +} + +<# +Default categories when creating a new database file. +This will be a module-scoped variable, not exposed to the user +#> + +$PSWorkItemDefaultCategories = "Work", "Personal", "Project", "Other" + Register-ArgumentCompleter -CommandName New-PSWorkItem, Get-PSWorkItem, Set-PSWorkItem, Get-PSWorkItemArchive,Remove-PSWorkItemArchive -ParameterName Category -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) #PowerShell code to populate $WordToComplete @@ -96,3 +107,5 @@ Register-ArgumentCompleter -CommandName New-PSWorkItem, Get-PSWorkItem, Set-PSWo [System.Management.Automation.CompletionResult]::new($_.category, $_.category, 'ParameterValue', $_.description) } } + +#endregion \ No newline at end of file diff --git a/README.md b/README.md index f15c105..2ab9afe 100644 --- a/README.md +++ b/README.md @@ -12,17 +12,15 @@ This module requires PowerShell 7.2 or later and a 64-bit version of PowerShell, Install-Module PSWorkItem [-scope CurrentUser] ``` -Module installation will also install the required [MySQLite](https://github.com/jdhitsolutions/MySQLite) module from the PowerShell Gallery. +:heavy_exclamation_mark: Module installation will also install the required [MySQLite](https://github.com/jdhitsolutions/MySQLite) module from the PowerShell Gallery. ## PSWorkItem Database Change **If you were using a version of this module prior to v1.0.0, this note applies to you.** -Version 1.0.0 of the PSWorkItem module introduced a structural change to the database tables. If you are using a database created in an earlier version, you need to run [Update-PSWorkItemDatabase](docs/Update-PSWorkItemDatabase.md) before adding, changing, or completing work items. It is recommended that you backup your database file before running this command. - -As an alternative, you could export your work items, delete the database file, initialize a new one, and re-import your work items. - -During the upgrade, a new table column called ID is added to the Tasks and Archive database tables. In the Tasks table, the ID column for existing entries will be set to the row id, which should be the task number you are used to seeing. In the archive table, existing entries will get an ID value of 0, since it is impossible to know the original ID number. This database change corrects this problem. Going forward, the PSWorkItem ID will remain the same when you complete it and move the item to the Archive table. +>Version 1.0.0 of the PSWorkItem module introduced a structural change to the database tables. If you are using a database created in an earlier version, you need to run [Update-PSWorkItemDatabase](docs/Update-PSWorkItemDatabase.md) before adding, changing, or completing work items. It is recommended that you back up your database file before running this command. +>As an alternative, you could export your work items, delete the database file, initialize a new one, and re-import your work items. +>During the upgrade, a new table column called ID is added to the Tasks and Archive database tables. In the Tasks table, the ID column for existing entries will be set to the row id, which should be the task number you are used to seeing. In the archive table, existing entries will get an ID value of 0, since it is impossible to know the original ID number. This database change corrects this problem. Going forward, the PSWorkItem ID will remain the same when you complete it and move the item to the Archive table. ## Module Commands and Design @@ -31,15 +29,18 @@ During the upgrade, a new table column called ID is added to the Tasks and Archi - [Get-PSWorkItem](docs/Get-PSWorkItem.md) - [Get-PSWorkItemArchive](docs/Get-PSWorkItemArchive.md) - [Get-PSWorkItemCategory](docs/Get-PSWorkItemCategory.md) +- [Get-PSWorkItemData](docs/Get-PSWorkItemData.md) - [Get-PSWorkItemDatabase](docs/Get-PSWorkItemDatabase.md) - [Get-PSWorkItemReport](docs/Get-PSWorkItemReport.md) - [Initialize-PSWorkItemDatabase](docs/Initialize-PSWorkItemDatabase.md) +- [New-PSWorkItem](docs/New-PSWorkItem.md) - [Remove-PSWorkItem](docs/Remove-PSWorkItem.md) - [Remove-PSWorkItemArchive](docs/Remove-PSWorkItemArchive.md) - [Remove-PSWorkItemCategory](docs/Remove-PSWorkItemCategory.md) -- [New-PSWorkItem](docs/New-PSWorkItem.md) - [Set-PSWorkItem](docs/Set-PSWorkItem.md) +- [Set-PSWorkItemCategory](docs/Set-PSWorkItemCategory.md) - [Update-PSWorkItemDatabase](docs/Update-PSWorkItemDatabase.md) +- [Update-PSWorkItemPreferences](docs/Update-PSWorkItemPreferences.md) The module is based on three tables in a SQLite database file. The primary `Tasks` table is where active items are stored. @@ -229,7 +230,7 @@ You can modify this hashtable as you would any other hashtable. $PSWorkItemCategory.Add("Event","`e[38;5;153m") ``` -The entry will have no effect unless the category is defined in the database. +The entry will have no effect unless the category is defined in the database. The category customizations last for the duration of your PowerShell session or until the module is removed. Add your customizations to your PowerShell profile script. > Note that when you view the hashtable, you won't see any values because they escape sequences are non-printable. @@ -338,8 +339,8 @@ rowid : 19 ## Future Tasks or Commands -+ Password protection options. -+ A WPF and/or TUI form for entering new work items. -+ A WPF and/or TUI form for displaying and managing work items. +- Password protection options. +- A WPF and/or TUI form for entering new work items. +- A WPF and/or TUI form for displaying and managing work items and categories If you have an enhancement suggestion, please submit it as an [Issue](https://github.com/jdhitsolutions/PSWorkItem/issues). diff --git a/changelog.md b/changelog.md index 4bd5f51..86c8526 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,18 @@ ## [Unreleased] +## [1.1.0] - 2023-06-30 + +### Added + +- Added a format file for PSWorkItemCategory to display categories using the designated color scheme. [Issue #10](https://github.com/jdhitsolutions/PSWorkItem/issues/10)] +- Added command `Update-PSWorkItemPreferences` to store user preferences in a JSON file stored in `$HOME`. If the file is found, settings will be imported. +- Added command `Set-PSWorkItemCategory` [Issue 11](https://github.com/jdhitsolutions/PSWorkItem/issues/11) + +### Changed + +- Updated README. + ## [1.0.1] - 2023-03-13 ### Changed @@ -178,7 +190,8 @@ This is a major update with significant changes. If this is your first time inst - Initial files - Created Module outline -[Unreleased]: https://github.com/jdhitsolutions/PSWorkItem/compare/v1.0.1..HEAD +[Unreleased]: https://github.com/jdhitsolutions/PSWorkItem/compare/v1.1.0..HEAD +[1.1.0]: https://github.com/jdhitsolutions/PSWorkItem/compare/v1.0.1..v1.1.0 [1.0.1]: https://github.com/jdhitsolutions/PSWorkItem/compare/v1.0.0..v1.0.1 [1.0.0]: https://github.com/jdhitsolutions/PSWorkItem/compare/v0.9.0..v1.0.0 [0.9.0]: https://github.com/jdhitsolutions/PSWorkItem/compare/v0.8.0..v0.9.0 diff --git a/docs/Add-PSWorkItemCategory.md b/docs/Add-PSWorkItemCategory.md index aaae8c3..148b564 100644 --- a/docs/Add-PSWorkItemCategory.md +++ b/docs/Add-PSWorkItemCategory.md @@ -171,4 +171,6 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell [Get-PSWorkItemCategory](Get-PSWorkItemCategory.md) +[Set-PSWorkItemCategory](Set-PSWorkItemCategory.md) + [Remove-PSWorkItemCategory](Remove-PSWorkItemCategory.md) diff --git a/docs/Remove-PSWorkItemCategory.md b/docs/Remove-PSWorkItemCategory.md index 339200e..7dcdfe1 100644 --- a/docs/Remove-PSWorkItemCategory.md +++ b/docs/Remove-PSWorkItemCategory.md @@ -118,3 +118,5 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell [Add-PSWorkItemCategory](Add-PSWorkItemCategory.md) [Get-PSWorkItemCategory](Get-PSWorkItemCategory.md) + +[Set-PSWorkItemCategory](Set-PSWorkItemCategory.md) diff --git a/docs/Set-PSWorkItemCategory.md b/docs/Set-PSWorkItemCategory.md new file mode 100644 index 0000000..6620384 --- /dev/null +++ b/docs/Set-PSWorkItemCategory.md @@ -0,0 +1,177 @@ +--- +external help file: PSWorkItem-help.xml +Module Name: PSWorkItem +online version: +schema: 2.0.0 +--- + +# Set-PSWorkItemCategory + +## SYNOPSIS + +Update an existing PSWorkItem category + +## SYNTAX + +```yaml +Set-PSWorkItemCategory [-Category] [-Description ] +[-NewName ] [-Path ] [-PassThru] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION + +This command will update an existing PSWorkItem category. The category name is case-sensitive. Use caution when renaming a category that has active tasks using the old category name. + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> Set-PsworkItemCategory -Category work -Description "Uncategorized work activities" -PassThru + +Category Description +-------- ----------- +Work Uncategorized work activities +``` + +## PARAMETERS + +### -Category + +Specify a case-sensitive category name. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: Name + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Confirm + +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Description + +Specify a category comment or description. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NewName + +Specify a new name for the category. +This is case-sensitive. +Be careful renaming a category with active tasks using the old category name. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru + +Write the updated category to the pipeline. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path + +The path to the PSWorkItem SQLite database file. +It should end in .db + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: $PSWorkItemPath +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf + +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### None + +### PSWorkItemCategory + +## NOTES + +## RELATED LINKS + +[Add-PSWorkItemCategory](Add-PSWorkItemCategory.md) + +[Get-PSWorkItemCategory](Get-PSWorkItemCategory.md) + +[Remove-PSWorkItemCategory](Remove-PSWorkItemCategory.md) \ No newline at end of file diff --git a/docs/Update-PSWorkItemPreferences.md b/docs/Update-PSWorkItemPreferences.md new file mode 100644 index 0000000..fc7c42c --- /dev/null +++ b/docs/Update-PSWorkItemPreferences.md @@ -0,0 +1,103 @@ +--- +external help file: PSWorkItem-help.xml +Module Name: PSWorkItem +online version: +schema: 2.0.0 +--- + +# Update-PSWorkItemPreferences + +## SYNOPSIS + +Update or create a preference file + +## SYNTAX + +```yaml +Update-PSWorkItemPreferences [-Passthru] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION + +Use this command to export your preferences for the PSWorkitem module to file. This file will be used when importing the module to set the database path and customized highlighting sequences for $PSWorkItemCategory. The file will be stored in $HOME. + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> Update-PSWorkItemPreferences +``` + +This assumes you've customized category settings or the database path. + +## PARAMETERS + +### -Confirm + +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Passthru + +Show the completed file. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf + +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.IO.FileInfo + +### None + +## NOTES + +## RELATED LINKS + +[Get-PSWorkItemCategory](Get-PSWorkitemCategory.md) diff --git a/en-us/PSWorkItem-help.xml b/en-us/PSWorkItem-help.xml index 10cb2cd..9108366 100644 --- a/en-us/PSWorkItem-help.xml +++ b/en-us/PSWorkItem-help.xml @@ -246,6 +246,10 @@ Blog blog management and content Get-PSWorkItemCategory + + Set-PSWorkItemCategory + + Remove-PSWorkItemCategory @@ -2886,6 +2890,10 @@ What if: Performing the operation "Remove-PSWorkItemArchive" on target "19fea3ee Get-PSWorkItemCategory + + Set-PSWorkItemCategory + + @@ -3224,6 +3232,251 @@ ID Name Description DueDate Category Pct + + + Set-PSWorkItemCategory + Set + PSWorkItemCategory + + Update an existing PSWorkItem category + + + + This command will update an existing PSWorkItem category. The category name is case-sensitive. Use caution when renaming a category that has active tasks using the old category name. + + + + Set-PSWorkItemCategory + + Category + + Specify a case-sensitive category name. + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Description + + Specify a category comment or description. + + String + + String + + + None + + + NewName + + Specify a new name for the category. This is case-sensitive. Be careful renaming a category with active tasks using the old category name. + + String + + String + + + None + + + PassThru + + Write the updated category to the pipeline. + + + SwitchParameter + + + False + + + Path + + The path to the PSWorkItem SQLite database file. It should end in .db + + String + + String + + + $PSWorkItemPath + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Category + + Specify a case-sensitive category name. + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Description + + Specify a category comment or description. + + String + + String + + + None + + + NewName + + Specify a new name for the category. This is case-sensitive. Be careful renaming a category with active tasks using the old category name. + + String + + String + + + None + + + PassThru + + Write the updated category to the pipeline. + + SwitchParameter + + SwitchParameter + + + False + + + Path + + The path to the PSWorkItem SQLite database file. It should end in .db + + String + + String + + + $PSWorkItemPath + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + System.String + + + + + + + + + + None + + + + + + + + PSWorkItemCategory + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Set-PsworkItemCategory -Category work -Description "Uncategorized work activities" -PassThru + +Category Description +-------- ----------- +Work Uncategorized work activities + + + + + + + + Add-PSWorkItemCategory + + + + Get-PSWorkItemCategory + + + + Remove-PSWorkItemCategory + + + + Update-PSWorkItemDatabase @@ -3422,4 +3675,141 @@ ID Name Description DueDate Category Pct + + + Update-PSWorkItemPreferences + Update + PSWorkItemPreferences + + Update or create a preference file + + + + Use this command to export your preferences for the PSWorkitem module to file. This file will be used when importing the module to set the database path and customized highlighting sequences for $PSWorkItemCategory. The file will be stored in $HOME. + + + + Update-PSWorkItemPreferences + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + Passthru + + Show the completed file. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + Passthru + + Show the completed file. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + None + + + + + + + + + + System.IO.FileInfo + + + + + + + + None + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Update-PSWorkItemPreferences + + This assumes you've customized category settings or the database path. + + + + + + Get-PSWorkItemCategory + + + + \ No newline at end of file diff --git a/formats/psworkitemcategory.format.ps1xml b/formats/psworkitemcategory.format.ps1xml new file mode 100644 index 0000000..6f60c03 --- /dev/null +++ b/formats/psworkitemcategory.format.ps1xml @@ -0,0 +1,51 @@ + + + + + + default + + PSWorkItemCategory + + + + + + + 20 + left + + + + + left + + + + + + + + "$($PSWorkItemCategory[$_.Category])$($_.Category)$($PSStyle.Reset)" + + + + + "$($PSWorkItemCategory[$_.Category])$($_.Description)$($PSStyle.Reset)" + + + + + + + + + \ No newline at end of file diff --git a/functions/public/Set-PSWorkItemCategory.ps1 b/functions/public/Set-PSWorkItemCategory.ps1 new file mode 100644 index 0000000..c6647f1 --- /dev/null +++ b/functions/public/Set-PSWorkItemCategory.ps1 @@ -0,0 +1,126 @@ +Function Set-PSWorkItemCategory { + [cmdletbinding(SupportsShouldProcess)] + [OutputType('None', 'PSWorkItemCategory')] + Param( + [Parameter( + Position = 0, + Mandatory, + ValueFromPipeline, + HelpMessage = 'Specify a case-sensitive category name.' + )] + [ValidateNotNullOrEmpty()] + [Alias('Name')] + [string]$Category, + + [Parameter( + HelpMessage = 'Specify a category comment or description.' + )] + [String]$Description, + + [Parameter(HelpMessage = 'Specify a new name for the category. This is case-sensitive. Be careful renaming a category with active tasks using the old category name.')] + [ValidateNotNullOrEmpty()] + [string]$NewName, + + [Parameter(HelpMessage = 'The path to the PSWorkItem SQLite database file. It should end in .db')] + [ValidateNotNullOrEmpty()] + [ValidatePattern('\.db$')] + [ValidateScript({ + if (Test-Path $_) { + Return $True + } + else { + Throw "Failed to validate $_" + Return $False + } + })] + [String]$Path = $PSWorkItemPath, + [switch]$PassThru + ) + + Begin { + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Running under PowerShell version $($PSVersionTable.PSVersion)" + if ((-Not $PSBoundParameters.ContainsKey('Description')) -AND (-Not $PSBoundParameters.ContainsKey('NewName'))) { + Write-Warning 'You must specify either a description or a new name' + Return + } + Write-Debug 'Using bound parameters' + $PSBoundParameters | Out-String | Write-Debug + + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] $($MyInvocation.MyCommand): Opening a connection to $Path" + Try { + $conn = Open-MySQLiteDB -Path $Path -ErrorAction Stop + $conn | Out-String | Write-Debug + + } + Catch { + Throw "$($MyInvocation.MyCommand): Failed to open the database $Path" + } + + #parameters to splat to Invoke-MySQLiteQuery + $splat = @{ + Connection = $conn + KeepAlive = $true + Query = '' + ErrorAction = 'Stop' + } + + $BaseQuery = 'Update categories set ' + } #begin + + Process { + + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Processing $Category" + if ($conn.state -eq 'open') { + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] $($MyInvocation.MyCommand): Validating category $category" + $splat.query = "SELECT * FROM categories WHERE category = '$Category' collate nocase" + Try { + $cat = Invoke-MySQLiteQuery @splat + } + Catch { + Write-Warning "Failed to execute query $($splat.query)" + Close-MySQLiteDB -Connection $conn + Throw $_ + } + if ($cat.category -eq $Category) { + #update the category + # -Query "Update categories set description = 'work stuff',category='newname' Where category='work' collate nocase" + $updates = @{ + Description = $Description + Category = $NewName + } + $updates.GetEnumerator() | Where-Object { $_.value } | ForEach-Object -Begin { $set = @() } -Process { + $set += "$($_.key) = '$($_.value)'" }-End { $BaseQuery += ($set -join ', ') + } + + $BaseQuery += " WHERE category = '$category' collate nocase" + $splat.query = $BaseQuery + if ($PSCmdlet.ShouldProcess($BaseQuery)) { + Invoke-MySQLiteQuery @splat + if ($PassThru) { + if ($NewName) { + Get-PSWorkItemCategory -Category $NewName -Path $Path + } + else { + Get-PSWorkItemCategory -Category $Category -Path $Path + } + } + } + + } #If category found + } #IF connection open + else { + Write-Warning "$($MyInvocation.MyCommand): The database connection is not open" + } + + } #process + + End { + Write-Verbose "[$((Get-Date).TimeOfDay) END ] $($MyInvocation.MyCommand): Closing the connection to $Path" + if ($conn.state -eq 'open') { + Close-MySQLiteDB -Connection $conn + } + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" + } #end + +} #close Set-PSWorkItemCategory \ No newline at end of file diff --git a/functions/public/Update-PSWorkItemPreferences.ps1 b/functions/public/Update-PSWorkItemPreferences.ps1 new file mode 100644 index 0000000..3f38d79 --- /dev/null +++ b/functions/public/Update-PSWorkItemPreferences.ps1 @@ -0,0 +1,44 @@ +Function Update-PSWorkItemPreferences { + [cmdletbinding(SupportsShouldProcess)] + [OutputType('System.IO.FileInfo','None')] + Param( + [Parameter( + HelpMessage = "Update PSWorkitem user preferences settings file." + )] + [ValidateNotNullOrEmpty()] + [Switch]$Passthru + ) + + Begin { + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Running under PowerShell version $($PSVersionTable.PSVersion)" + $FilePath = Join-Path -Path $HOME -ChildPath ".psworkitempref.json" + } #begin + + Process { + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating PSWorkItem user preferences" + $pref = [PSCustomObject]@{ + Path = $PSWorkItemPath + Categories = $PSWorkItemCategory.GetEnumerator() | + ForEach-Object { @{Category = $_.Key;ANSI = $_.value}} + } + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Saving preferences to $FilePath" + Try { + $pref | ConvertTo-Json | Out-File -FilePath $FilePath -ErrorAction Stop + } + Catch { + Throw $_ + } + + if ($PAssthru -AND (Test-Path $FilePath) -AND (-Not $WhatIfPreference)) { + Get-Item -path $FilePath + } + + } #process + + End { + + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" + } #end + +} #close Update-PSWorkItemPreferences \ No newline at end of file diff --git a/tests/RunTest.ps1 b/tests/RunTest.ps1 new file mode 100644 index 0000000..5691474 --- /dev/null +++ b/tests/RunTest.ps1 @@ -0,0 +1,8 @@ +#invoke Pester v5 test +#requires -module Pester + +$config = New-PesterConfiguration + +$config.Output.Verbosity ="detailed" + +Invoke-Pester -Configuration $config \ No newline at end of file diff --git a/tests/psworkitem.tests.ps1 b/tests/psworkitem.tests.ps1 index 8a584a5..d52d24c 100644 --- a/tests/psworkitem.tests.ps1 +++ b/tests/psworkitem.tests.ps1 @@ -25,8 +25,8 @@ Describe 'ModuleStructure' { $mod.ExportedFunctions.keys | Where-Object { $_ -notmatch "^\w+\-\w+"} | Should -HaveCount 0 } - It "Should export 3 format files" { - ( $mod.ExportedFormatFiles).count | Should -Be 3 + It "Should export 4 format files" { + ( $mod.ExportedFormatFiles).count | Should -Be 4 } It "Should export 2 type extension files" { @@ -323,6 +323,25 @@ Describe Set-PSWorkItem { } -Tag function +Describe Update-PSWorkItemPreferences { + It "Should have help documentation" { + (Get-Help Update-PSWorkItemPreferences).Description | Should -Not -BeNullOrEmpty + } + It "Should have a defined output type" { + (Get-Command -CommandType function -name Update-PSWorkItemPreferences).OutputType | Should -Not -BeNullOrEmpty + } + It "Should run without error" { + <# + mock and set mandatory parameters as needed + this test is marked as pending since it + most likely needs to be refined + #> + {Update-PSWorkItemPreferences} | Should -Not -Throw + } -pending + #insert additional command-specific tests + +} -tag function + Describe Update-PSWorkItemDatabase { It "Should have help documentation" { (Get-Help Update-PSWorkItemDatabase).Description | Should -Not -BeNullOrEmpty @@ -342,7 +361,6 @@ Describe Update-PSWorkItemDatabase { } -tag function - Describe Remove-PSWorkItemArchive { It "Should have help documentation" { (Get-Help Remove-PSWorkItemArchive).Description | Should -Not -BeNullOrEmpty @@ -360,4 +378,24 @@ Describe Remove-PSWorkItemArchive { } -pending #insert additional command-specific tests +} -tag function + + +Describe Set-PSWorkItemCategory { + It "Should have help documentation" { + (Get-Help Set-PSWorkItemCategory).Description | Should -Not -BeNullOrEmpty + } + It "Should have a defined output type" { + (Get-Command -CommandType function -name Set-PSWorkItemCategory).OutputType | Should -Not -BeNullOrEmpty + } + It "Should run without error" { + <# + mock and set mandatory parameters as needed + this test is marked as pending since it + most likely needs to be refined + #> + {Set-PSWorkItemCategory} | Should -Not -Throw + } -pending + #insert additional command-specific tests + } -tag function \ No newline at end of file diff --git a/tests/readme.txt b/tests/readme.txt deleted file mode 100644 index 4b65c32..0000000 --- a/tests/readme.txt +++ /dev/null @@ -1,2 +0,0 @@ -Module Pester tests for the module. This file can be deleted. -