mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-15 16:43:49 -05:00
V3
Many many many changes, honestly just read the release notes
This commit is contained in:
51
src/main.rs
51
src/main.rs
@@ -1,23 +1,26 @@
|
||||
use check::get_updates;
|
||||
use chrono::Local;
|
||||
use clap::{Parser, Subcommand};
|
||||
use config::Config;
|
||||
use docker::get_images_from_docker_daemon;
|
||||
use formatting::spinner::Spinner;
|
||||
#[cfg(feature = "cli")]
|
||||
use formatting::{print_raw_updates, print_updates, Spinner};
|
||||
use formatting::{print_raw_updates, print_updates};
|
||||
use logging::Logger;
|
||||
#[cfg(feature = "server")]
|
||||
use server::serve;
|
||||
use std::path::PathBuf;
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub mod check;
|
||||
pub mod config;
|
||||
pub mod docker;
|
||||
#[cfg(feature = "cli")]
|
||||
pub mod formatting;
|
||||
pub mod image;
|
||||
pub mod http;
|
||||
pub mod logging;
|
||||
pub mod registry;
|
||||
#[cfg(feature = "server")]
|
||||
pub mod server;
|
||||
pub mod structs;
|
||||
pub mod utils;
|
||||
|
||||
#[derive(Parser)]
|
||||
@@ -29,13 +32,17 @@ struct Cli {
|
||||
config_path: String,
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
#[arg(short, long)]
|
||||
debug: bool,
|
||||
#[arg(long)]
|
||||
refresh: bool,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
#[cfg(feature = "cli")]
|
||||
Check {
|
||||
#[arg(name = "Images", default_value = None)]
|
||||
#[arg(name = "images", default_value = None)]
|
||||
references: Option<Vec<String>>,
|
||||
#[arg(short, long, default_value_t = false, help = "Enable icons")]
|
||||
icons: bool,
|
||||
@@ -59,6 +66,12 @@ enum Commands {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Context {
|
||||
pub config: Config,
|
||||
pub logger: Logger,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let cli = Cli::parse();
|
||||
@@ -67,10 +80,13 @@ async fn main() {
|
||||
path => Some(PathBuf::from(path)),
|
||||
};
|
||||
let mut config = Config::new().load(cfg_path);
|
||||
match cli.socket {
|
||||
Some(socket) => config.socket = Some(socket),
|
||||
None => ()
|
||||
if let Some(socket) = cli.socket {
|
||||
config.socket = Some(socket)
|
||||
}
|
||||
let mut ctx = Context {
|
||||
config,
|
||||
logger: Logger::new(cli.debug, false),
|
||||
};
|
||||
match &cli.command {
|
||||
#[cfg(feature = "cli")]
|
||||
Some(Commands::Check {
|
||||
@@ -78,27 +94,28 @@ async fn main() {
|
||||
icons,
|
||||
raw,
|
||||
}) => {
|
||||
let start = Local::now().timestamp_millis();
|
||||
let images = get_images_from_docker_daemon(&config, references).await;
|
||||
match raw {
|
||||
let start = SystemTime::now();
|
||||
if *raw {
|
||||
ctx.logger.set_raw(true);
|
||||
}
|
||||
match *raw || cli.debug {
|
||||
true => {
|
||||
let updates = get_updates(&images, &config).await;
|
||||
let updates = get_updates(references, cli.refresh, &ctx).await;
|
||||
print_raw_updates(&updates);
|
||||
}
|
||||
false => {
|
||||
let spinner = Spinner::new();
|
||||
let updates = get_updates(&images, &config).await;
|
||||
let updates = get_updates(references, cli.refresh, &ctx).await;
|
||||
spinner.succeed();
|
||||
let end = Local::now().timestamp_millis();
|
||||
print_updates(&updates, icons);
|
||||
info!("✨ Checked {} images in {}ms", updates.len(), end - start);
|
||||
ctx.logger.info(format!("✨ Checked {} images in {}ms", updates.len(), start.elapsed().unwrap().as_millis()));
|
||||
}
|
||||
};
|
||||
}
|
||||
#[cfg(feature = "server")]
|
||||
Some(Commands::Serve { port }) => {
|
||||
let _ = serve(port, &config).await;
|
||||
let _ = serve(port, &ctx).await;
|
||||
}
|
||||
None => (),
|
||||
None => error!("Whoops! It looks like you haven't specified a command to run! Try `cup help` to see available options."),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user