You've already forked step-ca-cli
mirror of
https://github.com/smallstep/cli.git
synced 2025-08-09 03:22:43 +03:00
Check flag values before printing
This commit is contained in:
@@ -171,38 +171,38 @@ func initAction(ctx *cli.Context) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if create {
|
if create {
|
||||||
fmt.Print("What would you like to name your new PKI?\n")
|
ui.PrintlnIfEmpty("What would you like to name your new PKI?", 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 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("What is the name of your organization?\n")
|
ui.Println("What is the name of your organization?")
|
||||||
org, err = ui.Prompt("(e.g. Smallstep)",
|
org, err = ui.Prompt("(e.g. Smallstep)",
|
||||||
ui.WithValidateNotEmpty())
|
ui.WithValidateNotEmpty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("What resource id do you want to use? [we will append -Root-CA or -Intermediate-CA]\n")
|
ui.Println("What resource id do you want to use? [we will append -Root-CA or -Intermediate-CA]")
|
||||||
resource, err = ui.Prompt("(e.g. Smallstep)",
|
resource, err = ui.Prompt("(e.g. Smallstep)",
|
||||||
ui.WithValidateRegexp("^[a-zA-Z0-9-_]+$"))
|
ui.WithValidateRegexp("^[a-zA-Z0-9-_]+$"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("What is the id of your project on Google's Cloud Platform?\n")
|
ui.Println("What is the id of your project on Google's Cloud Platform?")
|
||||||
project, err = ui.Prompt("(e.g. smallstep-ca)",
|
project, err = ui.Prompt("(e.g. smallstep-ca)",
|
||||||
ui.WithValidateRegexp("^[a-z][a-z0-9-]{4,28}[a-z0-9]$"))
|
ui.WithValidateRegexp("^[a-z][a-z0-9-]{4,28}[a-z0-9]$"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print("What region or location do you want to use?\n")
|
ui.Println("What region or location do you want to use?")
|
||||||
location, err = ui.Prompt("(e.g. us-west1)",
|
location, err = ui.Prompt("(e.g. us-west1)",
|
||||||
ui.WithValidateRegexp("^[a-z0-9-]+$"))
|
ui.WithValidateRegexp("^[a-z0-9-]+$"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Print("What certificate authority would you like to use?\n")
|
ui.Println("What certificate authority would you like to use?")
|
||||||
iss, err = ui.Prompt("(e.g. projects/smallstep-ca/locations/us-west1/certificateAuthorities/intermediate-ca)",
|
iss, err = ui.Prompt("(e.g. projects/smallstep-ca/locations/us-west1/certificateAuthorities/intermediate-ca)",
|
||||||
ui.WithValidateRegexp("^projects/[a-z][a-z0-9-]{4,28}[a-z0-9]/locations/[a-z0-9-]+/certificateAuthorities/[a-zA-Z0-9-_]+$"))
|
ui.WithValidateRegexp("^projects/[a-z][a-z0-9-]{4,28}[a-z0-9]/locations/[a-z0-9-]+/certificateAuthorities/[a-zA-Z0-9-_]+$"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -219,7 +219,7 @@ func initAction(ctx *cli.Context) (err error) {
|
|||||||
Location: location,
|
Location: location,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Print("What would you like to name your new PKI?\n")
|
ui.PrintlnIfEmpty("What would you like to name your new PKI?", 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
|
||||||
fmt.Print("What DNS names or IP addresses would you like to add to your new CA?\n")
|
ui.PrintlnIfEmpty("What DNS names or IP addresses would you like to add to your new CA?", 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
|
||||||
fmt.Print("What IP and port will your new CA bind to?\n")
|
ui.PrintlnIfEmpty("What IP and port will your new CA bind to?", 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
|
||||||
fmt.Print("What would you like to name the CA's first provisioner?\n")
|
ui.PrintlnIfEmpty("What would you like to name the CA's first provisioner?", 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Choose a password for your CA keys and first provisioner.\n")
|
ui.PrintlnIfEmpty("Choose a password for your CA keys and first provisioner.", 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 {
|
||||||
|
7
ui/ui.go
7
ui/ui.go
@@ -85,6 +85,13 @@ func PrintSelected(name, value string, opts ...Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print if the value (eg. a specific flag value) is empty
|
||||||
|
func PrintlnIfEmpty(s, value string) {
|
||||||
|
if value == "" {
|
||||||
|
Println(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prompt creates and runs a promptui.Prompt with the given label.
|
// Prompt creates and runs a promptui.Prompt with the given label.
|
||||||
func Prompt(label string, opts ...Option) (string, error) {
|
func Prompt(label string, opts ...Option) (string, error) {
|
||||||
o := &options{
|
o := &options{
|
||||||
|
Reference in New Issue
Block a user