Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove: output option #197

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions cmd/s3s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"
"os/signal"
"path/filepath"
"time"

"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -35,8 +34,6 @@ var (
until time.Time
cliUntil cli.Timestamp

output string

// command option
isDelve bool
isDebug bool
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 2 additions & 20 deletions s3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/url"
"os"
"strings"
"time"

Expand Down Expand Up @@ -37,7 +36,6 @@ type Query struct {
type Option struct {
IsDryRun bool
IsCountMode bool
Output string
}

type Client struct {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
}
Expand Down
Loading