arblant
firefox-vpn-client / core / cmd / firefox-vpn-tun / commands_windows.go
commands_windows.go41 lines · 858 B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
package main

import (
	"errors"
	"strconv"

	"github.com/armanlife/firefox-vpn-client/core/internal/tunservice"
)

// runPlatform runs the commands an update and an uninstall from inside the
// service leave behind: "restart-service" and "cleanup".
func runPlatform(command string, args []string) int {
	switch command {
	case "restart-service":
		pid, err := pidArg(args)
		if err != nil {
			return exitUsage
		}
		if err := tunservice.RestartService(pid); err != nil {
			return fail(err)
		}
	case "cleanup":
		pid, err := pidArg(args)
		if err != nil || len(args) != 2 {
			return exitUsage
		}
		if err := tunservice.Cleanup(pid, args[1]); err != nil {
			return fail(err)
		}
	default:
		usage()
	}
	return 0
}

func pidArg(args []string) (int, error) {
	if len(args) == 0 {
		return 0, errors.New("no process id")
	}
	return strconv.Atoi(args[0])
}