diff --git a/MyTasks.psd1 b/MyTasks.psd1 index 9d7bab3..64f4891 100644 --- a/MyTasks.psd1 +++ b/MyTasks.psd1 @@ -8,7 +8,9 @@ RootModule = 'MyTasks.psm1' # Version number of this module. -ModuleVersion = '1.9.0' +ModuleVersion = '2.0.0' + +CompatiblePSEditions = @("Desktop","Core") # ID used to uniquely identify this module GUID = '6a5db6e0-9669-4178-a176-54b4931aa4e2' @@ -26,7 +28,7 @@ Copyright = '(c) 2016-2019 JDH Information Technology Solutions, Inc. All rights Description = 'A tool set for managing tasks or to-do projects in PowerShell. Task data is stored in XML and managed through a PowerShell class.' # Minimum version of the Windows PowerShell engine required by this module -PowerShellVersion = '5.0' +PowerShellVersion = '5.1' # Name of the Windows PowerShell host required by this module # PowerShellHostName = '' @@ -56,7 +58,7 @@ PowerShellVersion = '5.0' # TypesToProcess = @() # Format files (.ps1xml) to be loaded when importing this module -FormatsToProcess = "MyTasks.format.ps1xml" +FormatsToProcess = "MyTasks.format.ps1xml","mytaskpath.format.ps1xml" # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess # NestedModules = @() @@ -65,7 +67,8 @@ FormatsToProcess = "MyTasks.format.ps1xml" FunctionsToExport = @("New-MyTask","Set-MyTask","Remove-MyTask","Get-MyTask", "Show-MyTask","Complete-MyTask","Get-MyTaskCategory","Add-MyTaskCategory", "Remove-MyTaskCategory","Backup-MyTaskFile","Save-MyTask","Enable-EmailReminder", -"Disable-EmailReminder","Get-EmailReminder","Set-MyTaskPath","Get-MyTaskArchive") +"Disable-EmailReminder","Get-EmailReminder","Set-MyTaskPath","Get-MyTaskArchive", +"Get-MyTaskPath") # Cmdlets to export from this module # CmdletsToExport = '*' diff --git a/MyTasks.psm1 b/MyTasks.psm1 index 91fc2c0..0362a86 100644 --- a/MyTasks.psm1 +++ b/MyTasks.psm1 @@ -1,13 +1,8 @@ #region variables -#path to user defined categories -if ($isLinux) { - $global:mytaskhome = $home -} -else { - $global:mytaskhome = "$home\Documents" -} +#set default location that should work cross platform +$global:myTaskHome = [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments) #path to the category file $global:myTaskCategory = Join-Path -Path $mytaskhome -ChildPath myTaskCategory.txt diff --git a/MyTasksFunctions.ps1 b/MyTasksFunctions.ps1 index c3c1a0c..bc9a754 100644 --- a/MyTasksFunctions.ps1 +++ b/MyTasksFunctions.ps1 @@ -61,7 +61,7 @@ Class MyTask { $this.Refresh() } #used for importing from XML - MyTask([string]$Name, [datetime]$DueDate, [string]$Description, [string]$Category,[boolean]$Completed) { + MyTask([string]$Name, [datetime]$DueDate, [string]$Description, [string]$Category, [boolean]$Completed) { write-verbose "[CLASS ] Constructing with due date, description and category" $this.Name = $Name $this.DueDate = $DueDate @@ -96,7 +96,7 @@ Function _ImportTasks { } $propHash | Out-String | Write-Verbose Try { - $tmp = New-Object -TypeName MyTask -ArgumentList $propHash.Name, $propHash.DueDate, $propHash.Description, $propHash.Category,$propHash.completed + $tmp = New-Object -TypeName MyTask -ArgumentList $propHash.Name, $propHash.DueDate, $propHash.Description, $propHash.Category, $propHash.completed #set additional properties $tmp.TaskID = $prophash.TaskID @@ -204,7 +204,7 @@ Function New-MyTask { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Calculating due date in $Days days" $DueDate = (Get-Date).AddDays($Days) } - $task = New-Object -TypeName MyTask -ArgumentList $Name, $DueDate, $Description, $Category,$False + $task = New-Object -TypeName MyTask -ArgumentList $Name, $DueDate, $Description, $Category, $False #convert to xml Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Converting to XML" @@ -545,7 +545,7 @@ Function Get-MyTask { [cmdletbinding(DefaultParameterSetName = "Days")] [OutputType("MyTask")] [Alias("gmt")] - + Param( [Parameter( Position = 0, @@ -746,7 +746,7 @@ Function Show-MyTask { $table = ($tasks | Format-Table -AutoSize | Out-String -Stream).split("`r`n") #define a regular expression pattern to match the due date - [regex]$rx = "\b\d{1,2}\/\d{1,2}\/\d{4}\b" + [regex]$rx = "\b\d{1,2}\/\d{1,2}\/(\d{2}|\d{4})\b" Write-Host "`n" Write-Host $table[1] -ForegroundColor Cyan @@ -755,7 +755,7 @@ Function Show-MyTask { #define a parameter hashtable to splat to Write-Host to better #handle colors in the PowerShell ISE under Windows 10 $phash = @{ - Object = $Null + object = $Null } $table[3..$table.count] | foreach-object { @@ -767,6 +767,8 @@ Function Show-MyTask { $hours = (($rx.Match($_).Value -as [datetime]) - (Get-Date)).totalhours } + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Hours = $hours" + #test if task is complete if ($_ -match '\b100\b$') { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Detected as completed" @@ -790,12 +792,13 @@ Function Show-MyTask { $hours = 999 } else { - if ($pHash.ContainsKey("foregroundcolor")) { + if ($pHash.ContainsKey("ForegroundColor")) { #remove foreground color so that Write-Host uses #the current default - $pHash.Remove("foregroundcolor") + $pHash.Remove("ForegroundColor") } } + Write-Host @pHash } #foreach @@ -1182,7 +1185,7 @@ Function Save-MyTask { foreach ($node in $completed.node) { $imp = $out.ImportNode($node.ParentNode, $True) Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Archiving $($node.parentnode.property[0].'#text')" - if ($PSCmdlet.ShouldProcess( $($node.parentnode.property[0].'#text') ,"Archiving")) { + if ($PSCmdlet.ShouldProcess( $($node.parentnode.property[0].'#text') , "Archiving")) { $parent.AppendChild($imp) | Out-Null #remove from existing file $in.objects.RemoveChild($node.parentnode) | Out-Null @@ -1241,7 +1244,7 @@ Function Enable-EmailReminder { [Parameter(HelpMessage = "Send an HTML body email")] [switch]$AsHtml, [ValidateNotNullOrEmpty()] - [ValidateScript({$_ -gt 0})] + [ValidateScript( {$_ -gt 0})] [int]$Days = 3, [Parameter(Mandatory, HelpMessage = "Re-enter your local user credentials for the scheduled job task")] [ValidateNotNullOrEmpty()] @@ -1517,6 +1520,19 @@ Function Set-MyTaskPath { } } #close Set-MyTaskPath +Function Get-MyTaskPath { + [cmdletbinding()] + Param() + + [PSCustomObject]@{ + PSTypeName = "myTaskPath" + myTaskHome = $global:mytaskhome + myTaskPath = $global:myTaskPath + myTaskArchivePath = $global:myTaskArchivePath + myTaskCategory = $global:myTaskCategory + } +} + Function Get-MyTaskArchive { [cmdletbinding(DefaultParameterSetName = "Name")] @@ -1606,7 +1622,7 @@ Function Get-MyTaskArchive { "Category" { Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Retrieving tasks for category $Category" - $results = $tasks.Where({$_.Category -eq $Category}) + $results = $tasks.Where( {$_.Category -eq $Category}) } #category } #switch @@ -1614,8 +1630,8 @@ Function Get-MyTaskArchive { #display tasks if found otherwise display a warning if ($results.count -ge 1) { $results.foreach( { - $_.psobject.typenames.insert(0, "myTaskArchive")}) - $results + $_.psobject.typenames.insert(0, "myTaskArchive")}) + $results } else { Write-Warning "No tasks found matching your criteria" @@ -1628,5 +1644,7 @@ Function Get-MyTaskArchive { } #Get-MyTask + + #endregion diff --git a/README.md b/README.md index a8bae21..5625e01 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MyTasks -This PowerShell module is designed as a task or simple To-Do manager. The module contains several commands for working with tasks. It should work with both Windows PowerShell and PowerShell Core. You can install the latest version from the PowerShell Gallery. You will need the -Scope parameter for PowerShell Core. +This PowerShell module is designed as a task or simple To-Do manager. The module contains several commands for working with tasks. It should work with both Windows PowerShell and PowerShell Core with a few limitations. You can install the latest version from the PowerShell Gallery. You will need the -Scope parameter for PowerShell Core. ```powershell Install-Module MyTasks [-scope currentuser] @@ -41,13 +41,13 @@ New-MyTask "return library books" -Category personal You can also specify a due date. ```powershell -New-MyTask "Pluralsight" -duedate "2/1/2018" -description "renew subscription" -category other +New-MyTask "Pluralsight" -duedate "2/1/2019" -description "renew subscription" -category other ``` You can use `Set-MyTask` to modify a task. ```powershell -Get-MyTask Pluralsight | Set-Mytask -DueDate 3/1/2018 +Get-MyTask Pluralsight | Set-Mytask -DueDate 3/1/2019 ``` Because the task has a Progress property, you can use [Set-MyTask](./docs/Set-MyTask.md) to update that as well. @@ -63,7 +63,7 @@ PS S:\> get-mytask -name MemoryTools ID Name Description DueDate OverDue Category Progress -- ---- ----------- ------- ------- -------- -------- -8 MemoryTools update module 7/22/2018 False Projects 10 +8 MemoryTools update module 7/22/2019 False Projects 10 ``` The default behavior is to display incomplete tasks due in the next 30 days. Look at the help for `Get-MyTask` for more information. @@ -94,7 +94,7 @@ Over time your task file might get quite large. Even though the default behavior Get-Mytask -Completed | Archive-MyTask ``` -There is an option to archive tasks when you run [Complete-MyTask](./docs/Complete-MyTask.md). T. Or you can completely delete a task with `Remove-MyTask`. +There is an option to archive tasks when you run [Complete-MyTask](./docs/Complete-MyTask.md). Or you can completely delete a task with `Remove-MyTask`. Use the `Get-myTaskArchive` to view archived tasks. @@ -119,10 +119,11 @@ You should read full help and examples for all commands as well as the [about_My + [Disable-EmailReminder](docs/Disable-EmailReminder.md) + [Get-EmailReminder](docs/Get-EmailReminder.md) + [Set-MyTaskPath](docs/Set-MyTaskPath.md) ++ [Get-MyTaskPath](docs/Get-MyTaskPath.md) + [Get-MyTaskArchive](docs/Get-MyTaskArchive.md) ## Limitations Please post any issues, questions or feature requests in the [Issues](https://github.com/jdhitsolutions/MyTasks/issues) section. -*last updated 04 January 2019* +*last updated 20 February 2019* diff --git a/Tests/MyTasks.module.tests.ps1 b/Tests/MyTasks.module.tests.ps1 index 0280cbf..7aa6d58 100644 --- a/Tests/MyTasks.module.tests.ps1 +++ b/Tests/MyTasks.module.tests.ps1 @@ -7,8 +7,8 @@ Import-Module -Name "$PSScriptRoot\..\Mytasks.psd1" -Force Describe 'MyTasks' { $Module = Get-Module -Name MyTasks - It 'should have 15 functions' { - $Module.ExportedFunctions.count | Should -Be 16 + It 'should have 17 functions' { + $Module.ExportedFunctions.count | Should -Be 17 } It 'should have 8 aliases command' { @@ -30,16 +30,16 @@ Describe 'MyTasks' { param ($Variable) {Get-Variable -Name $variable -Scope global} | Should -Not -Throw } - It 'should have a formatting xml file' { - $Module.ExportedFormatFiles.Count | Should -Be 1 + It 'should have 2 formatting xml files' { + $Module.ExportedFormatFiles.Count | Should -Be 2 } It 'should have an about help topic' { {Get-Help about_mytasks} | Should -Not -Throw } - It 'requires PowerShell 5.0' { - $Module.PowerShellVersion | Should -Be '5.0' + It 'requires PowerShell 5.1' { + $Module.PowerShellVersion | Should -Be '5.1' } } #describe my module @@ -62,6 +62,7 @@ Describe "Functions" { @{Name = 'Backup-MyTaskFile'} @{Name = 'Set-MyTaskPath'} @{Name = 'Get-myTaskArchive'} + @{Name = 'Get-MyTaskPath'} ) It " has external help defined with at least one example" -TestCases $cmds { @@ -181,6 +182,10 @@ Describe "Functions" { } Context 'Get-MyTaskArchive' { + + } + + Context 'Get-MyTaskPath' { } diff --git a/changelog.md b/changelog.md index f581675..71bf6ff 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Change Log for MyTasks +## v2.0.0 + ++ Updated manifest to require PowerShell 5.1 and support for both Desktop and Core PSEditions *Breaking Change* ++ Added `Get-MyTaskPath` command (Issue #36) ++ Added a format.ps1xml file for `Get-MyTaskPath` ++ Modified code to determine home folder to use `[Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments)` Thank you @kilasuit and @thecliguy (Issue #35) *Breaking Change* ++ Fixed bug in `Show-Mytask` where year is displayed in 2 digits instead of 4 on Linux platforms. ++ documentation updates + ## v1.9.0 + Updated autocompleter to get task names and enclose in quotes @@ -10,7 +19,7 @@ + Modified `MyTasks.format.ps1xml` to support myTaskArchive type + Updated help -## v1.8.2 +## v1.8.2ex + Fixed bugs with email reminder. Typo in a parameter name. + Added parameter validation for `-Days` in `Enable-EmailReminder` diff --git a/docs/Get-MyTaskPath.md b/docs/Get-MyTaskPath.md new file mode 100644 index 0000000..9d0372f --- /dev/null +++ b/docs/Get-MyTaskPath.md @@ -0,0 +1,62 @@ +--- +external help file: MyTasks-help.xml +Module Name: Mytasks +online version: +schema: 2.0.0 +--- + +# Get-MyTaskPath + +## SYNOPSIS + +Get current values of the myTask variables + +## SYNTAX + +```yaml +Get-MyTaskPath [] +``` + +## DESCRIPTION + +The myTasks module relies on a number of global variables to keep track of the necessary files. While you can use Get-Variable to see the current value, this command simplifies the entire process. + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> get-mytaskpath + + +myTaskHome : C:\Users\Jeff\dropbox\mytasks +myTaskPath : C:\Users\Jeff\dropbox\mytasks\myTasks.xml +myTaskArchivePath : C:\Users\Jeff\dropbox\mytasks\myTasksArchive.xml +myTaskCategory : C:\Users\Jeff\dropbox\mytasks\myTaskCategory.txt +``` + +Display the current locations. You can modify them using Set-MyTaskPath. + +## PARAMETERS + +### 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 + +### myTaskPath + +## NOTES + +Learn more about PowerShell: +http://jdhitsolutions.com/blog/essential-powershell-resources/ + +## RELATED LINKS + +[Set-MyTaskPath]() \ No newline at end of file diff --git a/docs/about_MyTasks.md b/docs/about_MyTasks.md index f2a3a29..64770af 100644 --- a/docs/about_MyTasks.md +++ b/docs/about_MyTasks.md @@ -54,6 +54,10 @@ C:\Users\Jeff\Documents\myTasks.xml. There is also an XML file for archiving completed tasks. This too is in the Documents or $home folder and can be referenced via the myTaskArchivePath variable. +NOTE: Starting with version 2.0.0 of this module the home location is determined +by using [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments) +Use the `Get-MyTaskPath` command to view your current settings. + As tasks are created, modified, completed and archived, these XML files are updated. `Select-XML` is used extensively to make this process as efficient as possible. diff --git a/en-US/MyTasks-help.xml b/en-US/MyTasks-help.xml index b0bbf0b..219166a 100644 --- a/en-US/MyTasks-help.xml +++ b/en-US/MyTasks-help.xml @@ -1778,6 +1778,71 @@ Customer + + + Get-MyTaskPath + Get + MyTaskPath + + Get current values of the myTask variables + + + + The myTasks module relies on a number of global variables to keep track of the necessary files. While you can use Get-Variable to see the current value, this command simplifies the entire process. + + + + Get-MyTaskPath + + + + + + + None + + + + + + + + + + myTaskPath + + + + + + + + + Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ + + + + + -------------------------- Example 1 -------------------------- + PS C:\> get-mytaskpath + + +myTaskHome : C:\Users\Jeff\dropbox\mytasks +myTaskPath : C:\Users\Jeff\dropbox\mytasks\myTasks.xml +myTaskArchivePath : C:\Users\Jeff\dropbox\mytasks\myTasksArchive.xml +myTaskCategory : C:\Users\Jeff\dropbox\mytasks\myTaskCategory.txt + + Display the current locations. You can modify them using Set-MyTaskPath. + + + + + + Set-MyTaskPath + + + + New-MyTask diff --git a/en-US/about_mytasks.help.txt b/en-US/about_mytasks.help.txt index 740f3f8..77aba7c 100644 --- a/en-US/about_mytasks.help.txt +++ b/en-US/about_mytasks.help.txt @@ -49,6 +49,10 @@ LONG DESCRIPTION for archiving completed tasks. This too is in the Documents or $home folder and can be referenced via the myTaskArchivePath variable. + NOTE: Starting with version 2.0.0 of this module the home location is determined + by using [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments) + Use the `Get-MyTaskPath` command to view your current settings. + As tasks are created, modified, completed and archived, these XML files are updated. Select-XML is used extensively to make this process as efficient as possible. diff --git a/mytaskpath.format.ps1xml b/mytaskpath.format.ps1xml new file mode 100644 index 0000000..9ac4cc6 --- /dev/null +++ b/mytaskpath.format.ps1xml @@ -0,0 +1,44 @@ + + + + + + + default + + myTaskPath + + + + + + + + + myTaskHome + + + + myTaskPath + + + + myTaskArchivePath + + + + myTaskCategory + + + + + + + + \ No newline at end of file