diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/dialoguer/examples/wizard.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/dialoguer/examples/wizard.rs')
-rw-r--r-- | vendor/dialoguer/examples/wizard.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/vendor/dialoguer/examples/wizard.rs b/vendor/dialoguer/examples/wizard.rs new file mode 100644 index 0000000..b914032 --- /dev/null +++ b/vendor/dialoguer/examples/wizard.rs @@ -0,0 +1,81 @@ +use std::error::Error; +use std::net::IpAddr; + +use console::Style; +use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select}; + +#[derive(Debug)] +#[allow(dead_code)] +struct Config { + interface: IpAddr, + hostname: String, + use_acme: bool, + private_key: Option<String>, + cert: Option<String>, +} + +fn init_config() -> Result<Option<Config>, Box<dyn Error>> { + let theme = ColorfulTheme { + values_style: Style::new().yellow().dim(), + ..ColorfulTheme::default() + }; + println!("Welcome to the setup wizard"); + + if !Confirm::with_theme(&theme) + .with_prompt("Do you want to continue?") + .interact()? + { + return Ok(None); + } + + let interface = Input::with_theme(&theme) + .with_prompt("Interface") + .default("127.0.0.1".parse().unwrap()) + .interact()?; + + let hostname = Input::with_theme(&theme) + .with_prompt("Hostname") + .interact()?; + + let tls = Select::with_theme(&theme) + .with_prompt("Configure TLS") + .default(0) + .item("automatic with ACME") + .item("manual") + .item("no") + .interact()?; + + let (private_key, cert, use_acme) = match tls { + 0 => (Some("acme.pkey".into()), Some("acme.cert".into()), true), + 1 => ( + Some( + Input::with_theme(&theme) + .with_prompt(" Path to private key") + .interact()?, + ), + Some( + Input::with_theme(&theme) + .with_prompt(" Path to certificate") + .interact()?, + ), + false, + ), + _ => (None, None, false), + }; + + Ok(Some(Config { + hostname, + interface, + private_key, + cert, + use_acme, + })) +} + +fn main() { + match init_config() { + Ok(None) => println!("Aborted."), + Ok(Some(config)) => println!("{:#?}", config), + Err(err) => println!("error: {}", err), + } +} |