Skip to content

Commit

Permalink
Adding support for more than two instances (#5)
Browse files Browse the repository at this point in the history
- Adding support for more than two instances
- Updating manifest for scoop release
  • Loading branch information
Nyuwb authored Nov 3, 2022
1 parent 86110f7 commit df6894c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/Config/Loader.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class Loader
{
[Hashtable] $Instances = @{}
[Array] $Services
[String] $Version = '0.3'
[String] $Version = '0.4'

Loader()
{
Expand All @@ -25,20 +25,20 @@ Class Loader
Return ($This.GetInstances().Keys -Contains $InstanceName)
}

[System.Object] GetByInstanceName([String] $InstanceName)
[Instance] GetByInstanceName([String] $InstanceName)
{
Return $This.GetInstances()[$InstanceName]
}

[System.Object] GetOtherInstanceThan([String] $InstanceName)
[System.Collections.ArrayList] GetOtherInstancesThan([String] $InstanceName)
{
$Instance = $null
$InstanceList = [System.Collections.ArrayList]::New()
$This.GetInstances().Keys | Foreach-Object {
If ($_ -ne $InstanceName) {
$Instance = $This.GetByInstanceName($_)
$InstanceList.Add($This.GetByInstanceName($_))
}
}
Return $Instance
Return $InstanceList
}

# Associate every service together to generate a string that will be used as a regex for the command
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ConfigController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Class ConfigController
}
}
}
If ($InstanceLength -ne 2) {
If ($InstanceLength -le 1) {
Throw 'The instances property is invalid in the configuration'
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/Controller/ServiceController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ Class ServiceController
# Getting instance list config (which should be activated and deactivated)
$InstanceList = @{
'start' = $Config.GetByInstanceName($Hostname)
'stop' = $Config.GetOtherInstanceThan($Hostname)
}

# Verifying the two instances config
If ($InstanceList['start'].GetType() -eq $null -or $InstanceList['stop'] -eq $null) {
Throw 'The instance list configuration didn''t load properly'
'stop' = $Config.GetOtherInstancesThan($Hostname)
}

# Execution of the WSL commands
'stop', 'start' | Foreach-Object {
$Action = $_
[Console]::Write($(If ($Action -eq 'stop') { 'Dea' } else { 'A' }) +'ctivation of the services on the instance '+ $InstanceList[$Action].GetHostname() +"...`n")
$ServiceList -Split ',' | ForEach-Object {
[Command]::Execute($InstanceList[$Action].GetHostname(), $InstanceList[$Action].GetService($_), $Action)
$InstanceList[$Action] | Foreach-Object {
$Instance = $_
[Console]::Write($(If ($Action -eq 'stop') { 'Dea' } else { 'A' }) +'ctivation of the services on the instance '+ $Instance.GetHostname() +"...`n")
$ServiceList -Split ',' | ForEach-Object {
$Service = $_
[Command]::Execute($Instance.GetHostname(), $Instance.GetService($Service), $Action)
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions wsl-switch.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"version": "0.3",
"version": "0.4",
"description": "Switch WSL service activation from an host to another",
"homepage": "https://github.com/Nyuwb/wsl-switch/",
"license": "MIT license",
"url": "https://github.com/Nyuwb/wsl-switch/archive/refs/tags/v0.3.zip",
"hash": "257048dde0cc785aa402feee36131c29a1cab297",
"url": "https://github.com/Nyuwb/wsl-switch/releases/download/v0.4/wsl-switch-v0.4.zip",
"hash": "b6fe2f872092c234d9b388b9f4cfe245443cb69515b1148e61ced2105fa1889e",
"bin": "wsl-switch.ps1",
"persist": "config.json"
}

0 comments on commit df6894c

Please sign in to comment.