Skip to content

Commit db9e975

Browse files
it-praktykWojciech Sciesinski
authored and
Wojciech Sciesinski
committed
New-OutputObject v. 0.9.12
1 parent 1d06cb9 commit db9e975

7 files changed

+162
-37
lines changed

CHANGELOG.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@
9090
- New-OutputObject-Module-Specific.Tests v. 0.9.11
9191
- New-OutputObject.Tests v. 0.9.11
9292
- Test-CharsInPath.Tests v. 0.7.0
93+
- 0.9.12 - 2018-03-16
94+
- New-OutputObject v. 0.9.12
95+
- New-OutputFile v. 0.9.11
96+
- New-OutputFolder v. 0.9.11
97+
- Test-CharsInPath v. 0.7.0
98+
- Get-OverwriteDecision v. 0.1.2
99+
- New-OutputObject-Module-Specific.Tests v. 0.9.11
100+
- New-OutputObject.Tests v. 0.9.12
101+
- Test-CharsInPath.Tests v. 0.7.0
93102

94103
## General
95104

@@ -116,6 +125,9 @@
116125
- 0.9.11 - 2017-10-16
117126
- Module can run when Set-StrictMode -Value Latest is set
118127
- Compatibility with PowerShell Core 6.0 beta 8
128+
- 0.9.12 - 2018-03-16
129+
- The parameter Force added
130+
- minor formating updates
119131

120132
## Function New-OutputObject
121133

@@ -135,7 +147,9 @@
135147
- 0.9.11 - 2017.10.16
136148
- The function can run when Set-StrictMode -Value Latest is set
137149
- Compatibility with PowerShell Core 6.0 beta 8
138-
150+
- 0.9.12 - 2018-03-16
151+
- The parameter Force added
152+
- minor formating updates
139153

140154
## Function New-OutputFile
141155

@@ -162,6 +176,7 @@
162176
- 0.9.8 - 2017-05-06 - Help updated due to change of description for the ExcitCode = 1, default value for the parameter DateTimePartFormat declared
163177
- 0.9.9 - 2017-05-16 - skiping inadequate PScriptAnalyzer rule implemented better
164178
- 0.9.10 - 2017-07-23 - Reference to VERSIONS.md changed to CHANGELOG.md
179+
- 0.9.11 - 2018-03-16 - The parameter Force added, minor formating updates
165180

166181
## Function New-OutputFolder
167182

@@ -177,6 +192,7 @@
177192
- 0.9.8 - 2017-05-06 - Help updated due to change of description for the ExcitCode = 1, default value for the parameter DateTimePartFormat declared
178193
- 0.9.9 - 2017-05-16 - An unused parameter removed - fix #2, skiping inadequate PScriptAnalyzer rule implemented better
179194
- 0.9.10 - 2017-07-23 - Reference to VERSIONS.md changed to CHANGELOG.md
195+
- 0.9.11 - 2018-03-16 - The parameter Force added, minor formating updates
180196

181197
## Function Test-CharsInPath
182198

@@ -235,6 +251,7 @@
235251
- The function can run when Set-StrictMode -Value Latest is set
236252
- Compatibility with PowerShell Core 6.0 beta 8
237253
- folder separators generalized to support differences between Windows/Linux/macOS
254+
- 0.9.12 - 2018-03-16 - The parameter Force added, minor formating updates
238255

239256
## Test-CharsInPath.Tests
240257

New-OutputObject.psd1

-134 Bytes
Binary file not shown.

