Cargo formatting

This commit is contained in:
kdeng00
2024-05-05 15:59:55 -04:00
parent 33abb7b948
commit 72e6070946
22 changed files with 116 additions and 80 deletions
+9 -7
View File
@@ -1,8 +1,8 @@
mod managers; mod managers;
mod models; mod models;
mod utilities;
mod parsers; mod parsers;
mod syncers; mod syncers;
mod utilities;
use std::env; use std::env;
use std::process; use std::process;
@@ -17,7 +17,7 @@ fn print_help() {
Actions Actions
download download
upload upload (Search NOTE)
upload-meta upload-meta
retrieve retrieve
delete delete
@@ -58,13 +58,15 @@ fn print_help() {
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() == 0 { if args.len() == 1 {
print_help(); print_help();
exit_program(-1); exit_program(-1);
} }
let args_len = args.len() as i32; let args_len = args.len() as i32;
println!("Argument count: {}", args_len);
let mut act_mgr = managers::action_managers::ActionManager { let mut act_mgr = managers::action_managers::ActionManager {
action: String::from(""), action: String::from(""),
flags: Vec::new(), flags: Vec::new(),
@@ -78,10 +80,10 @@ fn main() {
chosen_act.print_action_and_flags(); chosen_act.print_action_and_flags();
let cmt_mgr = managers::commit_manager::CommitManager { let cmt_mgr = managers::commit_manager::CommitManager {
// action: String::from(""), // action: String::from(""),
// flags: Vec::new(), // flags: Vec::new(),
// params: Vec::new(), // params: Vec::new(),
// param_count: 1, // param_count: 1,
ica_action: chosen_act, ica_action: chosen_act,
}; };
+21 -4
View File
@@ -19,7 +19,8 @@ impl ActionManager {
} }
fn supported_flags(&self) -> Vec<String> { fn supported_flags(&self) -> Vec<String> {
return vec![String::from("-u"), return vec![
String::from("-u"),
String::from("-p"), String::from("-p"),
String::from("-t"), String::from("-t"),
String::from("-h"), String::from("-h"),
@@ -45,6 +46,7 @@ impl ActionManager {
pub fn initialize(&mut self) { pub fn initialize(&mut self) {
self.validate_flags(); self.validate_flags();
self.validate_action();
self.action = self.action.to_lowercase(); self.action = self.action.to_lowercase();
} }
@@ -53,16 +55,22 @@ impl ActionManager {
let flag_vals = self.parsed_flags(); let flag_vals = self.parsed_flags();
for i in 0..flag_vals.len() { let mut i = 0;
println!("Flag count: {}", flag_vals.len());
// for mut i in 0..flag_vals.len() {
while i < flag_vals.len() {
let flag = &flag_vals[i]; let flag = &flag_vals[i];
println!("Value: {}", flag); println!("Index: {} | Value: {}", i, flag);
let mut flg = models::flags::Flags::default(); let mut flg = models::flags::Flags::default();
if self.is_valid_flag(flag) && self.does_flag_have_value(flag) { if self.is_valid_flag(flag) && self.does_flag_have_value(flag) {
println!("Flag has value"); println!("Flag has value");
flg.flag = String::from(flag); flg.flag = String::from(flag);
flg.value = String::from(&flag_vals[i+1]); flg.value = String::from(&flag_vals[i + 1]);
// println!("Before change {}", i);
i = i + 1;
// println!("After change {}", i);
} else if self.is_valid_flag(flag) { } else if self.is_valid_flag(flag) {
println!("Flag does not have a value"); println!("Flag does not have a value");
flg.flag = String::from(flag); flg.flag = String::from(flag);
@@ -72,6 +80,15 @@ impl ActionManager {
} }
self.flags.push(flg); self.flags.push(flg);
println!("");
i += 1;
}
}
fn validate_action(&self) {
if self.params.len() >= 2 {
let act = &self.params[1];
println!("The action {}", act);
} }
} }
+47 -28
View File
@@ -1,5 +1,5 @@
use std::default::Default;
use std::collections::HashMap; use std::collections::HashMap;
use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -17,7 +17,6 @@ pub struct CommitManager {
pub ica_action: models::icarus_action::IcarusAction, pub ica_action: models::icarus_action::IcarusAction,
} }
pub struct Album { pub struct Album {
pub title: String, pub title: String,
pub album_artist: String, pub album_artist: String,
@@ -35,19 +34,21 @@ impl Default for Album {
album_artist: String::new(), album_artist: String::new(),
genre: String::new(), genre: String::new(),
year: 0, year: 0,
track_count: 0, track_count: 0,
disc_count: 0, disc_count: 0,
songs: Vec::new(), songs: Vec::new(),
} }
} }
} }
#[derive(Clone, Debug)]
enum ActionValues { enum ActionValues {
DeleteAct, DeleteAct,
DownloadAct, DownloadAct,
RetrieveAct, RetrieveAct,
UploadAct, UploadAct,
UploadSongWithMetadata, UploadSongWithMetadata,
None,
} }
enum RetrieveTypes { enum RetrieveTypes {
@@ -66,28 +67,38 @@ impl Album {
} }
impl CommitManager { impl CommitManager {
pub fn commit_action(&self) { pub fn commit_action(&self) {
let action = &self.ica_action.action; let action = &self.ica_action.action;
println!("Committing {} action", action); println!("Committing {} action", action);
match self.map_actions()[action] { let mapped_actions = self.map_actions();
ActionValues::DeleteAct => self.delete_song(), let mapped_action = self.find_mapped_action(&mapped_actions, action);
ActionValues::DownloadAct => self.download_song(),
ActionValues::RetrieveAct => self.retrieve_object(), println!("{:?}", mapped_action);
ActionValues::UploadAct => self.upload_song(), }
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata(),
_ => { fn find_mapped_action(
println!("Nothing good here"); &self,
actions: &HashMap<String, ActionValues>,
action: &String,
) -> ActionValues {
for (key, act) in actions {
if key == action {
return act.clone();
} }
} }
return ActionValues::None;
} }
fn map_actions(&self) -> HashMap<String, ActionValues> { fn map_actions(&self) -> HashMap<String, ActionValues> {
let mut actions: HashMap<String, ActionValues> = HashMap::new(); let mut actions: HashMap<String, ActionValues> = HashMap::new();
actions.insert("download".to_string(), ActionValues::DownloadAct); actions.insert("download".to_string(), ActionValues::DownloadAct);
actions.insert("upload".to_string(), ActionValues::UploadAct); // actions.insert("upload".to_string(), ActionValues::UploadAct);
actions.insert("upload-meta".to_string(), ActionValues::UploadSongWithMetadata); actions.insert(
"upload-meta".to_string(),
ActionValues::UploadSongWithMetadata,
);
actions.insert("retrieve".to_string(), ActionValues::RetrieveAct); actions.insert("retrieve".to_string(), ActionValues::RetrieveAct);
actions.insert("delete".to_string(), ActionValues::DeleteAct); actions.insert("delete".to_string(), ActionValues::DeleteAct);
@@ -101,36 +112,42 @@ impl CommitManager {
api: models::api::API::default(), api: models::api::API::default(),
}; };
println!("Deleting song");
let api = prsr.retrieve_api(); let api = prsr.retrieve_api();
let song = models::song::Song::default(); let song = models::song::Song::default();
for arg in &self.ica_action.flags { for arg in &self.ica_action.flags {}
}
} }
// TODO: Implement // TODO: Implement
fn download_song(&self) { fn download_song(&self) {
println!("Deleting song");
} }
// TODO: Implement // TODO: Implement
fn retrieve_object(&self) { fn retrieve_object(&self) {
println!("Deleting song");
} }
// TODO: Implement // TODO: Implement
// NOTE: Might not need to implement. I will see how this goes
fn upload_song(&self) { fn upload_song(&self) {
println!("Deleting song");
} }
fn parse_token(&self, api: &models::api::API) -> models::token::Token { fn parse_token(&self, api: &models::api::API) -> models::token::Token {
println!("Fetching token"); println!("Fetching token");
let mut usr_mgr: managers::user_manager::UserManager = managers::user_manager::UserManager { let mut usr_mgr: managers::user_manager::UserManager =
user: models::user::User { managers::user_manager::UserManager {
username: String::new(), user: models::user::User {
password: String::new(), username: String::new(),
}, password: String::new(),
ica_action: self.ica_action.clone(), },
}; ica_action: self.ica_action.clone(),
};
let usr = usr_mgr.retrieve_user(); let usr = usr_mgr.retrieve_user();
let tok_mgr = managers::token_manager::TokenManager { let tok_mgr = managers::token_manager::TokenManager {
@@ -141,7 +158,9 @@ impl CommitManager {
return tok_mgr.request_token(); return tok_mgr.request_token();
} }
// TODO: Implement // TODO: Implement
fn upload_song_with_metadata(&self) {} fn upload_song_with_metadata(&self) {
println!("Deleting song");
}
// TODO: Implement // TODO: Implement
fn sing_target_upload( fn sing_target_upload(
&self, &self,
@@ -162,7 +181,8 @@ impl CommitManager {
let track = 1; let track = 1;
let mut mode = 0; let mut mode = 0;
let songpath = song.song_path(); let songpath = song.song_path();
let filename = &<std::option::Option<std::string::String> as Clone>::clone(&song.filepath).unwrap(); let filename =
&<std::option::Option<std::string::String> as Clone>::clone(&song.filepath).unwrap();
// let directory = &<std::option::Option<std::string::String> as Clone>::clone(&self.directory).unwrap(); // let directory = &<std::option::Option<std::string::String> as Clone>::clone(&self.directory).unwrap();
let trd = filename.contains("trackd"); let trd = filename.contains("trackd");
@@ -202,9 +222,8 @@ impl CommitManager {
} }
// let t = &filename[1..5]; // let t = &filename[1..5];
} }
}, }
2 => { 2 => {}
},
_ => println!(""), _ => println!(""),
} }
+1 -1
View File
@@ -1,4 +1,4 @@
pub mod action_managers; pub mod action_managers;
pub mod commit_manager; pub mod commit_manager;
pub mod user_manager;
pub mod token_manager; pub mod token_manager;
pub mod user_manager;
+1 -2
View File
@@ -7,7 +7,6 @@ pub struct TokenManager {
pub api: models::api::API, pub api: models::api::API,
} }
impl TokenManager { impl TokenManager {
pub fn request_token(&self) -> models::token::Token { pub fn request_token(&self) -> models::token::Token {
let usr_json = self.user.to_json(); let usr_json = self.user.to_json();
@@ -29,4 +28,4 @@ impl TokenManager {
return endpoint; return endpoint;
} }
} }
-1
View File
@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
use crate::models; use crate::models;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct UserManager { pub struct UserManager {
pub user: models::user::User, pub user: models::user::User,
+1 -2
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct API { pub struct API {
pub url: String, pub url: String,
@@ -18,4 +17,4 @@ impl Default for API {
version: String::from(""), version: String::from(""),
} }
} }
} }
-1
View File
@@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};
use crate::models; use crate::models;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IcarusAction { pub struct IcarusAction {
pub action: String, pub action: String,
+5 -4
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Song { pub struct Song {
pub id: Option<i32>, pub id: Option<i32>,
@@ -46,16 +45,18 @@ impl Song {
} }
pub fn song_path(&self) -> String { pub fn song_path(&self) -> String {
let directory = &<std::option::Option<std::string::String> as Clone>::clone(&self.directory).unwrap(); let directory =
&<std::option::Option<std::string::String> as Clone>::clone(&self.directory).unwrap();
let mut buffer: String = directory.to_string(); let mut buffer: String = directory.to_string();
let count = buffer.len(); let count = buffer.len();
if buffer.chars().nth(count-1) != Some('/') { if buffer.chars().nth(count - 1) != Some('/') {
buffer += "/"; buffer += "/";
} }
let filename = &<std::option::Option<std::string::String> as Clone>::clone(&self.filepath).unwrap(); let filename =
&<std::option::Option<std::string::String> as Clone>::clone(&self.filepath).unwrap();
buffer += filename; buffer += filename;
return buffer; return buffer;
-1
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct Token { pub struct Token {
pub access_token: Option<String>, pub access_token: Option<String>,
+1 -2
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct UploadForm { pub struct UploadForm {
pub url: Option<String>, pub url: Option<String>,
@@ -16,4 +15,4 @@ impl Default for UploadForm {
filepath: None, filepath: None,
} }
} }
} }
+1 -2
View File
@@ -1,4 +1,3 @@
use crate::models; use crate::models;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@@ -36,4 +35,4 @@ impl APIParser {
self.api.version = "v1".to_string(); self.api.version = "v1".to_string();
} }
} }
+1 -1
View File
@@ -1 +1 @@
pub mod api_parser; pub mod api_parser;
+3 -5
View File
@@ -1,10 +1,8 @@
use crate::models; use crate::models;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Delete { pub struct Delete {}
}
impl Delete { impl Delete {
pub fn delete_song(&self, token: &models::token::Token, song: &models::song::Song) { pub fn delete_song(&self, token: &models::token::Token, song: &models::song::Song) {}
} }
}
+1
View File
@@ -0,0 +1 @@
+1 -1
View File
@@ -2,4 +2,4 @@ pub mod delete;
pub mod download; pub mod download;
pub mod retrieve_records; pub mod retrieve_records;
pub mod syncer_base; pub mod syncer_base;
pub mod upload; pub mod upload;
+1
View File
@@ -0,0 +1 @@
+2 -4
View File
@@ -1,8 +1,6 @@
use crate::models; use crate::models;
struct Syncer { struct Syncer {}
}
impl Syncer { impl Syncer {
pub fn retrieve_url(api: &models::api::API, song: &models::song::Song) -> String { pub fn retrieve_url(api: &models::api::API, song: &models::song::Song) -> String {
@@ -16,4 +14,4 @@ impl Syncer {
return url; return url;
} }
} }
+1
View File
@@ -0,0 +1 @@
+16 -8
View File
@@ -1,8 +1,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct Checks { pub struct Checks {}
}
impl Checks { impl Checks {
pub fn is_numeric(text: &String) -> bool { pub fn is_numeric(text: &String) -> bool {
@@ -10,20 +9,29 @@ impl Checks {
} }
// TODO: Implement // TODO: Implement
pub fn item_in_container(container: &Vec<String>, item: &String, pub fn item_in_container(
func: fn(a: &String, b: &String) -> String) -> String { container: &Vec<String>,
item: &String,
func: fn(a: &String, b: &String) -> String,
) -> String {
return String::from(""); return String::from("");
} }
// TODO: Implement // TODO: Implement
pub fn item_iter_in_container(container: &Vec<String>, item: &String, pub fn item_iter_in_container(
func: fn(a: &String, b: &String) -> String) -> String { container: &Vec<String>,
item: &String,
func: fn(a: &String, b: &String) -> String,
) -> String {
return String::from(""); return String::from("");
} }
// TODO: Implement // TODO: Implement
pub fn index_of_item_in_container(container: &String, item: &char, pub fn index_of_item_in_container(
func: fn(a: &char, b: &char) -> bool) -> i32 { container: &String,
item: &char,
func: fn(a: &char, b: &char) -> bool,
) -> i32 {
let mut index = -1; let mut index = -1;
for c in container.chars() { for c in container.chars() {
+2 -5
View File
@@ -1,9 +1,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct Conversions { pub struct Conversions {}
}
impl Conversions { impl Conversions {
pub fn to_lower_char(val: &mut char) { pub fn to_lower_char(val: &mut char) {
@@ -12,8 +10,7 @@ impl Conversions {
} }
} }
pub fn initialize_values(&self) { pub fn initialize_values(&self) {}
}
pub fn print_value<T: std::fmt::Debug>(&self, val: T) { pub fn print_value<T: std::fmt::Debug>(&self, val: T) {
println!("Going to print value"); println!("Going to print value");
+1 -1
View File
@@ -1,2 +1,2 @@
pub mod checks; pub mod checks;
pub mod conversions; pub mod conversions;