Skip to content

Commit bc6f481

Browse files
authored
Merge pull request #9 from rulasg/allow-albitrary-path
feat(new-notes): add RootPath parameter to New-Note and related functions
2 parents ee27673 + 3725469 commit bc6f481

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

Test/public/newNotes.test.ps1

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,30 @@ function Test_NewNotes_SUCCESS{
163163

164164
}
165165

166-
# ./TestNotesRoot/howto/250720-howto-someting_that_may_be_useful/250720-howto-someting_that_may_be_useful.md ]
167-
# ./TestNotesRoot/howto/250728-howto-someting_that_may_be_useful/250728-howto-someting_that_may_be_useful.md ]
168-
# [ /tmp/Posh_Testing_250728_87d8dc/TestRunFolder/Test_NewNotesToday_Failing
166+
function Test_NewNotes_SUCCESS_WithRootPath{
167+
168+
Reset-InvokeCommandMock
169+
170+
$RootFolder = "TestNotesRoot"
171+
172+
New-TestingFolder $RootFolder
173+
174+
New-TestingFolder -Path "./$RootFolder/howto"
175+
$today = (Get-Date).ToString("yyMMdd")
176+
177+
# Act
178+
$result = New-Note howto "someting that may be useful" -NoOpen -RootPath $RootFolder
179+
180+
$expectedPath = "./$RootFolder/howto/howto-someting_that_may_be_useful/howto-someting_that_may_be_useful.md"
181+
182+
Assert-AreEqualPath -Expected $expectedPath -Presented $result
183+
184+
# With date
185+
186+
$result = New-Note howto "someting that may be useful" -NoOpen -Date $today -RootPath $RootFolder
187+
188+
$expectedPath = "./$RootFolder/howto/$today-howto-someting_that_may_be_useful/$today-howto-someting_that_may_be_useful.md"
189+
190+
Assert-AreEqualPath -Expected $expectedPath -Presented $result
191+
192+
}

private/resolveNotesPath.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ function Resolve-NotesPath {
2424
function Get-NoteFolder{
2525
[CmdletBinding()]
2626
param(
27+
[Parameter()][string] $RootPath,
2728
[Parameter()][string] $Category,
2829
[Parameter()][string] $Section,
2930
[Parameter()][switch] $Force
3031
)
3132

32-
$notesPath = Resolve-NotesPath
33+
$notesPath = Resolve-NotesPath -Path $RootPath
3334

3435
# Add the category if needed
3536
if(-Not [string]::IsNullOrWhiteSpace($Category)) {

public/newNotes.ps1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ function New-Note{
1313
[Parameter()][string] [ValidateSet("none","meetingmini")] $Template = "none",
1414
[Parameter()][switch] $NoOpen,
1515
[Parameter()][switch] $AvoidChildFolder,
16-
[Parameter()][switch] $Force
16+
[Parameter()][switch] $Force,
17+
[Parameter()][string] $RootPath
18+
1719
)
1820

1921
# FILENAME
2022

21-
$folder = Get-NoteFolder -Category $Category -Section $Section -Force:$Force
23+
$folder = Get-NoteFolder -RootPath $RootPath -Category $Category -Section $Section -Force:$Force
2224

2325
if(-Not $folder) {
2426
Write-Error "Failed to create the folder for the note. Try -Force."
@@ -141,12 +143,13 @@ function New-NoteToday{
141143
[Parameter()][string] [ValidateSet("none","meetingmini")] $Template = "none",
142144
[Parameter()][switch] $NoOpen,
143145
[Parameter()][switch] $AvoidChildFolder,
144-
[Parameter()][switch] $Force
146+
[Parameter()][switch] $Force,
147+
[Parameter()][string] $RootPath
145148
)
146149

147150
# FILENAME
148151

149-
$folder = Get-NoteFolder -Category $Category -Section $Section -Force:$Force
152+
$folder = Get-NoteFolder -RootPath $RootPath -Category $Category -Section $Section -Force:$Force
150153

151154
if(-Not $folder) {
152155
Write-Error "Failed to create the folder for the note. Try -Force."
@@ -272,7 +275,8 @@ function New-NoteTodayMeeting{
272275
[Parameter(Position = 2)][string] $Notes,
273276
[Parameter(ValueFromPipeline)][string] $IssueUrl,
274277
[Parameter()][switch] $NoOpen,
275-
[Parameter()][switch] $Force
278+
[Parameter()][switch] $Force,
279+
[Parameter()][string] $RootPath
276280
)
277281

278282
begin {
@@ -282,7 +286,7 @@ function New-NoteTodayMeeting{
282286

283287
process{
284288

285-
$folder = Get-NoteFolder -Category $category -Section $section -Force:$Force
289+
$folder = Get-NoteFolder -RootPath $RootPath -Category $category -Section $section -Force:$Force
286290

287291
if (-not $folder) {
288292
Write-Error "Client folder for '$section' does not exist and Force was not specified."

0 commit comments

Comments
 (0)