Skip to content

Commit 75b7363

Browse files
feat: Support paths in quotes
1 parent f0f549e commit 75b7363

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

functions/keytool.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#PSScriptInfo
2-
.VERSION 1.0.0
2+
.VERSION 1.1.0
33
.GUID d73b9c33-1ca5-40c2-bbce-ff18efd062ab
44
.AUTHOR Code Dx
55
.DESCRIPTION Includes keytool-related helpers
@@ -32,6 +32,12 @@ function Set-KeystorePassword([string] $keystorePath, [string] $keystorePwd, [st
3232
}
3333
}
3434

35+
function Test-KeystoreAlias([string] $keystorePath, [string] $keystorePwd, [string] $aliasName) {
36+
37+
keytool -list -alias $aliasName -keystore $keystorePath -storepass (Get-KeystorePasswordEscaped $keystorePwd) | Out-Null
38+
$?
39+
}
40+
3541
function Remove-KeystoreAlias([string] $keystorePath, [string] $keystorePwd, [string] $aliasName) {
3642

3743
keytool -delete -alias $aliasName -keystore $keystorePath -storepass (Get-KeystorePasswordEscaped $keystorePwd)
@@ -57,7 +63,9 @@ function Import-TrustedCaCert([string] $keystorePath, [string] $keystorePwd, [st
5763

5864
$aliasName = Get-TrustedCaCertAlias $certFile
5965

60-
Remove-KeystoreAlias $keystorePath $keystorePwd $aliasName
66+
if (Test-KeystoreAlias $keystorePath $keystorePwd $aliasName) {
67+
Remove-KeystoreAlias $keystorePath $keystorePwd $aliasName
68+
}
6169
Add-KeystoreAlias $keystorePath $keystorePwd $aliasName $certFile
6270
}
6371

guided-setup.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'guided-setup'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.14.0'
15+
ModuleVersion = '1.15.0'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @('Core')

guided-setup.psm1

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,10 @@ class IntegerQuestion : Question {
754754

755755
class PathQuestion : Question {
756756

757-
[microsoft.powershell.commands.testpathtype] $type
757+
[bool] $isDirectory
758758

759-
PathQuestion([string] $promptText, [microsoft.powershell.commands.testpathtype] $type, [bool] $allowEmptyResponse) : base($promptText) {
760-
$this.type = $type
759+
PathQuestion([string] $promptText, [bool] $isDirectory, [bool] $allowEmptyResponse) : base($promptText) {
760+
$this.isDirectory = $isDirectory
761761
$this.allowEmptyResponse = $allowEmptyResponse
762762
}
763763

@@ -774,22 +774,33 @@ class PathQuestion : Question {
774774
break
775775
}
776776

777-
if (Test-Path $this.response -PathType $this.type) {
777+
$pathType = 'Leaf'
778+
if ($this.isDirectory) {
779+
$pathType = 'Container'
780+
}
781+
782+
if (Test-Path $this.response -PathType $pathType) {
783+
break
784+
}
785+
786+
$path = $this.response.Trim("'").Trim('"')
787+
if (Test-Path $path -PathType $pathType) {
788+
$this.response = $path
778789
break
779790
}
780791

781-
$pathType = 'file'
782-
if ($this.type -eq [microsoft.powershell.commands.testpathtype]::Container) {
783-
$pathType = 'directory'
792+
$pathTypeMessage = 'file'
793+
if ($this.isDirectory) {
794+
$pathTypeMessage = 'directory'
784795
}
785-
Write-Host "Unable to read $pathType '$($this.response)' - the $pathType may not exist or you may not have permissions to read it - please enter another $pathType path"
796+
Write-Host "Unable to read $pathTypeMessage '$($this.response)' - the $pathTypeMessage may not exist or you may not have permissions to read it - please enter another $pathTypeMessage path"
786797
}
787798
}
788799
}
789800

790801
class CertificateFileQuestion : PathQuestion {
791802

792-
CertificateFileQuestion([string] $promptText, [bool] $allowEmptyResponse) : base($promptText, [microsoft.powershell.commands.testpathtype]::leaf, $allowEmptyResponse) {
803+
CertificateFileQuestion([string] $promptText, [bool] $allowEmptyResponse) : base($promptText, $false, $allowEmptyResponse) {
793804
}
794805

795806
[void]Prompt() {

0 commit comments

Comments
 (0)