misc fixes
This commit is contained in:
parent
82e7331558
commit
f0c6e38403
1 changed files with 23 additions and 12 deletions
35
src/main.rs
35
src/main.rs
|
@ -6,10 +6,9 @@ use std::fs::File;
|
||||||
use std::io::{self, IsTerminal};
|
use std::io::{self, IsTerminal};
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::ExitCode;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::config::{Config, RecordType};
|
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::{Parser, Subcommand, ValueEnum};
|
use clap::{Parser, Subcommand, ValueEnum};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
@ -18,12 +17,15 @@ use serde_json::json;
|
||||||
use tabled::settings::object::Column;
|
use tabled::settings::object::Column;
|
||||||
use tabled::settings::{Alignment, Modify};
|
use tabled::settings::{Alignment, Modify};
|
||||||
use tabled::{Table, Tabled};
|
use tabled::{Table, Tabled};
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
use tracing::{debug, info, instrument, trace, warn, Level};
|
use tracing::{debug, error, info, instrument, trace, warn, Level};
|
||||||
use tracing_subscriber::filter::Directive;
|
use tracing_subscriber::filter::Directive;
|
||||||
use tracing_subscriber::fmt::Subscriber;
|
use tracing_subscriber::fmt::Subscriber;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
use crate::config::{Config, RecordType};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
|
||||||
const X_AUTH_EMAIL: &str = "X-Auth-Email";
|
const X_AUTH_EMAIL: &str = "X-Auth-Email";
|
||||||
|
@ -43,7 +45,7 @@ pub struct Args {
|
||||||
#[clap(short, long, global = true)]
|
#[clap(short, long, global = true)]
|
||||||
config_file: Option<PathBuf>,
|
config_file: Option<PathBuf>,
|
||||||
#[clap(short, long, global = true, value_delimiter = ',')]
|
#[clap(short, long, global = true, value_delimiter = ',')]
|
||||||
verbose: Vec<Directive>,
|
log: Vec<Directive>,
|
||||||
// Force whether or not to print colors
|
// Force whether or not to print colors
|
||||||
#[clap(long, default_value_t = Color::default())]
|
#[clap(long, default_value_t = Color::default())]
|
||||||
color: Color,
|
color: Color,
|
||||||
|
@ -78,7 +80,7 @@ enum OutputFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for OutputFormat {
|
impl Display for OutputFormat {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
OutputFormat::Table => Display::fmt("table", f),
|
OutputFormat::Table => Display::fmt("table", f),
|
||||||
OutputFormat::Json => Display::fmt("json", f),
|
OutputFormat::Json => Display::fmt("json", f),
|
||||||
|
@ -95,7 +97,7 @@ enum Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Color {
|
impl Display for Color {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Color::Auto => Display::fmt("auto", f),
|
Color::Auto => Display::fmt("auto", f),
|
||||||
Color::Never => Display::fmt("never", f),
|
Color::Never => Display::fmt("never", f),
|
||||||
|
@ -104,16 +106,25 @@ impl Display for Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
fn main() -> ExitCode {
|
||||||
async fn main() -> Result<()> {
|
let runtime = Runtime::new().unwrap();
|
||||||
|
let result = runtime.block_on(real_main());
|
||||||
|
drop(runtime);
|
||||||
|
if let Err(e) = result {
|
||||||
|
error!("{e:#?}");
|
||||||
|
ExitCode::FAILURE
|
||||||
|
} else {
|
||||||
|
ExitCode::SUCCESS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn real_main() -> Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let env_filter = args
|
let env_filter = args
|
||||||
.verbose
|
.log
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold(EnvFilter::from_default_env(), |env, directive| {
|
.fold(EnvFilter::from_default_env(), EnvFilter::add_directive);
|
||||||
env.add_directive(directive)
|
|
||||||
});
|
|
||||||
|
|
||||||
let is_stdout_terminal = io::stdout().is_terminal();
|
let is_stdout_terminal = io::stdout().is_terminal();
|
||||||
let use_ansi = match args.color {
|
let use_ansi = match args.color {
|
||||||
|
|
Loading…
Reference in a new issue