Add back the check command

This commit is contained in:
Andrey Golovizin 2023-04-09 23:41:35 +02:00
parent f663a4f8b4
commit ebccc59bf0
2 changed files with 34 additions and 3 deletions

View file

@ -41,6 +41,9 @@ struct ConfigOpts {
#[derive(Subcommand, Debug)]
enum Command {
/// Checks connection status
Check,
/// Prints the list of VPN endpoints
Locations,
@ -52,12 +55,27 @@ fn main() -> Result<(), anyhow::Error> {
env_logger::init();
let opts = Opts::parse();
match &opts.command {
Command::Check => check(&opts)?,
Command::Locations => list_locations(&opts)?,
Command::Config(get_config_opts) => get_config(&opts, get_config_opts)?,
}
Ok(())
}
fn check(opts: &Opts) -> Result<(), anyhow::Error> {
let check_result = api::check()?;
if opts.json {
println!("{}", serde_json::to_string(&check_result)?);
} else {
println!("Connected: {}", check_result.connected);
println!("Ip: {}", check_result.ip);
if let Some(location) = check_result.location {
println!("Location: {}", location);
}
}
Ok(())
}
fn list_locations(opts: &Opts) -> Result<(), anyhow::Error> {
let locations = api::get_locations()?;
if opts.json {