style: reorder imports and reformat code for consistency

This commit is contained in:
Andrew Phillips
2025-05-10 10:06:33 -03:00
committed by Andrew Phillips (aider)
parent c936326ac3
commit 9feec61759
13 changed files with 492 additions and 356 deletions

View File

@@ -1,39 +1,27 @@
use std::io;
use std::path::PathBuf;
use anyhow::{Context, Result, anyhow};
use rusqlite::Connection;
use gethostname::gethostname;
use strum::IntoEnumIterator;
use clap::error::ErrorKind;
use anyhow::{anyhow, Context, Result};
use clap::*;
use log::*;
use is_terminal::IsTerminal;
use chrono::prelude::*;
use std::os::fd::FromRawFd;
use std::process::Stdio;
use nix::fcntl::{FdFlag};
use nix::unistd::{close, pipe};
use nix::Error as NixError;
use std::path::PathBuf;
use strum::IntoEnumIterator;
use crate::compression::CompressionType;
use strum::EnumString;
use crate::compression::program::CompressionEngineProgram;
use crate::compression::COMPRESSION_PROGRAMS;
use crate::compression::default_type;
use crate::db;
use crate::modes::common::{format_size, string_column};
use crate::compression::program::CompressionEngineProgram;
use crate::compression::CompressionType;
use crate::compression::COMPRESSION_PROGRAMS;
use std::str::FromStr;
use crate::compression::CompressionEngine;
use prettytable::{Table, Row, Cell, Attr};
use prettytable::format;
use prettytable::format::{TableFormat, Alignment};
use prettytable::row;
use prettytable::color;
use crate::FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR;
use crate::FORMAT_NO_BORDER_LINE_SEPARATOR;
use prettytable::color;
use prettytable::row;
use prettytable::{Attr, Cell, Row, Table};
pub fn mode_status(_cmd: &mut Command, args: crate::Args, data_path: PathBuf, db_path: PathBuf) -> Result<()> {
pub fn mode_status(
_cmd: &mut Command,
args: crate::Args,
data_path: PathBuf,
db_path: PathBuf,
) -> Result<()> {
let mut path_table = Table::new();
if std::io::stdout().is_terminal() {
@@ -49,15 +37,24 @@ pub fn mode_status(_cmd: &mut Command, args: crate::Args, data_path: PathBuf, db
path_table.add_row(Row::new(vec![
Cell::new("Data"),
Cell::new(&data_path.into_os_string().into_string().expect("Unable to convert data path to string"))
Cell::new(
&data_path
.into_os_string()
.into_string()
.expect("Unable to convert data path to string"),
),
]));
path_table.add_row(Row::new(vec![
Cell::new("Database"),
Cell::new(&db_path.into_os_string().into_string().expect("Unable to convert DB path to string"))
Cell::new(
&db_path
.into_os_string()
.into_string()
.expect("Unable to convert DB path to string"),
),
]));
let mut compression_table = Table::new();
if std::io::stdout().is_terminal() {
compression_table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR);
@@ -73,38 +70,40 @@ pub fn mode_status(_cmd: &mut Command, args: crate::Args, data_path: PathBuf, db
b->"Compress",
b->"Decompress"));
let default_type = match args.item.compression {
Some(compression_name) => FromStr::from_str(&compression_name)
.context(anyhow!("Invalid compression type {}", compression_name))?,
None => default_type()
None => default_type(),
};
for compression_type in CompressionType::iter() {
let compression_program: CompressionEngineProgram = match &COMPRESSION_PROGRAMS[compression_type.clone()] {
Some(compression_program) => compression_program.clone(),
None => CompressionEngineProgram {
program: "".to_string(),
compress: Vec::new(),
decompress: Vec::new(),
supported: true
}
};
let compression_program: CompressionEngineProgram =
match &COMPRESSION_PROGRAMS[compression_type.clone()] {
Some(compression_program) => compression_program.clone(),
None => CompressionEngineProgram {
program: "".to_string(),
compress: Vec::new(),
decompress: Vec::new(),
supported: true,
},
};
let is_default = compression_type == default_type;
compression_table.add_row(Row::new(vec![
Cell::new(&compression_type.to_string()),
match compression_program.supported {
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED))
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)),
},
match is_default {
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No")
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No"),
},
match compression_program.program.eq("") {
true => Cell::new("<INTERNAL>").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK)),
true => {
Cell::new("<INTERNAL>").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))
}
false => Cell::new(&compression_program.program),
},
Cell::new(&compression_program.compress.join(" ")),