Uplink CLI setup welcome message (#1735)

This commit is contained in:
Michal Niewrzal 2019-04-24 15:17:32 +02:00 committed by GitHub
parent ee3bf4a102
commit dcea59205d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 8 deletions

View File

@ -71,19 +71,41 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
var override map[string]interface{}
if !setupCfg.NonInteractive {
_, err = fmt.Print("Enter your Satellite address: ")
_, err = fmt.Print(`
Pick satellite to use:
[1] mars.tardigrade.io
[2] jupiter.tardigrade.io
[3] saturn.tardigrade.io
Please enter numeric choice or enter satellite address manually [1]: `)
if err != nil {
return err
}
satellites := []string{"mars.tardigrade.io", "jupiter.tardigrade.io", "saturn.tardigrade.io"}
var satelliteAddress string
_, err = fmt.Scanln(&satelliteAddress)
n, err := fmt.Scanln(&satelliteAddress)
if err != nil {
return err
if n == 0 {
// fmt.Scanln cannot handle empty input
satelliteAddress = satellites[0]
} else {
return err
}
}
// TODO add better validation
if satelliteAddress == "" {
return errs.New("Satellite address cannot be empty")
return errs.New("satellite address cannot be empty")
} else if len(satelliteAddress) == 1 {
switch satelliteAddress {
case "1":
satelliteAddress = satellites[0]
case "2":
satelliteAddress = satellites[1]
case "3":
satelliteAddress = satellites[2]
default:
return errs.New("Satellite address cannot be one character")
}
}
satelliteAddress, err = ApplyDefaultHostAndPortToAddr(satelliteAddress, cmd.Flags().Lookup("satellite-addr").Value.String())
@ -96,8 +118,8 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
return err
}
var apiKey string
_, err = fmt.Scanln(&apiKey)
if err != nil {
n, err = fmt.Scanln(&apiKey)
if err != nil && n != 0 {
return err
}
@ -147,9 +169,29 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
"api-key": apiKey,
"enc.key": string(encKey),
}
err = process.SaveConfigWithAllDefaults(cmd.Flags(), filepath.Join(setupDir, "config.yaml"), override)
if err != nil {
return nil
}
_, err = fmt.Println(`
Your Uplink CLI is configured and ready to use!
Some things to try next:
* Run 'uplink --help' to see the operations that can be performed
* See https://github.com/storj/docs/blob/master/Uplink-CLI.md#usage for some example commands
`)
if err != nil {
return nil
}
return nil
}
return process.SaveConfigWithAllDefaults(cmd.Flags(), filepath.Join(setupDir, "config.yaml"), override)
return process.SaveConfigWithAllDefaults(cmd.Flags(), filepath.Join(setupDir, "config.yaml"), nil)
}
// ApplyDefaultHostAndPortToAddrFlag applies the default host and/or port if either is missing in the specified flag name.

View File

@ -117,7 +117,7 @@ func saveConfig(flagset *pflag.FlagSet, outfile string, overrides map[string]int
if err != nil {
return err
}
fmt.Println("Configuration saved to:", outfile)
fmt.Println("Your configuration is saved to:", outfile)
return nil
}