summaryrefslogtreecommitdiff
path: root/internal/clients/baseclient.go
diff options
context:
space:
mode:
authorPaul Buetow <35781042+pbuetow@users.noreply.github.com>2021-03-29 17:49:16 +0100
committerGitHub <noreply@github.com>2021-03-29 17:49:16 +0100
commit9a467da883976c74d231ea9c7773430f583bab98 (patch)
tree4e75a996ef44bc5adc771c318753b0c4ad934269 /internal/clients/baseclient.go
parente811d1725ee5f931ece6fac01db70227b0fc8a7a (diff)
parent93fce245564ffde20c3e5113757bc65672f69ed5 (diff)
Merge pull request #22 from snonux/develop
Add context awareness to dgrep
Diffstat (limited to 'internal/clients/baseclient.go')
-rw-r--r--internal/clients/baseclient.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/internal/clients/baseclient.go b/internal/clients/baseclient.go
index f20156f..f83fcfd 100644
--- a/internal/clients/baseclient.go
+++ b/internal/clients/baseclient.go
@@ -2,6 +2,8 @@ package clients
import (
"context"
+ "fmt"
+ "strings"
"sync"
"time"
@@ -118,10 +120,44 @@ func (c *baseClient) start(ctx context.Context, active chan struct{}, i int, con
}
}
+func (c *baseClient) makeCommandOptions() map[string]string {
+ options := make(map[string]string)
+
+ if c.Args.Quiet {
+ options["quiet"] = fmt.Sprintf("%v", c.Args.Quiet)
+ }
+ if c.Args.LContext.MaxCount != 0 {
+ options["max"] = fmt.Sprintf("%d", c.Args.LContext.MaxCount)
+ }
+ if c.Args.LContext.BeforeContext != 0 {
+ options["before"] = fmt.Sprintf("%d", c.Args.LContext.BeforeContext)
+ }
+ if c.Args.LContext.AfterContext != 0 {
+ options["after"] = fmt.Sprintf("%d", c.Args.LContext.AfterContext)
+ }
+
+ return options
+}
+
+func (c *baseClient) commandOptionsToString(options map[string]string) string {
+ var sb strings.Builder
+
+ count := 0
+ for k, v := range options {
+ if count > 0 {
+ sb.WriteString(":")
+ }
+ sb.WriteString(fmt.Sprintf("%s=%s", k, v))
+ count++
+ }
+
+ return sb.String()
+}
+
func (c *baseClient) makeConnection(server string, sshAuthMethods []gossh.AuthMethod, hostKeyCallback client.HostKeyCallback) *remote.Connection {
conn := remote.NewConnection(server, c.UserName, sshAuthMethods, hostKeyCallback)
conn.Handler = c.maker.makeHandler(server)
- conn.Commands = c.maker.makeCommands()
+ conn.Commands = c.maker.makeCommands(c.makeCommandOptions())
return conn
}