diff options
| -rw-r--r-- | cmd/dgrep/main.go | 18 | ||||
| -rw-r--r-- | cmd/dtail/main.go | 10 | ||||
| -rw-r--r-- | internal/clients/args.go | 12 | ||||
| -rw-r--r-- | internal/clients/baseclient.go | 12 | ||||
| -rw-r--r-- | internal/lcontext/lcontext.go | 8 |
5 files changed, 31 insertions, 29 deletions
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go index 4a6790b..123d061 100644 --- a/cmd/dgrep/main.go +++ b/cmd/dgrep/main.go @@ -41,15 +41,19 @@ func main() { flag.StringVar(&args.What, "files", "", "File(s) to read") flag.StringVar(&cfgFile, "cfg", "", "Config file path") - // Context awareness. - flag.StringVar(&args.LineContext.RegexStr, "regex", ".", "Regular expression") + // Line context awareness. + flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression") flag.StringVar(&grep, "grep", "", "Alias for -regex") - flag.IntVar(&args.LineContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines") - flag.IntVar(&args.LineContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines") - flag.IntVar(&args.LineContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines") + flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines") + flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines") + flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines") flag.Parse() + if grep != "" { + args.RegexStr = grep + } + config.Read(cfgFile, sshPort) color.Colored = !noColor @@ -63,10 +67,6 @@ func main() { Quiet: args.Quiet, }) - if grep != "" { - args.RegexStr = grep - } - client, err := clients.NewGrepClient(args) if err != nil { panic(err) diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go index 1930483..2639b4b 100644 --- a/cmd/dtail/main.go +++ b/cmd/dtail/main.go @@ -56,12 +56,12 @@ func main() { flag.StringVar(&cfgFile, "cfg", "", "Config file path") flag.StringVar(&queryStr, "query", "", "Map reduce query") - // Context awareness. - flag.StringVar(&args.LineContext.RegexStr, "regex", ".", "Regular expression") + // Line context awareness. + flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression") flag.StringVar(&grep, "grep", "", "Alias for -regex") - flag.IntVar(&args.LineContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines") - flag.IntVar(&args.LineContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines") - flag.IntVar(&args.LineContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines") + flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines") + flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines") + flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines") flag.Parse() diff --git a/internal/clients/args.go b/internal/clients/args.go index 67d2044..684dadd 100644 --- a/internal/clients/args.go +++ b/internal/clients/args.go @@ -1,22 +1,16 @@ package clients import ( + "github.com/mimecast/dtail/internal/lcontext" "github.com/mimecast/dtail/internal/omode" gossh "golang.org/x/crypto/ssh" ) -// LineContext is here to help filtering out only specific lines. -type LineContext struct { - RegexStr string - AfterContext int - BeforeContext int - MaxCount int -} - // Args is a helper struct to summarize common client arguments. type Args struct { - LineContext + lcontext.LContext + RegexStr string Mode omode.Mode ServersStr string UserName string diff --git a/internal/clients/baseclient.go b/internal/clients/baseclient.go index 0bdd62e..f83fcfd 100644 --- a/internal/clients/baseclient.go +++ b/internal/clients/baseclient.go @@ -126,14 +126,14 @@ func (c *baseClient) makeCommandOptions() map[string]string { if c.Args.Quiet { options["quiet"] = fmt.Sprintf("%v", c.Args.Quiet) } - if c.Args.LineContext.MaxCount != 0 { - options["max"] = fmt.Sprintf("%d", c.Args.LineContext.MaxCount) + if c.Args.LContext.MaxCount != 0 { + options["max"] = fmt.Sprintf("%d", c.Args.LContext.MaxCount) } - if c.Args.LineContext.BeforeContext != 0 { - options["before"] = fmt.Sprintf("%d", c.Args.LineContext.BeforeContext) + if c.Args.LContext.BeforeContext != 0 { + options["before"] = fmt.Sprintf("%d", c.Args.LContext.BeforeContext) } - if c.Args.LineContext.AfterContext != 0 { - options["after"] = fmt.Sprintf("%d", c.Args.LineContext.AfterContext) + if c.Args.LContext.AfterContext != 0 { + options["after"] = fmt.Sprintf("%d", c.Args.LContext.AfterContext) } return options diff --git a/internal/lcontext/lcontext.go b/internal/lcontext/lcontext.go new file mode 100644 index 0000000..bd51d94 --- /dev/null +++ b/internal/lcontext/lcontext.go @@ -0,0 +1,8 @@ +package lcontext + +// LContext stands for line context and is here to help filtering out only specific lines. +type LContext struct { + AfterContext int + BeforeContext int + MaxCount int +} |
