-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathclipboard.go
More file actions
37 lines (30 loc) · 1.13 KB
/
clipboard.go
File metadata and controls
37 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package open
import (
"github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
"github.com/microsoft/go-sqlcmd/internal/config"
"github.com/microsoft/go-sqlcmd/internal/localizer"
"github.com/microsoft/go-sqlcmd/internal/output"
"github.com/microsoft/go-sqlcmd/internal/pal"
)
// copyPasswordToClipboard copies the password for the current context to the clipboard
// if the user is using SQL authentication. Returns true if a password was copied.
func copyPasswordToClipboard(user *sqlconfig.User, out *output.Output) bool {
if user == nil || user.AuthenticationType != "basic" {
return false
}
// Get the decrypted password from the current context
_, _, password := config.GetCurrentContextInfo()
if password == "" {
return false
}
err := pal.CopyToClipboard(password)
if err != nil {
// Don't fail the command if clipboard copy fails, just warn the user
out.Warn(localizer.Sprintf("Could not copy password to clipboard: %s", err.Error()))
return false
}
out.Info(localizer.Sprintf("Password copied to clipboard - paste it when prompted"))
return true
}