From 478472d9d2cd8bbfac76d9325479dce879e24b46 Mon Sep 17 00:00:00 2001 From: OSCH2008 Date: Tue, 30 Apr 2024 13:37:31 -0800 Subject: [PATCH] refactor: cleanup, split infotexts into info.txt --- src/args/mod.rs | 1 - src/main.rs | 12 ++++++------ src/strings/info.txt | 25 +++++++++++++++++++++++++ src/strings/mod.rs | 12 +++++++++--- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/args/mod.rs b/src/args/mod.rs index e34b320..f7a9e4b 100644 --- a/src/args/mod.rs +++ b/src/args/mod.rs @@ -1,7 +1,6 @@ use std::io::Read; pub mod types; -pub mod strings; #[derive(Debug, Clone, PartialEq)] pub struct Args { diff --git a/src/main.rs b/src/main.rs index bbf21ab..2a629f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,10 +31,10 @@ async fn main() -> std::process::ExitCode { if let Some(help_flag) = args.help_flag { match help_flag { args::types::Help::Help => println!("{}", strings::get_help()), - args::types::Help::List => println!("{}", strings::get_mod("list")), - args::types::Help::Bulk => println!("{}", strings::get_mod("bulk")), - args::types::Help::Get => println!("{}", strings::get_mod("get")), - args::types::Help::Examples => println!("{}", strings::get_mod("examples")), + args::types::Help::List => println!("{}", strings::get_str("usage", "list")), + args::types::Help::Bulk => println!("{}", strings::get_str("usage", "bulk")), + args::types::Help::Get => println!("{}", strings::get_str("usage", "get")), + args::types::Help::Examples => println!("{}", strings::get_str("usage", "examples")), } return std::process::ExitCode::SUCCESS; } @@ -76,9 +76,9 @@ async fn main() -> std::process::ExitCode { return std::process::ExitCode::FAILURE; } }, - args::types::Method::List => println!("{}", strings::get_mod("supported")), + args::types::Method::List => println!("{}", strings::get_str("info", "supported")), args::types::Method::Help => unreachable!(), - args::types::Method::Version => println!("{}", strings::get_mod("version").replace("{}", VERSION.trim())), + args::types::Method::Version => println!("{}", strings::get_str("info", "version").replace("{}", VERSION.trim())), args::types::Method::CobaltVersion => { let request = reqwest::Client::new().get("https://co.wuk.sh/api/serverInfo") .header("User-Agent", &format!("tcobalt {}", VERSION.trim())); diff --git a/src/strings/info.txt b/src/strings/info.txt index e69de29..187928c 100644 --- a/src/strings/info.txt +++ b/src/strings/info.txt @@ -0,0 +1,25 @@ +[version] +tcobalt command line utility {} +Copyright (c) 2024 Khyernet +This is free software, distributed under the GNU GPL v3. +You may also use, modify, and distribute this software under the same license. +The code and license is available at https://github.com/khyerdev/tcobalt + +[supported] +bilibili.com & bilibili.tv +dailymotion videos +instagram reels, posts & stories +ok video (full video+audio only) +pinterest videos & stories +reddit videos & gifs +rutube videos +soundcloud (audio only) +streamable.com +tiktok videos, photos & audio +tumblr video & audio +twitch clips +twitter videos & voice +vimeo +vine archive +vk video & clips (full video+audio only) +youtube videos, shorts & music diff --git a/src/strings/mod.rs b/src/strings/mod.rs index 79c5ffe..c5b4061 100644 --- a/src/strings/mod.rs +++ b/src/strings/mod.rs @@ -11,13 +11,19 @@ pub fn get_help() -> String { remove_trailing_whitespace(string) } -pub fn get_mod(help_mod: &str) -> String { +pub fn get_str(module: &str, symbol: &str) -> String { + let text = match module { + "usage" => USAGE_TXT, + "info" => INFO_TXT, + _ => unreachable!() + }; + let mut string = String::new(); let mut select = false; let mut brackets = 0; - for line in USAGE_TXT.lines().into_iter() { + for line in text.lines().into_iter() { if brackets == 2 { break } - if !select && remove_trailing_whitespace(line) != format!("[{help_mod}]") { continue } + if !select && remove_trailing_whitespace(line) != format!("[{symbol}]") { continue } select = true; if line.chars().collect::>().first() == Some(&'[') { brackets += 1; continue }