1
0
mirror of https://github.com/smallstep/cli.git synced 2025-08-09 03:22:43 +03:00

Use ui.Println with options instead of private func

This commit is contained in:
Carl Tashian
2021-03-22 16:19:36 -07:00
parent 9cd5d9d77b
commit fe7b03041c

View File

@@ -171,7 +171,7 @@ func initAction(ctx *cli.Context) (err error) {
return err return err
} }
if create { if create {
printlnIfEmpty("What would you like to name your new PKI?", ctx.String("name")) ui.Println("What would you like to name your new PKI?", ui.WithValue(ctx.String("name")))
name, err = ui.Prompt("(e.g. Smallstep)", name, err = ui.Prompt("(e.g. Smallstep)",
ui.WithValidateNotEmpty(), ui.WithValue(ctx.String("name"))) ui.WithValidateNotEmpty(), ui.WithValue(ctx.String("name")))
if err != nil { if err != nil {
@@ -219,7 +219,7 @@ func initAction(ctx *cli.Context) (err error) {
Location: location, Location: location,
} }
default: default:
printlnIfEmpty("What would you like to name your new PKI?", ctx.String("name")) ui.Println("What would you like to name your new PKI?", ui.WithValue(ctx.String("name")))
name, err = ui.Prompt("(e.g. Smallstep)", name, err = ui.Prompt("(e.g. Smallstep)",
ui.WithValidateNotEmpty(), ui.WithValue(ctx.String("name"))) ui.WithValidateNotEmpty(), ui.WithValue(ctx.String("name")))
if err != nil { if err != nil {
@@ -239,7 +239,7 @@ func initAction(ctx *cli.Context) (err error) {
if configure { if configure {
var names string var names string
printlnIfEmpty("What DNS names or IP addresses would you like to add to your new CA?", ctx.String("dns")) ui.Println("What DNS names or IP addresses would you like to add to your new CA?", ui.WithValue(ctx.String("dns")))
names, err = ui.Prompt("(e.g. ca.smallstep.com[,1.1.1.1,etc.])", names, err = ui.Prompt("(e.g. ca.smallstep.com[,1.1.1.1,etc.])",
ui.WithValidateFunc(ui.DNS()), ui.WithValue(ctx.String("dns"))) ui.WithValidateFunc(ui.DNS()), ui.WithValue(ctx.String("dns")))
if err != nil { if err != nil {
@@ -256,7 +256,7 @@ func initAction(ctx *cli.Context) (err error) {
} }
var address string var address string
printlnIfEmpty("What IP and port will your new CA bind to?", ctx.String("address")) ui.Println("What IP and port will your new CA bind to?", ui.WithValue(ctx.String("address")))
address, err = ui.Prompt("(e.g. :443 or 127.0.0.1:4343)", address, err = ui.Prompt("(e.g. :443 or 127.0.0.1:4343)",
ui.WithValidateFunc(ui.Address()), ui.WithValue(ctx.String("address"))) ui.WithValidateFunc(ui.Address()), ui.WithValue(ctx.String("address")))
if err != nil { if err != nil {
@@ -264,7 +264,7 @@ func initAction(ctx *cli.Context) (err error) {
} }
var provisioner string var provisioner string
printlnIfEmpty("What would you like to name the CA's first provisioner?", ctx.String("provisioner")) ui.Println("What would you like to name the CA's first provisioner?", ui.WithValue(ctx.String("provisioner")))
provisioner, err = ui.Prompt("(e.g. you@smallstep.com)", provisioner, err = ui.Prompt("(e.g. you@smallstep.com)",
ui.WithValidateNotEmpty(), ui.WithValue(ctx.String("provisioner"))) ui.WithValidateNotEmpty(), ui.WithValue(ctx.String("provisioner")))
if err != nil { if err != nil {
@@ -277,7 +277,7 @@ func initAction(ctx *cli.Context) (err error) {
p.SetCAURL(caURL) p.SetCAURL(caURL)
} }
printlnIfEmpty("Choose a password for your CA keys and first provisioner.", password) ui.Println("Choose a password for your CA keys and first provisioner.", ui.WithValue(password))
pass, err := ui.PromptPasswordGenerate("[leave empty and we'll generate one]", pass, err := ui.PromptPasswordGenerate("[leave empty and we'll generate one]",
ui.WithRichPrompt(), ui.WithValue(password)) ui.WithRichPrompt(), ui.WithValue(password))
if err != nil { if err != nil {
@@ -366,10 +366,3 @@ func assertCryptoRand() error {
} }
return nil return nil
} }
// printlnIfEmpty prints s if value (eg. a specific flag value) is empty
func printlnIfEmpty(s, value string) {
if value == "" {
ui.Println(s)
}
}