Skip to content

Commit

Permalink
Added a "all" command to switch all services at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyuwb committed Aug 1, 2023
1 parent 80800cc commit 0b5f5aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.7.0

- Added a "all" parameter to switch all configured services at once
- Fixed an unintended new line when switching services

# v0.6.1

- Fixed loading of config.json in the builded app
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The following services are currently managed, but you can custom it in the `conf
Add the bucket [scoop-srsrns](https://github.com/mbl-35/scoop-srsrns).
Then install it directly from this bucket:

```
```bash
scoop bucket add srsrns https://github.com/mbl-35/scoop-srsrns
scoop install wsl-switch
```
Expand All @@ -30,7 +30,7 @@ Download the latest build from [GitHub](https://github.com/Nyuwb/wsl-switch/rele

Unzip it then add the path to the ps1 file in your Powershell profile:

```
```bash
Invoke-Item $Profile
# Set-Alias wsl-switch _path_to_repository_\wsl-switch.ps1
```
Expand All @@ -39,7 +39,7 @@ Invoke-Item $Profile

You need to run the following command to edit the configuration file.

```
```bash
wsl-switch config
```

Expand All @@ -50,11 +50,12 @@ Save it, and it will direcly be used by the application.

To enable the service `$service` on `$hostname`, you'll need to type the following command:

```
```bash
wsl-switch $service $hostname
```

The `$hostname` parameter is the `key` stored in the `config.json`.
The `$hostname` parameter is the `key` stored in the `config.json`.
You can switch all configured services at once by using the parameter `all` instead of `$service`.

## Tips: How to install multiple instances

Expand Down
11 changes: 10 additions & 1 deletion src/Controller/AppController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Using Module '..\Utils\Console.psm1'

Class AppController
{
Static [String] $Version = '0.6.1'
Static [String] $Version = '0.7.0'

[Void] Static Run([String[]] $Arguments)
{
Expand All @@ -25,6 +25,15 @@ Class AppController
$Regex = '^('+ $Config.FormatServicesToString() +')$'
# Getting command from first argument
Switch -Regex ($Command) {
'^all$' {
# Checking instance name
$InstanceName = $Arguments[1]
If ($Config.InstanceExists($InstanceName) -ne $True) {
Throw ('The instance '''+ $InstanceName +''' doesn''t exist')
}
# Execute
[ServiceController]::Execute($Config, $InstanceName, $Config.GetServices() -Join ',')
}
'^build$' {
# Building app in single file (to avoid Powershell "Using module" problems)
if ([AppController]::IsBuildedApp() -eq $True) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/HelpController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Class HelpController
[Console]::Write(" php baz`t`t`tActivate php on baz`n")
[Console]::Write("The services can be written comma-separated to enable them together, for example:")
[Console]::Write(" apache,php foo`t`tActivate apache and php on foo")
[Console]::Write(" apache,mysql,php bar`t`tActivate apache, mysql and php on bar`n")
[Console]::Write(" all bar`t`tActivate all services on bar`n")
}
}
2 changes: 1 addition & 1 deletion src/Controller/ServiceController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Class ServiceController
$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")
[Console]::Write($(If ($Action -eq 'Stop') { 'Dea' } else { 'A' }) +'ctivation of the services on the instance '+ $Instance.GetHostname() +"...")
$ServiceList -Split ',' | ForEach-Object {
$Service = $_
[Command]::$Action($Instance.GetHostname(), $Instance.GetService($Service))
Expand Down

0 comments on commit 0b5f5aa

Please sign in to comment.