zenity/pwd_unix.go

32 lines
682 B
Go
Raw Permalink Normal View History

2021-05-05 19:38:49 -04:00
// +build !windows,!darwin
2021-04-08 20:26:57 -04:00
package zenity
import (
2021-07-29 11:20:50 -04:00
"os/exec"
2021-04-08 20:26:57 -04:00
"strings"
"github.com/ncruces/zenity/internal/zenutil"
)
2021-04-29 11:05:28 -04:00
func password(opts options) (string, string, error) {
2021-04-08 20:26:57 -04:00
args := []string{"--password"}
args = appendTitle(args, opts)
args = appendButtons(args, opts)
if opts.username {
args = append(args, "--username")
}
out, err := zenutil.Run(opts.ctx, args)
2021-04-29 11:05:28 -04:00
str, err := strResult(opts, out, err)
2021-07-29 11:20:50 -04:00
if opts.username {
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 255 {
return "", "", ErrUnsupported
}
if split := strings.SplitN(str, "|", 2); err == nil && len(split) == 2 {
2021-04-29 11:05:28 -04:00
return split[0], split[1], nil
2021-04-08 20:26:57 -04:00
}
}
2021-04-29 11:05:28 -04:00
return "", str, err
2021-04-08 20:26:57 -04:00
}