summaryrefslogtreecommitdiff
path: root/internal/cli/authkeyflags.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/authkeyflags.go')
-rw-r--r--internal/cli/authkeyflags.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/cli/authkeyflags.go b/internal/cli/authkeyflags.go
new file mode 100644
index 0000000..4c945d3
--- /dev/null
+++ b/internal/cli/authkeyflags.go
@@ -0,0 +1,43 @@
+package cli
+
+import (
+ "flag"
+
+ "github.com/mimecast/dtail/internal/config"
+)
+
+const authKeyPathHelpText = "Path to auth key/private key (defaults to ~/.ssh/id_rsa via config)"
+
+// BindAuthKeyFlags registers the legacy and current auth-key flags.
+func BindAuthKeyFlags(fs *flag.FlagSet, legacyKey *string, args *config.Args) {
+ fs.StringVar(legacyKey, "key", "", "Deprecated alias for -auth-key-path")
+ fs.StringVar(&args.SSHPrivateKeyFilePath, "auth-key-path", "", authKeyPathHelpText)
+}
+
+// FlagWasSet reports whether the named flag was explicitly set on the command line.
+func FlagWasSet(name string) bool {
+ var wasSet bool
+ flag.Visit(func(f *flag.Flag) {
+ if f.Name == name {
+ wasSet = true
+ }
+ })
+ return wasSet
+}
+
+// ApplyAuthKeyPathCompatibility copies the deprecated legacy key into args when
+// the new flag was not explicitly set. If both were set, the new flag wins and
+// a warning message is returned.
+func ApplyAuthKeyPathCompatibility(args *config.Args, legacyKey string, authKeyPathSet bool) string {
+ if authKeyPathSet {
+ if legacyKey != "" {
+ return "WARN: -key is deprecated; ignoring it because -auth-key-path was also set"
+ }
+ return ""
+ }
+
+ if legacyKey != "" {
+ args.SSHPrivateKeyFilePath = legacyKey
+ }
+ return ""
+}