diff options
Diffstat (limited to 'internal/clients/args.go')
| -rw-r--r-- | internal/clients/args.go | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/internal/clients/args.go b/internal/clients/args.go index 7f782f1..7ce1634 100644 --- a/internal/clients/args.go +++ b/internal/clients/args.go @@ -1,6 +1,13 @@ package clients import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/io/logger" "github.com/mimecast/dtail/internal/omode" gossh "golang.org/x/crypto/ssh" @@ -22,5 +29,42 @@ type Args struct { SSHAuthMethods []gossh.AuthMethod SSHHostKeyCallback gossh.HostKeyCallback PrivateKeyPathFile string - Quiet bool + Quiet bool +} + +// When no servers are given, connect to localhost! +func (a *Args) handleEmptyServer() { + if a.Discovery != "" || a.ServersStr != "" { + return + } + + fqdn, err := os.Hostname() + if err != nil { + logger.FatalExit(err) + } + a.ServersStr = fmt.Sprintf("%s:%d", fqdn, config.Common.SSHPort) + // I am trusting my own hostname. + a.TrustAllHosts = true + logger.Debug("Will connect to local server", a.ServersStr) + + cleanPath := func(dirtyPath string) string { + cleanPath, err := filepath.EvalSymlinks(dirtyPath) + if err != nil { + logger.FatalExit("Unable to evaluate symlinks", dirtyPath, err) + } + cleanPath, err = filepath.Abs(cleanPath) + if err != nil { + logger.FatalExit("Unable to make file path absolute", dirtyPath, cleanPath, err) + } + return cleanPath + } + + logger.Debug("Dirty file paths", a.What) + var filePaths []string + for _, dirtyPath := range strings.Split(a.What, ",") { + filePaths = append(filePaths, cleanPath(dirtyPath)) + } + + a.What = strings.Join(filePaths, ",") + logger.Debug("Clean file paths", a.What) } |
