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
+5 -3
View File
@@ -1,8 +1,8 @@
mod managers;
mod models;
mod utilities;
mod parsers;
mod syncers;
mod utilities;
use std::env;
use std::process;
@@ -17,7 +17,7 @@ fn print_help() {
Actions
download
upload
upload (Search NOTE)
upload-meta
retrieve
delete
@@ -58,13 +58,15 @@ fn print_help() {
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() == 0 {
if args.len() == 1 {
print_help();
exit_program(-1);
}
let args_len = args.len() as i32;
println!("Argument count: {}", args_len);
let mut act_mgr = managers::action_managers::ActionManager {
action: String::from(""),
flags: Vec::new(),
+20 -3
View File
@@ -19,7 +19,8 @@ impl ActionManager {
}
fn supported_flags(&self) -> Vec<String> {
return vec![String::from("-u"),
return vec![
String::from("-u"),
String::from("-p"),
String::from("-t"),
String::from("-h"),
@@ -45,6 +46,7 @@ impl ActionManager {
pub fn initialize(&mut self) {
self.validate_flags();
self.validate_action();
self.action = self.action.to_lowercase();
}
@@ -53,9 +55,12 @@ impl ActionManager {
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];
println!("Value: {}", flag);
println!("Index: {} | Value: {}", i, flag);
let mut flg = models::flags::Flags::default();
@@ -63,6 +68,9 @@ impl ActionManager {
println!("Flag has value");
flg.flag = String::from(flag);
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) {
println!("Flag does not have a value");
flg.flag = String::from(flag);
@@ -72,6 +80,15 @@ impl ActionManager {
}
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);
}
}
+40 -21
View File
@@ -1,5 +1,5 @@
use std::default::Default;
use std::collections::HashMap;
use std::default::Default;
use serde::{Deserialize, Serialize};
@@ -17,7 +17,6 @@ pub struct CommitManager {
pub ica_action: models::icarus_action::IcarusAction,
}
pub struct Album {
pub title: String,
pub album_artist: String,
@@ -42,12 +41,14 @@ impl Default for Album {
}
}
#[derive(Clone, Debug)]
enum ActionValues {
DeleteAct,
DownloadAct,
RetrieveAct,
UploadAct,
UploadSongWithMetadata,
None,
}
enum RetrieveTypes {
@@ -66,28 +67,38 @@ impl Album {
}
impl CommitManager {
pub fn commit_action(&self) {
let action = &self.ica_action.action;
println!("Committing {} action", action);
match self.map_actions()[action] {
ActionValues::DeleteAct => self.delete_song(),
ActionValues::DownloadAct => self.download_song(),
ActionValues::RetrieveAct => self.retrieve_object(),
ActionValues::UploadAct => self.upload_song(),
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata(),
_ => {
println!("Nothing good here");
let mapped_actions = self.map_actions();
let mapped_action = self.find_mapped_action(&mapped_actions, action);
println!("{:?}", mapped_action);
}
fn find_mapped_action(
&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> {
let mut actions: HashMap<String, ActionValues> = HashMap::new();
actions.insert("download".to_string(), ActionValues::DownloadAct);
actions.insert("upload".to_string(), ActionValues::UploadAct);
actions.insert("upload-meta".to_string(), ActionValues::UploadSongWithMetadata);
// actions.insert("upload".to_string(), ActionValues::UploadAct);
actions.insert(
"upload-meta".to_string(),
ActionValues::UploadSongWithMetadata,
);
actions.insert("retrieve".to_string(), ActionValues::RetrieveAct);
actions.insert("delete".to_string(), ActionValues::DeleteAct);
@@ -101,30 +112,36 @@ impl CommitManager {
api: models::api::API::default(),
};
println!("Deleting song");
let api = prsr.retrieve_api();
let song = models::song::Song::default();
for arg in &self.ica_action.flags {
}
for arg in &self.ica_action.flags {}
}
// TODO: Implement
fn download_song(&self) {
println!("Deleting song");
}
// TODO: Implement
fn retrieve_object(&self) {
println!("Deleting song");
}
// TODO: Implement
// NOTE: Might not need to implement. I will see how this goes
fn upload_song(&self) {
println!("Deleting song");
}
fn parse_token(&self, api: &models::api::API) -> models::token::Token {
println!("Fetching token");
let mut usr_mgr: managers::user_manager::UserManager = managers::user_manager::UserManager {
let mut usr_mgr: managers::user_manager::UserManager =
managers::user_manager::UserManager {
user: models::user::User {
username: String::new(),
password: String::new(),
@@ -141,7 +158,9 @@ impl CommitManager {
return tok_mgr.request_token();
}
// TODO: Implement
fn upload_song_with_metadata(&self) {}
fn upload_song_with_metadata(&self) {
println!("Deleting song");
}
// TODO: Implement
fn sing_target_upload(
&self,
@@ -162,7 +181,8 @@ impl CommitManager {
let track = 1;
let mut mode = 0;
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 trd = filename.contains("trackd");
@@ -202,9 +222,8 @@ impl CommitManager {
}
// let t = &filename[1..5];
}
},
2 => {
},
}
2 => {}
_ => println!(""),
}
+1 -1
View File
@@ -1,4 +1,4 @@
pub mod action_managers;
pub mod commit_manager;
pub mod user_manager;
pub mod token_manager;
pub mod user_manager;
-1
View File
@@ -7,7 +7,6 @@ pub struct TokenManager {
pub api: models::api::API,
}
impl TokenManager {
pub fn request_token(&self) -> models::token::Token {
let usr_json = self.user.to_json();
-1
View File
@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
use crate::models;
#[derive(Debug, Deserialize, Serialize)]
pub struct UserManager {
pub user: models::user::User,
-1
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct API {
pub url: String,
-1
View File
@@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};
use crate::models;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IcarusAction {
pub action: String,
+4 -3
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Song {
pub id: Option<i32>,
@@ -46,7 +45,8 @@ impl Song {
}
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 count = buffer.len();
@@ -55,7 +55,8 @@ impl Song {
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;
return buffer;
-1
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Token {
pub access_token: Option<String>,
-1
View File
@@ -2,7 +2,6 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct UploadForm {
pub url: Option<String>,
-1
View File
@@ -1,4 +1,3 @@
use crate::models;
#[derive(Clone, Debug)]
+2 -4
View File
@@ -1,10 +1,8 @@
use crate::models;
#[derive(Clone, Debug)]
pub struct Delete {
}
pub struct 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
View File
@@ -0,0 +1 @@
+1 -3
View File
@@ -1,8 +1,6 @@
use crate::models;
struct Syncer {
}
struct Syncer {}
impl Syncer {
pub fn retrieve_url(api: &models::api::API, song: &models::song::Song) -> String {
+1
View File
@@ -0,0 +1 @@
+16 -8
View File
@@ -1,8 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Checks {
}
pub struct Checks {}
impl Checks {
pub fn is_numeric(text: &String) -> bool {
@@ -10,20 +9,29 @@ impl Checks {
}
// TODO: Implement
pub fn item_in_container(container: &Vec<String>, item: &String,
func: fn(a: &String, b: &String) -> String) -> String {
pub fn item_in_container(
container: &Vec<String>,
item: &String,
func: fn(a: &String, b: &String) -> String,
) -> String {
return String::from("");
}
// TODO: Implement
pub fn item_iter_in_container(container: &Vec<String>, item: &String,
func: fn(a: &String, b: &String) -> String) -> String {
pub fn item_iter_in_container(
container: &Vec<String>,
item: &String,
func: fn(a: &String, b: &String) -> String,
) -> String {
return String::from("");
}
// TODO: Implement
pub fn index_of_item_in_container(container: &String, item: &char,
func: fn(a: &char, b: &char) -> bool) -> i32 {
pub fn index_of_item_in_container(
container: &String,
item: &char,
func: fn(a: &char, b: &char) -> bool,
) -> i32 {
let mut index = -1;
for c in container.chars() {
+2 -5
View File
@@ -1,9 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Conversions {
}
pub struct Conversions {}
impl Conversions {
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) {
println!("Going to print value");