From 57ef352b3c6fe6e18368bc80dc8e61b4c2e15fac Mon Sep 17 00:00:00 2001 From: Stefan Benten Date: Tue, 25 Jun 2019 20:25:31 +0200 Subject: [PATCH] Update Wizard to allow more easily addition of satellites and move package to cmd folder (#2340) --- cmd/gateway/main.go | 7 +++--- .../utils.go => cmd/internal/wizard/wizard.go | 25 +++++++++++++------ cmd/uplink/cmd/setup.go | 7 +++--- 3 files changed, 25 insertions(+), 14 deletions(-) rename pkg/cfgstruct/utils.go => cmd/internal/wizard/wizard.go (91%) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 061bf26ef..034751b5c 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -18,6 +18,7 @@ import ( "github.com/zeebo/errs" "go.uber.org/zap" + "storj.io/storj/cmd/internal/wizard" "storj.io/storj/internal/fpath" libuplink "storj.io/storj/lib/uplink" "storj.io/storj/pkg/cfgstruct" @@ -275,17 +276,17 @@ func (flags GatewayFlags) openProject(ctx context.Context) (*libuplink.Project, func (flags GatewayFlags) interactive( cmd *cobra.Command, setupDir string, encryptionKeyFilepath string, overrides map[string]interface{}, ) error { - satelliteAddress, err := cfgstruct.PromptForSatellite(cmd) + satelliteAddress, err := wizard.PromptForSatellite(cmd) if err != nil { return Error.Wrap(err) } - apiKey, err := cfgstruct.PromptForAPIKey() + apiKey, err := wizard.PromptForAPIKey() if err != nil { return Error.Wrap(err) } - humanReadableKey, err := cfgstruct.PromptForEncryptionKey() + humanReadableKey, err := wizard.PromptForEncryptionKey() if err != nil { return Error.Wrap(err) } diff --git a/pkg/cfgstruct/utils.go b/cmd/internal/wizard/wizard.go similarity index 91% rename from pkg/cfgstruct/utils.go rename to cmd/internal/wizard/wizard.go index d57e6e966..dce642a99 100644 --- a/pkg/cfgstruct/utils.go +++ b/cmd/internal/wizard/wizard.go @@ -1,7 +1,7 @@ // Copyright (C) 2019 Storj Labs, Inc. // See LICENSE for copying information -package cfgstruct +package wizard import ( "bytes" @@ -54,16 +54,25 @@ func applyDefaultHostAndPortToAddr(address, defaultAddress string) (string, erro // PromptForSatellite handles user input for a satellite address to be used with wizards func PromptForSatellite(cmd *cobra.Command) (string, error) { - _, err := fmt.Print(` -Pick satellite to use: - [1] us-central-1.tardigrade.io - [2] europe-west-1.tardigrade.io - [3] asia-east-1.tardigrade.io -Please enter numeric choice or enter satellite address manually [1]: `) + satellites := []string{"us-central-1.tardigrade.io", "europe-west-1.tardigrade.io", "asia-east-1.tardigrade.io"} + + _, err := fmt.Print("Pick a satellite to use:\n") if err != nil { return "", err } - satellites := []string{"us-central-1.tardigrade.io", "europe-west-1.tardigrade.io", "asia-east-1.tardigrade.io"} + + for iterator, value := range satellites { + _, err := fmt.Printf("\t[%d] %s\n", iterator+1, value) + if err != nil { + return "", nil + } + } + + _, err = fmt.Print("Please enter numeric choice or enter satellite address manually [1]: ") + if err != nil { + return "", err + } + var satelliteAddress string n, err := fmt.Scanln(&satelliteAddress) if err != nil { diff --git a/cmd/uplink/cmd/setup.go b/cmd/uplink/cmd/setup.go index 73cd0a393..bee67de7a 100644 --- a/cmd/uplink/cmd/setup.go +++ b/cmd/uplink/cmd/setup.go @@ -14,6 +14,7 @@ import ( "github.com/zeebo/errs" "go.uber.org/zap" + "storj.io/storj/cmd/internal/wizard" "storj.io/storj/internal/fpath" "storj.io/storj/pkg/cfgstruct" "storj.io/storj/pkg/process" @@ -116,17 +117,17 @@ func cmdSetupNonInteractive(cmd *cobra.Command, setupDir string, encryptionKeyFi // or to a default path whose directory tree exists. func cmdSetupInteractive(cmd *cobra.Command, setupDir string, encryptionKeyFilepath string) error { - satelliteAddress, err := cfgstruct.PromptForSatellite(cmd) + satelliteAddress, err := wizard.PromptForSatellite(cmd) if err != nil { return err } - apiKey, err := cfgstruct.PromptForAPIKey() + apiKey, err := wizard.PromptForAPIKey() if err != nil { return err } - humanReadableKey, err := cfgstruct.PromptForEncryptionKey() + humanReadableKey, err := wizard.PromptForEncryptionKey() if err != nil { return err }