github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/pkg/interactive/prompt.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package interactive contains functions for interacting with the user via STDIN. 5 package interactive 6 7 import ( 8 "fmt" 9 10 "github.com/AlecAivazis/survey/v2" 11 "github.com/Racer159/jackal/src/pkg/message" 12 "github.com/Racer159/jackal/src/types" 13 ) 14 15 // PromptSigPassword prompts the user for the password to their private key 16 func PromptSigPassword() ([]byte, error) { 17 var password string 18 19 prompt := &survey.Password{ 20 Message: "Private key password (empty for no password): ", 21 } 22 return []byte(password), survey.AskOne(prompt, &password) 23 } 24 25 // PromptVariable prompts the user for a value for a variable 26 func PromptVariable(variable types.JackalPackageVariable) (value string, err error) { 27 28 if variable.Description != "" { 29 message.Question(variable.Description) 30 } 31 32 prompt := &survey.Input{ 33 Message: fmt.Sprintf("Please provide a value for %q", variable.Name), 34 Default: variable.Default, 35 } 36 37 return value, survey.AskOne(prompt, &value) 38 }