Public/New-OutputFile.ps1

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ Function New-OutputFile {
1717
- 1 = "Provided parent path <PATH> doesn't exist"
1818
- 2 = "The result name contains unacceptable chars"
1919
- 3 = "Provided patch <PATH> is not writable"
20-
- 4 = "The file <PATH>\\<FILE_NAME> already exist - can be overwritten"
21-
- 5 = "The file <PATH>\\<FILE_NAME> already exist - can't be overwritten"
20+
- 4 = "The file <PATH>\\<FILE_NAME> already exist - can be overwritten"
21+
- 5 = "The file <PATH>\\<FILE_NAME> already exist - can't be overwritten"
22+
- 6 = "The file <PATH>\\<FILE_NAME> already exist - can be overwritten due to used the Force switch"
2223
2324
.PARAMETER ParentPath
2425
The folder path what will be used as the parent path for the new created object.
@@ -53,6 +54,9 @@ Function New-OutputFile {
5354
.PARAMETER BreakIfError
5455
Break function execution if parameters provided for output file creation are not correct or destination file path is not writables
5556
57+
.PARAMETER Force
58+
If used the function Doesn't ask for an overwrite decission, assumes that the file can be overwritten
59+
5660
.EXAMPLE
5761
5862
PS \> (Get-Item env:COMPUTERNAME).Value
@@ -131,7 +135,7 @@ Function New-OutputFile {
131135
KEYWORDS: PowerShell, File, FileSystem
132136
133137
CURRENT VERSION
134-
- 0.9.10 - 2017-07-23
138+
- 0.9.11 - 2018-03-16
135139
136140
HISTORY OF VERSIONS
137141
https://github.com/it-praktyk/New-OutputObject/CHANGELOG.md
@@ -167,7 +171,9 @@ Function New-OutputFile {
167171
[alias("Separator")]
168172
[String]$NamePartsSeparator = "-",
169173
[parameter(Mandatory = $false)]
170-
[Switch]$BreakIfError
174+
[Switch]$BreakIfError,
175+
[parameter(Mandatory = $false)]
176+
[Switch]$Force
171177
)
172178

173179

Public/New-OutputFolder.ps1

+7-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Function New-OutputFolder {
5050
.PARAMETER BreakIfError
5151
Break function execution if parameters provided for output folder creation are not correct or destination folder path is not writables
5252
53+
.PARAMETER Force
54+
If used the function Doesn't ask for an overwrite decission, assumes that the file can be overwritten
55+
5356
.EXAMPLE
5457
5558
PS \> (Get-Item env:COMPUTERNAME).Value
@@ -126,7 +129,7 @@ Function New-OutputFolder {
126129
KEYWORDS: PowerShell, Folder, FileSystem
127130
128131
CURRENT VERSION
129-
- 0.9.10 - 2017-07-23
132+
- 0.9.11 - 2018-03-16
130133
131134
HISTORY OF VERSIONS
132135
https://github.com/it-praktyk/New-OutputObject/CHANGELOG.md
@@ -160,8 +163,9 @@ Function New-OutputFolder {
160163
[alias("Separator")]
161164
[String]$NamePartsSeparator="-",
162165
[parameter(Mandatory = $false)]
163-
[Switch]$BreakIfError
164-
166+
[Switch]$BreakIfError,
167+
[parameter(Mandatory = $false)]
168+
[Switch]$Force
165169
)
166170

167171
$params = @{

Public/New-OutputObject.ps1

+41-24
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Function New-OutputObject {
1818
- 1 = "Provided parent path <PATH> doesn't exist"
1919
- 2 = "The name not created due to unaccepatable chars"
2020
- 3 = "Provided patch <PATH> is not writable"
21-
- 4 = "The file\folder <PATH>\\<FILE_OR_FOLDER_NAME> already exist - can be overwritten"
22-
- 5 = "The file\folder <PATH>\\<FILE_OR_FOLDER_NAME> already exist - can't be overwritten"
21+
- 4 = "The file\folder <PATH>\\<FILE_OR_FOLDER_NAME> already exist - can be overwritten"
22+
- 5 = "The file\folder <PATH>\\<FILE_OR_FOLDER_NAME> already exist - can't be overwritten"
23+
- 6 = "The file\folder <PATH>\\<FILE_OR_FOLDER_NAME> already exist - can be overwritten due to used the Force switch"
2324
2425
.PARAMETER ObjectType
2526
Type of object to prepare - file or folder
@@ -57,6 +58,9 @@ Function New-OutputObject {
5758
.PARAMETER BreakIfError
5859
Break function execution if parameters provided for output file creation are not correct or destination file path is not writables
5960
61+
.PARAMETER Force
62+
If used the function Doesn't ask for an overwrite decission, assumes that the file can be overwritten
63+
6064
.EXAMPLE
6165
6266
PS \> (Get-Item env:COMPUTERNAME).Value
@@ -68,8 +72,6 @@ Function New-OutputObject {
6872
OutputObjectNamePrefix = 'Messages';
6973
OutputObjectNameMidPart = (Get-Item env:COMPUTERNAME).Value;
7074
IncludeDateTimePartInOutputObjectName = $true;
71-
IncludeDateTimePartInOutputObjectName = $true;
72-
7375
BreakIfError = $true
7476
}
7577
@@ -145,7 +147,7 @@ Function New-OutputObject {
145147
KEYWORDS: PowerShell, File, Folder, FileSystem
146148
147149
CURRENT VERSION
148-
- 0.9.11- 2017-10-16
150+
- 0.9.12- 2018-03-16
149151
150152
HISTORY OF VERSIONS
151153
https://github.com/it-praktyk/New-OutputObject/CHANGELOG.md
@@ -185,8 +187,9 @@ Function New-OutputObject {
185187
[alias("Separator")]
186188
[String]$NamePartsSeparator = "-",
187189
[parameter(Mandatory = $false)]
188-
[Switch]$BreakIfError
189-
190+
[Switch]$BreakIfError,
191+
[parameter(Mandatory = $false)]
192+
[Switch]$Force
190193
)
191194

192195
#Declare variable
@@ -197,8 +200,9 @@ Function New-OutputObject {
197200
1 = "Provided parent path {0} doesn't exist"; # $ParentPath
198201
2 = 'The name not created due to unaccepatable chars';
199202
3 = "Provided path {0} is not writable"; # $ParentPath
200-
4 = "The {0} {1} already exist - can be overwritten" # $ItemTypeLowerCase, $OutputObjectPath.FullName
201-
5 = "The {0} {1} already exist - can't be overwritten" # $ItemTypeLowerCase, $OutputObjectPath
203+
4 = "The {0} {1} already exist - can be overwritten" # $ItemTypeLowerCase, $OutputObjectPath.FullName
204+
5 = "The {0} {1} already exist - can't be overwritten" # $ItemTypeLowerCase, $OutputObjectPath
205+
6 = "The {0} {1} already exist - can be overwritten due to used the Force switch" # $ItemTypeLowerCase, $OutputObjectPath
202206
}
203207

204208
[String]$ExitCodeDescription = 'Everything is fine :-)'
@@ -474,39 +478,52 @@ Function New-OutputObject {
474478

475479
If (Test-Path -Path $OutputObjectPath -PathType $PathType) {
476480

477-
$Answer = Get-OverwriteDecision -Path $OutputObjectPath -ItemType $ObjectType
481+
If ( -not $Force.IsPresent) {
478482

479-
switch ($Answer) {
483+
$Answer = Get-OverwriteDecision -Path $OutputObjectPath -ItemType $ObjectType
480484

481-
0 {
485+
switch ($Answer) {
482486

483-
[Int]$ExitCode = 4
487+
0 {
484488

485-
[String]$MessageText = $ExitCodesDescriptions[$ExitCode] -f $ItemTypeLowerCase, $OutputObjectPath.FullName
489+
[Int]$ExitCode = 4
486490

487-
[String]$ExitCodeDescription = $MessageText
491+
[String]$MessageText = $ExitCodesDescriptions[$ExitCode] -f $ItemTypeLowerCase, $OutputObjectPath.FullName
488492

489-
}
493+
[String]$ExitCodeDescription = $MessageText
490494

491-
1 {
495+
}
492496

493-
[Int]$ExitCode = 5
497+
1 {
494498

495-
[String]$MessageText = "The {0} {1} already exist - can't be overwritten" -f $ItemTypeLowerCase, $OutputObjectPath
499+
[Int]$ExitCode = 5
496500

497-
[String]$ExitCodeDescription = $MessageText
501+
[String]$MessageText = $ExitCodesDescriptions[$ExitCode] -f $ItemTypeLowerCase, $OutputObjectPath
498502

499-
}
503+
[String]$ExitCodeDescription = $MessageText
500504

501-
2 {
505+
}
502506

503-
[String]$MessageText = "The {0} {1} already exist - operation canceled by user" -f $ItemTypeLowerCase, $OutputObjectPath
507+
2 {
504508

505-
Throw $MessageText
509+
[String]$MessageText = "The {0} {1} already exist - operation canceled by user" -f $ItemTypeLowerCase, $OutputObjectPath
510+
511+
Throw $MessageText
512+
513+
}
506514

507515
}
508516

509517
}
518+
else {
519+
520+
[Int]$ExitCode = 6
521+
522+
[String]$MessageText = $ExitCodesDescriptions[$ExitCode] -f $ItemTypeLowerCase, $OutputObjectPath
523+
524+
[String]$ExitCodeDescription = $MessageText
525+
526+
}
510527

511528
}
512529

TODO.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Alligned to the version 0.9.10 - 2017-07-23
1313
- Exit codes and descriptions of them should to be moved to external parsable file
1414
- Static descriptions should be replaced by description from the external file
1515
- Check the function behaviour when called from other PSProvider than Filesystem
16-
- Add support for the Force parameter (if the parent path doesn't exist) or to replace/don't ask about overwrite decission
17-
- Catch situation when provided relative parent path is to high like "..\..\..\..\" - throw error(?)
16+
- Catch situation when provided relative parent path is too high, like "..\..\..\..\" - throw error(?)
1817
The current behaviouris: return root of psdrive
1918
- Trim provided parameters and display warning (?)
2019
- Replace non standard chars (?)

Tests/New-OutputObject.Tests.ps1

+85-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
KEYWORDS: PowerShell, Pester, psd1, New-OutputObject, New-OutputObject
1111
1212
CURRENT VERSION
13-
- 0.9.11 - 2017-10-16
13+
- 0.9.12 - 2017-03-16
1414
1515
HISTORY OF VERSIONS
1616
https://github.com/it-praktyk/New-OutputObject/CHANGELOG.md
@@ -1119,7 +1119,7 @@ foreach ($ObjectType in $ObjectTypes) {
11191119

11201120
It "Function $FunctionName - $ContextName - exit code description" {
11211121

1122-
[System.String]$RequiredMessage = "The {0} {1} already exist - can be overwritten" -f $ObjectType, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$TestExistingObject")
1122+
[System.String]$RequiredMessage = "The {0} {1} already exist - can be overwritten" -f $ObjectType, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$TestExistingObject")
11231123

11241124
$Result.ExitCodeDescription | Should Be $RequiredMessage
11251125

@@ -1201,7 +1201,7 @@ foreach ($ObjectType in $ObjectTypes) {
12011201

12021202
It "Function $FunctionName - $ContextName - exit code description" {
12031203

1204-
[System.String]$RequiredMessage = "The {0} {1} already exist - can't be overwritten" -f $ItemTypeLower, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$TestExistingObject")
1204+
[System.String]$RequiredMessage = "The {0} {1} already exist - can't be overwritten" -f $ItemTypeLower, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$TestExistingObject")
12051205

12061206
$Result.ExitCodeDescription | Should Be $RequiredMessage
12071207

@@ -1267,6 +1267,88 @@ foreach ($ObjectType in $ObjectTypes) {
12671267

12681268
}
12691269

1270+
[System.String]$ContextName = "run without parameters, destination {0} exists, the Force defined" -f $ObjectType
1271+
1272+
Context "Function $FunctionName - $ContextName" {
1273+
1274+
If ($ObjectType -eq 'File') {
1275+
1276+
Mock -ModuleName New-OutputObject -CommandName Get-Date -MockWith { Return [System.String]'20161108-000002' } -ParameterFilter { $Format }
1277+
1278+
$ExpectedOutputObjectName = "Output-20161108-000002.txt"
1279+
1280+
$OutputTypeToCreate = 'file'
1281+
1282+
[System.String]$TestExistingObject = "TestDrive:\Output-20161108-000002.txt"
1283+
1284+
}
1285+
Else {
1286+
1287+
Mock -ModuleName New-OutputObject -CommandName Get-Date -MockWith { Return [System.String]'20161108' } -ParameterFilter { $Format }
1288+
1289+
$ExpectedOutputObjectName = "Output-20161108"
1290+
1291+
$OutputTypeToCreate = 'directory'
1292+
1293+
[System.String]$TestExistingObject = "TestDrive:\Output-20161108"
1294+
1295+
1296+
}
1297+
1298+
1299+
New-Item -Path $TestExistingObject -ItemType $OutputTypeToCreate
1300+
1301+
Mock -ModuleName New-OutputObject -CommandName Get-OverwriteDecision -MockWith { Return [int]1 }
1302+
1303+
If ($ObjectType -eq 'File') {
1304+
1305+
$ResultProxyFunction = New-OutputFile -Force -Verbose:$VerboseInternal
1306+
1307+
}
1308+
Else {
1309+
1310+
$ResultProxyFunction = New-OutputFolder -Force -Verbose:$VerboseInternal
1311+
1312+
}
1313+
1314+
$Result = New-OutputObject -Verbose:$VerboseInternal -ObjectType $ObjectType
1315+
1316+
It "Function $FunctionName - $ContextName - OutputObjectPath - an object type" {
1317+
1318+
$Result.OutputObjectPath | Should BeOfType $ExpectedObjectType
1319+
1320+
$ResultProxyFunction.OutputObjectPath | Should BeOfType $ExpectedObjectType
1321+
1322+
}
1323+
1324+
It "Function $FunctionName - $ContextName - OutputObjectPath - Name " {
1325+
1326+
$Result.OutputObjectPath.Name | Should Be $ExpectedOutputObjectName
1327+
1328+
$ResultProxyFunction.OutputObjectPath.Name | Should Be $ExpectedOutputObjectName
1329+
1330+
}
1331+
1332+
It "Function $FunctionName - $ContextName - exit code" {
1333+
1334+
$Result.ExitCode | Should Be 6
1335+
1336+
$ResultProxyFunction.ExitCode | Should Be 6
1337+
1338+
}
1339+
1340+
It "Function $FunctionName - $ContextName - exit code description" {
1341+
1342+
[System.String]$RequiredMessage = "The {0} {1} already exist - can be overwritten due to used the Force switch" -f $ItemTypeLower, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$TestExistingObject")
1343+
1344+
$Result.ExitCodeDescription | Should Be $RequiredMessage
1345+
1346+
$ResultProxyFunction.ExitCodeDescription | Should Be $RequiredMessage
1347+
1348+
}
1349+
1350+
}
1351+
12701352
$ContextName = "run with incorrect chars in DateTimePartFormat, BreakIfError"
12711353

12721354
Context "Function $FunctionName - $ContextName" {

0 commit comments

Comments
 (0)