forked from jamesmcm/vopono
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jamesmcm#171 from jamesmcm/refactor_dialoguer
Refactor dialoguer code into cli_client
- Loading branch information
Showing
29 changed files
with
679 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "vopono" | ||
description = "Launch applications via VPN tunnels using temporary network namespaces" | ||
version = "0.10.0" | ||
version = "0.10.1" | ||
authors = ["James McMurray <[email protected]>"] | ||
edition = "2021" | ||
license = "GPL-3.0-or-later" | ||
|
@@ -29,6 +29,8 @@ bs58 = "0.4" | |
nix = "0.24" | ||
config = "0.13" | ||
basic_tcp_proxy = "0.3" | ||
strum = "0.24" | ||
strum_macros = "0.24" | ||
|
||
[package.metadata.rpm] | ||
package = "vopono" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use vopono_core::config::providers::{ | ||
BoolChoice, ConfigurationChoice, Input, InputNumericu16, Password, UiClient, | ||
}; | ||
|
||
pub struct CliClient {} | ||
|
||
impl UiClient for CliClient { | ||
/// Launches a dialoguer single select menu for the enum | ||
fn get_configuration_choice( | ||
&self, | ||
config_choice: &dyn ConfigurationChoice, | ||
) -> anyhow::Result<usize> { | ||
let display_names = config_choice.all_names(); | ||
let descriptions = config_choice.all_descriptions(); | ||
let parsed = if let Some(descs) = descriptions { | ||
display_names | ||
.iter() | ||
.zip(descs) | ||
.map(|x| format!("{}: {}", x.0, x.1)) | ||
.collect::<Vec<String>>() | ||
} else { | ||
display_names | ||
}; | ||
|
||
let index = dialoguer::Select::new() | ||
.with_prompt(config_choice.prompt()) | ||
.items(&parsed) | ||
// TODO: Is this good enough? | ||
.default(0) | ||
.interact()?; | ||
Ok(index) | ||
} | ||
fn get_bool_choice(&self, bool_choice: BoolChoice) -> anyhow::Result<bool> { | ||
Ok(dialoguer::Confirm::new() | ||
.with_prompt(&bool_choice.prompt) | ||
.default(bool_choice.default) | ||
.interact()?) | ||
} | ||
|
||
fn get_input(&self, inp: Input) -> anyhow::Result<String> { | ||
let mut d = dialoguer::Input::<String>::new(); | ||
|
||
d.with_prompt(&inp.prompt); | ||
|
||
if inp.validator.is_some() { | ||
d.validate_with(inp.validator.unwrap()); | ||
}; | ||
|
||
Ok(d.interact()?) | ||
} | ||
|
||
fn get_input_numeric_u16(&self, inp: InputNumericu16) -> anyhow::Result<u16> { | ||
let mut d = dialoguer::Input::<u16>::new(); | ||
d.with_prompt(&inp.prompt); | ||
|
||
if inp.default.is_some() { | ||
d.default(inp.default.unwrap()); | ||
} | ||
if inp.validator.is_some() { | ||
d.validate_with(inp.validator.unwrap()); | ||
} | ||
|
||
Ok(d.interact()?) | ||
} | ||
|
||
fn get_password(&self, pw: Password) -> anyhow::Result<String> { | ||
let mut req = dialoguer::Password::new(); | ||
if pw.confirm { | ||
req.with_confirmation("Confirm password", "Passwords did not match"); | ||
}; | ||
req.with_prompt(pw.prompt); | ||
Ok(req.interact()?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.