fix: handle inputs for server new correctly
This commit is contained in:
parent
9a0e12258a
commit
147687d7ce
|
@ -2,6 +2,8 @@ package internal
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -27,7 +29,7 @@ func EnsureServerProvider() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// EnsureCapsulNewFlags ensure all flags are present.
|
||||
// EnsureNewCapsulVPSFlags ensure all flags are present.
|
||||
func EnsureNewCapsulVPSFlags(c *cli.Context) error {
|
||||
if CapsulName == "" && !NoInput {
|
||||
prompt := &survey.Input{
|
||||
|
@ -69,6 +71,7 @@ func EnsureNewCapsulVPSFlags(c *cli.Context) error {
|
|||
}
|
||||
|
||||
if len(CapsulSSHKeys.Value()) == 0 && !NoInput {
|
||||
var sshKeys string
|
||||
prompt := &survey.Input{
|
||||
Message: "specify capsul SSH keys",
|
||||
Default: "me@foo.com,you@bar.com",
|
||||
|
@ -76,14 +79,20 @@ func EnsureNewCapsulVPSFlags(c *cli.Context) error {
|
|||
if err := survey.AskOne(prompt, &CapsulSSHKeys); err != nil {
|
||||
return err
|
||||
}
|
||||
CapsulSSHKeys = *cli.NewStringSlice(strings.Split(sshKeys, ",")...)
|
||||
}
|
||||
|
||||
if CapsulAPIToken == "" && !NoInput {
|
||||
prompt := &survey.Input{
|
||||
Message: "specify capsul API token",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &CapsulAPIToken); err != nil {
|
||||
return err
|
||||
token, ok := os.LookupEnv("CAPSUL_TOKEN")
|
||||
if !ok {
|
||||
prompt := &survey.Input{
|
||||
Message: "specify capsul API token",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &CapsulAPIToken); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
CapsulAPIToken = token
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,13 +150,15 @@ func EnsureNewHetznerCloudVPSFlags(c *cli.Context) error {
|
|||
}
|
||||
|
||||
if len(HetznerCloudSSHKeys.Value()) == 0 && !NoInput {
|
||||
var sshKeys string
|
||||
prompt := &survey.Input{
|
||||
Message: "specify hetzner cloud SSH keys",
|
||||
Default: "me@foo.com,you@bar.com",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &HetznerCloudSSHKeys); err != nil {
|
||||
if err := survey.AskOne(prompt, &sshKeys); err != nil {
|
||||
return err
|
||||
}
|
||||
HetznerCloudSSHKeys = *cli.NewStringSlice(strings.Split(sshKeys, ",")...)
|
||||
}
|
||||
|
||||
if HetznerCloudLocation == "" && !NoInput {
|
||||
|
@ -160,11 +171,16 @@ func EnsureNewHetznerCloudVPSFlags(c *cli.Context) error {
|
|||
}
|
||||
|
||||
if HetznerCloudAPIToken == "" && !NoInput {
|
||||
prompt := &survey.Input{
|
||||
Message: "specify hetzner cloud API token",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &HetznerCloudAPIToken); err != nil {
|
||||
return err
|
||||
token, ok := os.LookupEnv("HCLOUD_TOKEN")
|
||||
if !ok {
|
||||
prompt := &survey.Input{
|
||||
Message: "specify hetzner cloud API token",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &HetznerCloudAPIToken); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
HetznerCloudAPIToken = token
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ func newHetznerCloudVPS(c *cli.Context) error {
|
|||
|
||||
var sshKeysRaw []string
|
||||
var sshKeys []*hcloud.SSHKey
|
||||
for _, sshKey := range c.StringSlice("ssh-keys") {
|
||||
for _, sshKey := range c.StringSlice("hetzner-ssh-keys") {
|
||||
sshKey, _, err := client.SSHKey.GetByName(c.Context, sshKey)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -52,7 +52,7 @@ func newHetznerCloudVPS(c *cli.Context) error {
|
|||
|
||||
response := false
|
||||
prompt := &survey.Confirm{
|
||||
Message: "continue with capsul creation?",
|
||||
Message: "continue with hetzner cloud VPS creation?",
|
||||
}
|
||||
|
||||
if err := survey.AskOne(prompt, &response); err != nil {
|
||||
|
@ -160,6 +160,12 @@ The following providers are supported:
|
|||
You may invoke this command in "wizard" mode and be prompted for input:
|
||||
|
||||
abra record new
|
||||
|
||||
API tokens are read from the environment if specified, e.g.
|
||||
|
||||
export HCLOUD_TOKEN=...
|
||||
|
||||
Where "$provider_TOKEN" is the expected env var format.
|
||||
`,
|
||||
ArgsUsage: "<provider>",
|
||||
Flags: []cli.Flag{
|
||||
|
|
Loading…
Reference in New Issue