get 0.1.1

gets#it ultra fast
Documentation

use std::{fs::File, path::PathBuf};
use get::*;
pub use get::*;
use minimo::{divider, showln, vibrant, Printable, Renderable};
use reqwest::Client;
use tokio::time::error::Error;
pub use tokio::*;
//dripper banner
const BANNER: &str = r#"
                      ___        .___    
  *             ..___'  /  _____+ __/  _____ *
                 + __  /./  ___//  /__/  __+\      +
                / /_/ / /  /  _'  /._   /_/ /  ~
            +   \__,_/ / _/   * _/ +   .___/ 
───────────────────────────────────  _/─────────────────────     
"#;


#[tokio::main]
async fn main() -> Result<(), Error> {
    BANNER.print(vibrant);
    showln!(gray_dim, "ultra fast download manager ",yellow_bold,env!("CARGO_PKG_VERSION"),gray_dim," by ",cyan_bold,env!("CARGO_PKG_AUTHORS"));
    divider();
    handle_args().await;
    Ok(())

}


pub async fn handle_args() {
    let args: Vec<String> = std::env::args().collect();
    // if no args, print help
    if args.len() == 1 {
        print_help();
        return;
    }
    // if args, 
    // drip get <url> // download file
    // drip search <query> // search
    
    if args.len() > 1 {
        if args[1] == "get" || args[1] == "download" || args[1] == "-d" {
            let mut files = Vec::new();
            for i in 2..args.len() {
                files.push(args[i].clone());
            }
            download_files(files).await.unwrap();
        }
        if args[1] == "search" || args[1] == "-s"  || args[1] == "find" {
            let mut query = String::new();
            let mut page = String::new();
            for i in 2..args.len() {
                if args[i] == "-p" {
                    page = args[i+1].clone();
                    break;
                }
                query.push_str(args[i].as_str());
                query.push_str(" ");
            }
            // search(query, page).await;
        }
    }
}

pub fn print_help() {
    // showln!(yellow_bold,"USAGE ");
    // divider();
    showln!(white,"get ",yellow_bold,"<url> ",gray_dim,"- download file");
    showln!(white,"get ",yellow_bold,"'url1' 'url2' 'url3' ",gray_dim,"- download multiple files");
    showln!(white,"get ",yellow_bold,"<github_repo> ",gray_dim,"- download latest release");

    showln!(gray,"all downloads are saved to user's Downloads directory");
    divider();
}

pub async fn download_files(files: Vec<String>) -> Result<(), Error> {
    for file in files {
        let url = file.clone();
        let filename = file.split('/').last().unwrap();
        let download = Download {
            url: url,
            filename: filename.to_string(),
            memory: 256,
            threads: 4,
            network: Network::default(),
            progress: Progress::default(),
        };
        download.get().await;
    }
    Ok(())
}


pub fn get_downloads_directory() -> PathBuf {
    let mut path = dirs::home_dir().unwrap();
    path.push("Downloads");
    path
}