Skip to content

Commit 8af3d3a

Browse files
committed
Added option to accept defaults to "autoscan"
1 parent f389dcd commit 8af3d3a

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/jenv-add.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Invoke-Add {
2626
# Check if name is already used
2727
foreach ($jenv in $config.jenvs) {
2828
if ($jenv.name -eq $name) {
29-
Write-Output 'Theres already a JEnv with that name. Consider using "jenv list"'
29+
Write-Output "Theres already a JEnv with the name $name. Consider using ""jenv list"""
3030
return
3131
}
3232
}

src/jenv-autoscan.psm1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ function Invoke-AutoScan {
22
param (
33
[Parameter(Mandatory = $true)][object]$config,
44
[Parameter(Mandatory = $true)][boolean]$help,
5+
[Parameter(Mandatory = $true)][boolean]$acceptDefaults,
56
[string]$path
67
)
78

@@ -48,12 +49,16 @@ function Invoke-AutoScan {
4849
# Ask user if java.exe should be added to the list
4950
foreach ($java in $javaExecutables) {
5051
$version = Get-JavaVersion $java
51-
switch (Open-Prompt "JEnv autoscan" ("Found java.exe at {0}. Default name is: '{1}'. Do you want to add it to the list?" -f $java, $version) "Yes", "No", "Rename" ("This will add {0} with alias '{1}' to JEnv" -f $java, $version), ("Skip {0}" -f $java), "Change the default name" 1) {
52-
0 {
53-
Invoke-Add $config $false $version ($java -replace "\\bin\\java\.exe$", "")
54-
}
55-
2 {
56-
Invoke-Add $config $false (Read-Host ("Enter the new name for {0}" -f $java)) ($java -replace "\\bin\\java\.exe$", "")
52+
if ($acceptDefaults) {
53+
Invoke-Add $config $false $version ($java -replace "\\bin\\java\.exe$", "")
54+
} else {
55+
switch (Open-Prompt "JEnv autoscan" ("Found java.exe at {0}. Default name is: '{1}'. Do you want to add it to the list?" -f $java, $version) "Yes", "No", "Rename" ("This will add {0} with alias '{1}' to JEnv" -f $java, $version), ("Skip {0}" -f $java), "Change the default name" 1) {
56+
0 {
57+
Invoke-Add $config $false $version ($java -replace "\\bin\\java\.exe$", "")
58+
}
59+
2 {
60+
Invoke-Add $config $false (Read-Host ("Enter the new name for {0}" -f $java)) ($java -replace "\\bin\\java\.exe$", "")
61+
}
5762
}
5863
}
5964
}

src/jenv.ps1

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ param (
2828
[Alias("o")]
2929
[Switch]$output,
3030

31+
# Accept defaults
32+
[Alias("y")]
33+
[Switch]$yes,
34+
3135
[parameter(mandatory = $false, position = 1, ValueFromRemainingArguments = $true)]$arguments
3236
)
3337

@@ -121,15 +125,15 @@ if ($output) {
121125
#endregion
122126

123127
if ($help -and $action -eq "") {
124-
Write-Host '"jenv list" List all registered Java-Envs.'
125-
Write-Host '"jenv add <name> <path>" Adds a new Java-Version to JEnv which can be refferenced by the given name'
126-
Write-Host '"jenv remove <name>" Removes the specified Java-Version from JEnv'
127-
Write-Host '"jenv change <name>" Applys the given Java-Version globaly for all restarted shells and this one'
128-
Write-Host '"jenv use <name>" Applys the given Java-Version locally for the current shell'
129-
Write-Host '"jenv local <name>" Will use the given Java-Version whenever in this folder. Will set the Java-version for all subfolders as well'
130-
Write-Host '"jenv link <executable>" Creates shortcuts for executables inside JAVA_HOME. For example "javac"'
131-
Write-Host '"jenv uninstall <name>" Deletes JEnv and restores the specified java version to the system. You may keep your config file'
132-
Write-Host '"jenv autoscan ?<path>?" Will scan the given path for java installations and ask to add them to JEnv. Path is optional'
128+
Write-Host '"jenv list" List all registered Java-Envs.'
129+
Write-Host '"jenv add <name> <path>" Adds a new Java-Version to JEnv which can be refferenced by the given name'
130+
Write-Host '"jenv remove <name>" Removes the specified Java-Version from JEnv'
131+
Write-Host '"jenv change <name>" Applys the given Java-Version globaly for all restarted shells and this one'
132+
Write-Host '"jenv use <name>" Applys the given Java-Version locally for the current shell'
133+
Write-Host '"jenv local <name>" Will use the given Java-Version whenever in this folder. Will set the Java-version for all subfolders as well'
134+
Write-Host '"jenv link <executable>" Creates shortcuts for executables inside JAVA_HOME. For example "javac"'
135+
Write-Host '"jenv uninstall <name>" Deletes JEnv and restores the specified java version to the system. You may keep your config file'
136+
Write-Host '"jenv autoscan [--yes|-y] ?<path>?" Will scan the given path for java installations and ask to add them to JEnv. Path is optional and "--yes|-y" accepts defaults.'
133137
Write-Host 'Get help for individual commands using "jenv <list/add/remove/change/use/local> --help"'
134138
}
135139
else {
@@ -146,7 +150,7 @@ else {
146150
getjava { Get-Java $config }
147151
link { Invoke-Link $help @arguments }
148152
uninstall { Invoke-Uninstall $config $help @arguments }
149-
autoscan { Invoke-AutoScan $config $help @arguments }
153+
autoscan { Invoke-AutoScan $config $help $yes @arguments }
150154
}
151155

152156
#region Save the config

0 commit comments

Comments
 (0)