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

Commit

Permalink
start making config file
Browse files Browse the repository at this point in the history
  • Loading branch information
khyerdev committed May 3, 2024
1 parent 586dbb4 commit 5ca18b8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/args/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::path::PathBuf;

#[cfg(unix)]
const CONFIG_PATH: &str = "$HOME/.config/tcobalt.conf";
#[cfg(target_os = "windows")]
const CONFIG_PATH: &str = "$LOCALAPPDATA/tcobalt.conf";

pub fn load_config_into(args: &mut Vec<String>, instance_list: &mut String) {
let path = PathBuf::from(CONFIG_PATH);

if path.exists() {
let options = get_config("default");
for line in options.lines() {
let option: Vec<&str> = line.split('=').map(|s| s.trim()).collect();
if option.len() != 2 {
continue;
}

match option[0] {
"vcodec" => {},
"vquality" => {},
"aformat" => {},
"audio-only" => {},
"mute-audio" => {},
"twitter-gif" => {},
"tt-full-audio" => {},
"tt-h265" => {},
"dublang" => {},
"no-metadata" => {},
"fname-style" => {},
"instance" => {},
_ => ()
}
}
}
}

fn get_config(symbol: &str) -> String {
let text = CONFIG_PATH;

let mut string = String::new();
let mut select = false;
let mut brackets = 0;
for line in text.lines().into_iter() {
if brackets == 2 { break }
if !select && crate::strings::remove_trailing_whitespace(line) != format!("[{symbol}]") { continue }
select = true;
if line.chars().collect::<Vec<char>>().first() == Some(&'[') { brackets += 1; continue }

string.push_str(line);
string.push('\n');
}
crate::strings::remove_trailing_whitespace(string)
}

7 changes: 7 additions & 0 deletions src/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io::Read;

pub mod types;
mod config;

#[derive(Debug, Clone, PartialEq)]
pub struct Args {
Expand Down Expand Up @@ -64,6 +65,7 @@ impl Args {
str.into()
}
}).collect();

match self.raw.get(1) {
Some(method) => match method.as_str() {
"help" | "-h" | "--help" | "h" => {
Expand All @@ -82,6 +84,11 @@ impl Args {
},
"get" | "g" => {
self.method = Some(types::Method::Get);

let mut instance_list = String::new();
let mut default_args: Vec<String> = Vec::new();
config::load_config_into(&mut default_args, &mut instance_list);

let mut idx = 1;
let mut expected: Vec<ExpectedFlags> = Vec::new();
let mut stdin = false;
Expand Down

0 comments on commit 5ca18b8

Please sign in to comment.