Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/url"
"os"
"time"

"fmt"
"golang.org/x/term"
"strings"
"github.com/erikgeiser/promptkit/confirmation"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/flavors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -83,6 +85,22 @@ var rootCmd = &cobra.Command{
log.SetLevel(log.DebugLevel)
}

if password == "" {
if !term.IsTerminal(int(os.Stdin.Fd())) {
return fmt.Errorf("password is required but terminal is not interactive; please provide --vmware-password flag")
}
fmt.Print("Enter VMware Password: ")

// ReadPassword hides the user's typing for security
bytePassword, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading password: %v\n", err)
return err
}
password = strings.TrimSpace(string(bytePassword))
fmt.Println() // Add a newline since ReadPassword doesn't print one
}

endpointUrl := &url.URL{
Scheme: "https",
Host: endpoint,
Expand Down Expand Up @@ -335,7 +353,6 @@ func init() {
rootCmd.MarkPersistentFlagRequired("vmware-username")

rootCmd.PersistentFlags().StringVar(&password, "vmware-password", "", "VMware password")
rootCmd.MarkPersistentFlagRequired("vmware-password")

rootCmd.PersistentFlags().StringVar(&path, "vmware-path", "", "VMware VM path (e.g. '/Datacenter/vm/VM')")
rootCmd.MarkPersistentFlagRequired("vmware-path")
Expand Down