Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
refactor: cleanup, split infotexts into info.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
khyerdev committed Apr 30, 2024
1 parent 66422c5 commit 478472d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::Read;

pub mod types;
pub mod strings;

#[derive(Debug, Clone, PartialEq)]
pub struct Args {
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()));
Expand Down
25 changes: 25 additions & 0 deletions src/strings/info.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions src/strings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<char>>().first() == Some(&'[') { brackets += 1; continue }

Expand Down

0 comments on commit 478472d

Please sign in to comment.