// Wizard launches a interactive question/answer terminal prompt to create a config file
Wizard launches a interactive question/answer terminal prompt to create a config file
// Wizard launches a interactive question / answer terminal prompt to create a config file
func Wizard(configPath string, config *SSHrimp) (string, error) {
	newConfig := NewSSHrimp()
	if err := survey.Ask(certificateAuthorityQuestions(config), &newConfig.CertificateAuthority); err != nil {
		return "", err
	}
	if err := survey.Ask(agentQuestions(config), &newConfig.Agent); err != nil {
		return "", err
	}
	var browserCommand string
	if err := survey.Ask(browserCommandQuestions(config), &browserCommand); err != nil {
		return "", err
	}
	words, err := shellquote.Split(browserCommand)
	if err != nil {
		return "", err
	}
	newConfig.Agent.BrowserCommand = words
	var overwriteIfExists = false
	for !overwriteIfExists {
		if err := survey.Ask(configFileQuestions(configPath), &configPath); err != nil {
			return "", err
		}
		if _, err := os.Stat(configPath); err == nil {
			if err := survey.AskOne(&survey.Confirm{
				Message: "File exists, overwrite?",
				Default: false,
			}, &overwriteIfExists); err != nil {
				return "", err
			}
		} else {
			break
		}
	}
	newConfig.Write(configPath)
	return configPath, nil
}
func Wizard ( configPath string , config * SSHrimp ) ( string , error ) { newConfig := NewSSHrimp ( ) if err := survey . Ask ( certificateAuthorityQuestions ( config ) , & newConfig . CertificateAuthority ) ; err != nil { return " " , err } if err := survey . Ask ( agentQuestions ( config ) , & newConfig . Agent ) ; err != nil { return " " , err } var browserCommand string if err := survey . Ask ( browserCommandQuestions ( config ) , & browserCommand ) ; err != nil { return " " , err } words , err := shellquote . Split ( browserCommand ) if err != nil { return " " , err } newConfig . Agent . BrowserCommand = words var overwriteIfExists = false for ! overwriteIfExists { if err := survey . Ask ( configFileQuestions ( configPath ) , & configPath ) ; err != nil { return " " , err } if _ , err := os . Stat ( configPath ) ; err == nil { if err := survey . AskOne ( & survey . Confirm { Message : " " , Default : false , } , & overwriteIfExists ) ; err != nil { return " " , err } } else { break } } newConfig . Write ( configPath ) return configPath , nil }
Wizard launches a interactive question/answer terminal prompt to create a config file
Wizard launches a interactive question / answer terminal prompt to create a config file
// Create a new config that doesn't have any default values, otherwise survey appends to the defaults. //duplicating the necessary fields from Agent Config over to the CertificateAuthority Config // newConfig.CertificateAuthority.IdentityProviderURI = strings.Replace(newConfig.Agent.ProviderURL, "https://", "", 1) // newConfig.CertificateAuthority.IdentityProviderClientID = newConfig.Agent.ClientID // Ask BrowserCommand separately so we can store it as a []string, currently not supported by survey. // Split the command by sh rules using shellquote. The command is stored as a slice of arguments. // Confirm config file path, and keep prompting if exists and user chooses not to overwrite // File exists, confirm to be overwritten // File doesn't exist, break and save the file // Write the new configuration to a file