diff options
| author | Paul Buetow <git@mx.buetow.org> | 2021-02-05 09:02:14 +0000 |
|---|---|---|
| committer | Paul Buetow <git@mx.buetow.org> | 2021-02-05 09:02:14 +0000 |
| commit | 18a4de2bb288d44c4e5a7560fced7a15e9a6469d (patch) | |
| tree | d7a570ae5e9209a175aecef527e56e69d6879bce /internal/clients/baseclient.go | |
| parent | a40e3c5c01d0b33f23c53eba1276cf244e4d060b (diff) | |
add --max, --before, --after switches to dtail and dgrep commands
Diffstat (limited to 'internal/clients/baseclient.go')
| -rw-r--r-- | internal/clients/baseclient.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/internal/clients/baseclient.go b/internal/clients/baseclient.go index f20156f..0bdd62e 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.LineContext.MaxCount != 0 { + options["max"] = fmt.Sprintf("%d", c.Args.LineContext.MaxCount) + } + if c.Args.LineContext.BeforeContext != 0 { + options["before"] = fmt.Sprintf("%d", c.Args.LineContext.BeforeContext) + } + if c.Args.LineContext.AfterContext != 0 { + options["after"] = fmt.Sprintf("%d", c.Args.LineContext.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 } |
