From e1af699dc11a47ee8dedb015052c8c0f73a7bc14 Mon Sep 17 00:00:00 2001 From: koluku Date: Fri, 26 Apr 2024 09:29:58 +0000 Subject: [PATCH] remove: output option this option doesn't work. and i won't intend to maintain it. --- cmd/s3s/main.go | 17 ----------------- s3s.go | 22 ++-------------------- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/cmd/s3s/main.go b/cmd/s3s/main.go index acc5d07..dfb4cf0 100644 --- a/cmd/s3s/main.go +++ b/cmd/s3s/main.go @@ -6,7 +6,6 @@ import ( "log" "os" "os/signal" - "path/filepath" "time" "github.com/dustin/go-humanize" @@ -35,8 +34,6 @@ var ( until time.Time cliUntil cli.Timestamp - output string - // command option isDelve bool isDebug bool @@ -119,12 +116,6 @@ func main() { Timezone: time.UTC, Destination: &cliUntil, }, - &cli.StringFlag{ - Category: "Output:", - Name: "output", - Aliases: []string{"o"}, - Destination: &output, - }, &cli.BoolFlag{ Category: "Run:", Name: "delve", @@ -204,13 +195,6 @@ func cmd(ctx context.Context, paths []string) error { if queryStr == "" { queryStr = buildQuery(where, limit, isCount, isALBLogs, isCFLogs) } - var outputPath string - if output != "" { - outputPath, err = filepath.Abs(output) - if err != nil { - return errors.WithStack(err) - } - } var query *s3s.Query switch { @@ -252,7 +236,6 @@ func cmd(ctx context.Context, paths []string) error { option := &s3s.Option{ IsDryRun: isDryRun, IsCountMode: isCount, - Output: outputPath, } result, err := app.Run(ctx, paths, query, option) diff --git a/s3s.go b/s3s.go index 056ac94..1019cc1 100644 --- a/s3s.go +++ b/s3s.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/url" - "os" "strings" "time" @@ -37,7 +36,6 @@ type Query struct { type Option struct { IsDryRun bool IsCountMode bool - Output string } type Client struct { @@ -117,7 +115,7 @@ func (c *Client) Run(ctx context.Context, prefixes []string, query *Query, optio if !option.IsDryRun { eg.Go(func() error { - if err := c.writeOutput(egctx, jsonCH, option); err != nil { + if err := c.writeOutput(egctx, jsonCH); err != nil { return errors.WithStack(err) } return nil @@ -209,17 +207,7 @@ LOOP: return nil } -func (c *Client) writeOutput(ctx context.Context, out <-chan []byte, option *Option) error { - var file *os.File - if option.Output != "" { - f, err := os.OpenFile(option.Output, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_APPEND, 0666) - if err != nil { - return errors.WithStack(err) - } - file = f - defer file.Close() - } - +func (c *Client) writeOutput(ctx context.Context, out <-chan []byte) error { for { select { case json, ok := <-out: @@ -228,12 +216,6 @@ func (c *Client) writeOutput(ctx context.Context, out <-chan []byte, option *Opt } fmt.Println(string(json)) - - if file != nil { - if _, err := file.WriteString(string(json) + "\n"); err != nil { - return errors.WithStack(err) - } - } case <-ctx.Done(): return nil }