aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2018-02-24 14:49:11 +0100
committerMartin Polden <mpolden@mpolden.no>2018-02-24 14:49:11 +0100
commit3451be7043da054fffa681a52124651b49e291d7 (patch)
tree774e9f0860796517a370f23f0d0097e4fa84214d
parent905a1be5c2e87bb8fbc1e6ab3a266149e173d74f (diff)
Write info to stderr
-rw-r--r--cmd/lftpq/main.go14
-rw-r--r--cmd/lftpq/main_test.go3
2 files changed, 10 insertions, 7 deletions
diff --git a/cmd/lftpq/main.go b/cmd/lftpq/main.go
index 52f6230..cca2576 100644
--- a/cmd/lftpq/main.go
+++ b/cmd/lftpq/main.go
@@ -25,7 +25,8 @@ type CLI struct {
LftpPath string `short:"p" long:"lftp" description:"Path to lftp program" value-name:"NAME" default:"lftp"`
consumer queue.Consumer
lister lister
- wr io.Writer
+ stderr io.Writer
+ stdout io.Writer
rd io.Reader
}
@@ -39,7 +40,7 @@ func (c *CLI) Run() error {
if err != nil {
return err
}
- fmt.Fprintf(c.wr, "%s\n", json)
+ fmt.Fprintf(c.stdout, "%s\n", json)
return nil
}
var queues []queue.Queue
@@ -70,8 +71,8 @@ func (c *CLI) printf(format string, vs ...interface{}) {
}
}
if !c.Quiet || alwaysPrint {
- fmt.Fprint(c.wr, "lftpq: ")
- fmt.Fprintf(c.wr, format, vs...)
+ fmt.Fprint(c.stderr, "lftpq: ")
+ fmt.Fprintf(c.stderr, format, vs...)
}
}
@@ -110,7 +111,7 @@ func (c *CLI) transfer(q queue.Queue) error {
out, err = q.MarshalText()
}
if err == nil {
- fmt.Fprintf(c.wr, "%s", out)
+ fmt.Fprintf(c.stdout, "%s", out)
}
return err
}
@@ -137,7 +138,8 @@ func main() {
if err != nil {
os.Exit(1)
}
- cli.wr = os.Stdout
+ cli.stderr = os.Stderr
+ cli.stdout = os.Stdout
cli.rd = os.Stdin
client := lftp.Client{Path: cli.LftpPath, InheritIO: !cli.Quiet}
cli.lister = &client
diff --git a/cmd/lftpq/main_test.go b/cmd/lftpq/main_test.go
index 0a69a89..27840f7 100644
--- a/cmd/lftpq/main_test.go
+++ b/cmd/lftpq/main_test.go
@@ -66,7 +66,8 @@ func newTestCLI(config string) (*CLI, *bytes.Buffer) {
client := testClient{consumeQueue: false}
return &CLI{
Config: name,
- wr: &buf,
+ stderr: &buf,
+ stdout: &buf,
consumer: &client,
lister: &client,
}, &buf