forked from toolshed/abra
.gitea
cli
app
catalogue
formatter
internal
command.go
common.go
copy.go
deploy.go
errors.go
errors_test.go
new.go
recipe.go
record.go
server.go
validate.go
recipe
record
server
autocomplete.go
cli.go
upgrade.go
cmd
pkg
scripts
tests
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
Makefile
README.md
go.mod
go.sum
renovate.json
209 lines
4.9 KiB
Go
209 lines
4.9 KiB
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// EnsureServerProvider ensures a 3rd party server provider is chosen.
|
|
func EnsureServerProvider() error {
|
|
if ServerProvider == "" && !NoInput {
|
|
prompt := &survey.Select{
|
|
Message: "Select server provider",
|
|
Options: []string{"capsul", "hetzner-cloud"},
|
|
}
|
|
|
|
if err := survey.AskOne(prompt, &ServerProvider); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if ServerProvider == "" {
|
|
return fmt.Errorf("missing server provider?")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// EnsureNewCapsulVPSFlags ensure all flags are present.
|
|
func EnsureNewCapsulVPSFlags(c *cli.Context) error {
|
|
if CapsulName == "" && !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify capsul name",
|
|
}
|
|
if err := survey.AskOne(prompt, &CapsulName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify capsul instance URL",
|
|
Default: CapsulInstanceURL,
|
|
}
|
|
if err := survey.AskOne(prompt, &CapsulInstanceURL); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify capsul type",
|
|
Default: CapsulType,
|
|
}
|
|
if err := survey.AskOne(prompt, &CapsulType); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify capsul image",
|
|
Default: CapsulImage,
|
|
}
|
|
if err := survey.AskOne(prompt, &CapsulImage); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(CapsulSSHKeys.Value()) == 0 && !NoInput {
|
|
var sshKeys string
|
|
prompt := &survey.Input{
|
|
Message: "specify capsul SSH keys (e.g. me@foo.com)",
|
|
Default: "",
|
|
}
|
|
if err := survey.AskOne(prompt, &CapsulSSHKeys); err != nil {
|
|
return err
|
|
}
|
|
CapsulSSHKeys = *cli.NewStringSlice(strings.Split(sshKeys, ",")...)
|
|
}
|
|
|
|
if CapsulAPIToken == "" && !NoInput {
|
|
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
|
|
}
|
|
}
|
|
|
|
if CapsulName == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing capsul name?"))
|
|
}
|
|
if CapsulInstanceURL == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing capsul instance url?"))
|
|
}
|
|
if CapsulType == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing capsul type?"))
|
|
}
|
|
if CapsulImage == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing capsul image?"))
|
|
}
|
|
if len(CapsulSSHKeys.Value()) == 0 {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing capsul ssh keys?"))
|
|
}
|
|
if CapsulAPIToken == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing capsul API token?"))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// EnsureNewHetznerCloudVPSFlags ensure all flags are present.
|
|
func EnsureNewHetznerCloudVPSFlags(c *cli.Context) error {
|
|
if HetznerCloudName == "" && !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify hetzner cloud VPS name",
|
|
}
|
|
if err := survey.AskOne(prompt, &HetznerCloudName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify hetzner cloud VPS type",
|
|
Default: HetznerCloudType,
|
|
}
|
|
if err := survey.AskOne(prompt, &HetznerCloudType); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify hetzner cloud VPS image",
|
|
Default: HetznerCloudImage,
|
|
}
|
|
if err := survey.AskOne(prompt, &HetznerCloudImage); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(HetznerCloudSSHKeys.Value()) == 0 && !NoInput {
|
|
var sshKeys string
|
|
prompt := &survey.Input{
|
|
Message: "specify hetzner cloud SSH keys (e.g. me@foo.com)",
|
|
Default: "",
|
|
}
|
|
if err := survey.AskOne(prompt, &sshKeys); err != nil {
|
|
return err
|
|
}
|
|
HetznerCloudSSHKeys = *cli.NewStringSlice(strings.Split(sshKeys, ",")...)
|
|
}
|
|
|
|
if !NoInput {
|
|
prompt := &survey.Input{
|
|
Message: "specify hetzner cloud VPS location",
|
|
Default: HetznerCloudLocation,
|
|
}
|
|
if err := survey.AskOne(prompt, &HetznerCloudLocation); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if HetznerCloudAPIToken == "" && !NoInput {
|
|
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
|
|
}
|
|
}
|
|
|
|
if HetznerCloudName == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing hetzner cloud VPS name?"))
|
|
}
|
|
if HetznerCloudType == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing hetzner cloud VPS type?"))
|
|
}
|
|
if HetznerCloudImage == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing hetzner cloud image?"))
|
|
}
|
|
if len(HetznerCloudSSHKeys.Value()) == 0 {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing hetzner cloud ssh keys?"))
|
|
}
|
|
if HetznerCloudLocation == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing hetzner cloud VPS location?"))
|
|
}
|
|
if HetznerCloudAPIToken == "" {
|
|
ShowSubcommandHelpAndError(c, fmt.Errorf("missing hetzner cloud API token?"))
|
|
}
|
|
|
|
return nil
|
|
}
|