use flags for pluginHost
This commit is contained in:
2
main.go
2
main.go
@@ -277,7 +277,7 @@ func (gloom *GLoom) RegisterPlugin(pluginPath string, name string, domains []str
|
|||||||
slog.Debug("Starting pluginHost", "pluginPath", pluginPath)
|
slog.Debug("Starting pluginHost", "pluginPath", pluginPath)
|
||||||
|
|
||||||
processPath := path.Join(gloom.gloomDir, "pluginHost")
|
processPath := path.Join(gloom.gloomDir, "pluginHost")
|
||||||
args := []string{pluginPath, socketPath}
|
args := []string{"--plugin-path", pluginPath, "--socket-path", socketPath}
|
||||||
|
|
||||||
cmd := exec.Command(processPath, args...)
|
cmd := exec.Command(processPath, args...)
|
||||||
stderrPipe, err := cmd.StderrPipe()
|
stderrPipe, err := cmd.StderrPipe()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -15,23 +16,11 @@ import (
|
|||||||
|
|
||||||
var pluginPath string
|
var pluginPath string
|
||||||
var socketPath string
|
var socketPath string
|
||||||
var controlPath string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if len(os.Args) < 3 {
|
|
||||||
fmt.Fprintf(os.Stderr, "Usage: pluginHost <pluginPath> <socketPath> [controlPath]")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginPath = os.Args[1]
|
|
||||||
socketPath = os.Args[2]
|
|
||||||
// Idk why I originally wrote this solution when stderr is literally just the best solution for me, but this
|
// Idk why I originally wrote this solution when stderr is literally just the best solution for me, but this
|
||||||
// makes the pluginHost more generally useful outside of GLoom, so I'm keeping it
|
// makes the pluginHost more generally useful outside of GLoom, so I'm keeping it
|
||||||
// TODO: maybe make it a compiler flag, though I'm sure its not making the binary *that* much bigger
|
// TODO: maybe make it a compiler flag, though I'm sure its not making the binary *that* much bigger
|
||||||
if len(os.Args) > 3 {
|
var controlPath string
|
||||||
controlPath = os.Args[3]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
Init() (*fiber.Config, error)
|
Init() (*fiber.Config, error)
|
||||||
@@ -73,6 +62,32 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
fs := flag.NewFlagSet("pluginHost", flag.ExitOnError)
|
||||||
|
fs.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, "Usage: pluginHost <pluginPath> <socketPath> [controlPath]")
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.StringVar(&pluginPath, "plugin-path", "", "Path to the plugin")
|
||||||
|
fs.StringVar(&socketPath, "socket-path", "", "Path to the socket")
|
||||||
|
fs.StringVar(&controlPath, "control-path", "", "Path to the control socket")
|
||||||
|
|
||||||
|
err := fs.Parse(os.Args[1:])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error parsing arguments: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Args = fs.Args()
|
||||||
|
|
||||||
|
if pluginPath == "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: plugin path not specified")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if socketPath == "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: socket path not specified")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
var Print = func(format string, args ...any) {
|
var Print = func(format string, args ...any) {
|
||||||
fmt.Fprintf(os.Stderr, format, args...)
|
fmt.Fprintf(os.Stderr, format, args...)
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user