Skip to content

Commit

Permalink
argument binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Naegler committed Nov 29, 2019
1 parent 1442285 commit d432f19
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/test-example-service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $serviceName = "ExampleService-" + (New-Guid)

$serviceLogDirecotry = "$PSScriptRoot/log"
$serviceCommand = $currentPwshExe
$serviceArguments = "$PSScriptRoot/test-service.ps1 -Message 'TestMessage with space!'"
$serviceArguments = "$PSScriptRoot/test-service.ps1 -Message 'TestMessage with space!' -PathVar bind:PATH"

$serviceBinPath = 'P:\projects\service-wrapper\main.exe'
$serviceBinPath += ' -logdir "' + $serviceLogDirecotry + '"'
Expand Down
5 changes: 4 additions & 1 deletion example/test-service.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
param(
[string]$Message
[string]$Message,
[string]$PathVar
)

Write-Host "PATH: $PathVar"

$i = 0
while($true) {
Start-Sleep(1)
Expand Down
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import (
"flag"
"fmt"
"log"
"os"
"strings"

"github.com/bioapfelsaft/service-wrapper/service"
"golang.org/x/sys/windows/svc"
)

// #todo config
// #todo config ?
// 1. -bind:NAME -> -NAME <Value>
// 2. -NAME cfg:VALUE_NAME -> -NAME <Value>

// wrapper.exe -cfg-file test.yaml
// $env:NAME="123" + binding

// load order
// 1. config file
// 2. environment
// 3. wrapper.exe -arguments "..."

func parseCommandLine(commandArgs string) ([]string, error) {
args := []string{}
Expand Down Expand Up @@ -61,11 +73,19 @@ func main() {

flag.Parse()

//
args, err := parseCommandLine(*arguments)
if err != nil {
log.Fatalf("invalid arguments: %v", err)
}

//
for i := 0; i < len(args); i++ {
if strings.HasPrefix(args[i], "bind:") {
args[i] = os.Getenv(strings.TrimLeft(args[i], "bind:"))
}
}

//
isAnInteractiveSession, err := svc.IsAnInteractiveSession()
if err != nil {
Expand Down

0 comments on commit d432f19

Please sign in to comment.