diff options
| author | Paul Buetow <35781042+pbuetow@users.noreply.github.com> | 2021-03-29 17:49:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-29 17:49:16 +0100 |
| commit | 9a467da883976c74d231ea9c7773430f583bab98 (patch) | |
| tree | 4e75a996ef44bc5adc771c318753b0c4ad934269 /cmd | |
| parent | e811d1725ee5f931ece6fac01db70227b0fc8a7a (diff) | |
| parent | 93fce245564ffde20c3e5113757bc65672f69ed5 (diff) | |
Merge pull request #22 from snonux/develop
Add context awareness to dgrep
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/dgrep/main.go | 15 | ||||
| -rw-r--r-- | cmd/dtail/main.go | 9 |
2 files changed, 17 insertions, 7 deletions
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go index 4da1bb3..123d061 100644 --- a/cmd/dgrep/main.go +++ b/cmd/dgrep/main.go @@ -36,15 +36,24 @@ func main() { flag.IntVar(&sshPort, "port", 2222, "SSH server port") flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method") flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key") - flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression") flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect") flag.StringVar(&args.UserName, "user", userName, "Your system user name") flag.StringVar(&args.What, "files", "", "File(s) to read") flag.StringVar(&cfgFile, "cfg", "", "Config file path") + + // Line context awareness. + flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression") flag.StringVar(&grep, "grep", "", "Alias for -regex") + 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 @@ -58,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 f2a039f..2639b4b 100644 --- a/cmd/dtail/main.go +++ b/cmd/dtail/main.go @@ -50,14 +50,19 @@ func main() { flag.IntVar(&sshPort, "port", 2222, "SSH server port") flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method") flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key") - flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression") flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect") flag.StringVar(&args.UserName, "user", userName, "Your system user name") flag.StringVar(&args.What, "files", "", "File(s) to read") flag.StringVar(&cfgFile, "cfg", "", "Config file path") - flag.StringVar(&grep, "grep", "", "Alias for -regex") flag.StringVar(&queryStr, "query", "", "Map reduce query") + // Line context awareness. + flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression") + flag.StringVar(&grep, "grep", "", "Alias for -regex") + 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 != "" { |
