Skip to content

Commit

Permalink
improve: refactore code
Browse files Browse the repository at this point in the history
  • Loading branch information
lupinthe14th committed Jan 16, 2021
1 parent 0aae8ad commit 24bd919
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ var searchCommand = &cli.Command{
Usage: "Show match all",
},
&cli.StringFlag{
Name: "query",
Name: "filename",
Value: "",
Aliases: []string{"q"},
Aliases: []string{"f"},
Usage: "Specify query json file",
},
&cli.StringFlag{
Expand Down Expand Up @@ -279,7 +279,7 @@ func trimNextEqual(s string) string {
}

func buildQuery(c *cli.Context) (io.Reader, error) {
filename := c.String("query")
filename := c.String("filename")
log.Debug().Msgf("filename: %s", filename)
since := c.Timestamp("since").Format(time.RFC3339Nano)
log.Debug().Msgf("since: %s", since)
Expand Down
10 changes: 5 additions & 5 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ func TestBuildQuery(t *testing.T) {
t.Run(fmt.Sprint(i), func(t *testing.T) {
t.Parallel()
flags := []cli.Flag{
&cli.StringFlag{Name: "query", Aliases: []string{"q"}},
&cli.StringFlag{Name: "rule", Aliases: []string{"r"}},
&cli.TimestampFlag{Name: "since", Aliases: []string{"s"}, Layout: "2006-01-02 15:04:05"},
&cli.TimestampFlag{Name: "until", Aliases: []string{"u"}, Layout: "2006-01-02 15:04:05"},
&cli.StringFlag{Name: "filename"},
&cli.StringFlag{Name: "rule"},
&cli.TimestampFlag{Name: "since", Layout: "2006-01-02 15:04:05"},
&cli.TimestampFlag{Name: "until", Layout: "2006-01-02 15:04:05"},
}
set := flag.NewFlagSet("test", 0)
for _, fl := range flags {
_ = fl.Apply(set)
}
set.Parse([]string{"--query", tt.in.filename, "--rule", tt.in.rule, "--since", tt.in.since, "--until", tt.in.until})
set.Parse([]string{"--filename", tt.in.filename, "--rule", tt.in.rule, "--since", tt.in.since, "--until", tt.in.until})
c := cli.NewContext(nil, set, nil)
got, err := buildQuery(c)
if (err != nil) != tt.wantErr {
Expand Down

0 comments on commit 24bd919

Please sign in to comment.