aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2023-12-11 21:15:52 +0100
committerGitHub <noreply@github.com>2023-12-11 21:15:52 +0100
commitc53a1f210cde5eb3e2affdd2aa99d73e77691650 (patch)
tree20941207e6ce799d6d768977f764699f3a8b5071
parentb71a930bfc09cad42b7d7447d55af60cf6b3b747 (diff)
downloadsyncthing-c53a1f210cde5eb3e2affdd2aa99d73e77691650.tar.gz
syncthing-c53a1f210cde5eb3e2affdd2aa99d73e77691650.zip
cmd/syncthing: Better cli stdin handling (ref #9166) (#9281)
Seems to work for me, @AudriusButkevicius.
-rw-r--r--cmd/syncthing/cli/main.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/cmd/syncthing/cli/main.go b/cmd/syncthing/cli/main.go
index 01889c694..4d9fb5727 100644
--- a/cmd/syncthing/cli/main.go
+++ b/cmd/syncthing/cli/main.go
@@ -10,7 +10,6 @@ import (
"bufio"
"fmt"
"os"
- "os/exec"
"github.com/alecthomas/kong"
"github.com/flynn-archive/go-shlex"
@@ -75,15 +74,21 @@ func (*stdinCommand) Run() error {
if len(input) == 0 {
continue
}
- cmd := exec.Command(os.Args[0], append(args[1:], input...)...)
- out, err := cmd.CombinedOutput()
- fmt.Print(string(out))
+
+ var cli CLI
+ p, err := kong.New(&cli)
+ if err != nil {
+ // can't happen, really
+ return fmt.Errorf("creating parser: %w", err)
+ }
+ ctx, err := p.Parse(input)
if err != nil {
- if _, ok := err.(*exec.ExitError); ok {
- // we will continue loop no matter the command succeeds or not
- continue
- }
- return err
+ fmt.Println("Error:", err)
+ continue
+ }
+ if err := ctx.Run(); err != nil {
+ fmt.Println("Error:", err)
+ continue
}
}
return scanner.Err()