mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
feat: gpauth support macos
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
use clap_verbosity_flag::{LogLevel, Verbosity, VerbosityFilter};
|
||||
use log::Level;
|
||||
|
||||
use crate::error::PortalError;
|
||||
|
||||
pub mod args;
|
||||
@@ -8,7 +11,7 @@ pub trait Args {
|
||||
}
|
||||
|
||||
pub fn handle_error(err: anyhow::Error, args: &impl Args) {
|
||||
eprintln!("\nError: {}", err);
|
||||
eprintln!("\nError: {:?}", err);
|
||||
|
||||
let Some(err) = err.downcast_ref::<PortalError>() else {
|
||||
return;
|
||||
@@ -26,3 +29,53 @@ pub fn handle_error(err: anyhow::Error, args: &impl Args) {
|
||||
eprintln!("{} --ignore-tls-errors {}\n", args[0], args[1..].join(" "));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InfoLevel;
|
||||
|
||||
pub type InfoLevelVerbosity = Verbosity<InfoLevel>;
|
||||
|
||||
impl LogLevel for InfoLevel {
|
||||
fn default_filter() -> VerbosityFilter {
|
||||
VerbosityFilter::Info
|
||||
}
|
||||
|
||||
fn verbose_help() -> Option<&'static str> {
|
||||
Some("Enable verbose output, -v for debug, -vv for trace")
|
||||
}
|
||||
|
||||
fn quiet_help() -> Option<&'static str> {
|
||||
Some("Decrease logging verbosity, -q for warnings, -qq for errors")
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToVerboseArg {
|
||||
fn to_verbose_arg(&self) -> Option<&'static str>;
|
||||
}
|
||||
|
||||
/// Convert the verbosity to the CLI argument value
|
||||
/// The default verbosity is `Info`, which means no argument is needed
|
||||
impl ToVerboseArg for InfoLevelVerbosity {
|
||||
fn to_verbose_arg(&self) -> Option<&'static str> {
|
||||
match self.filter() {
|
||||
VerbosityFilter::Off => Some("-qqq"),
|
||||
VerbosityFilter::Error => Some("-qq"),
|
||||
VerbosityFilter::Warn => Some("-q"),
|
||||
VerbosityFilter::Info => None,
|
||||
VerbosityFilter::Debug => Some("-v"),
|
||||
VerbosityFilter::Trace => Some("-vv"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToVerboseArg for Level {
|
||||
fn to_verbose_arg(&self) -> Option<&'static str> {
|
||||
match self {
|
||||
Level::Error => Some("-qq"),
|
||||
Level::Warn => Some("-q"),
|
||||
Level::Info => None,
|
||||
Level::Debug => Some("-v"),
|
||||
Level::Trace => Some("-vv"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user