Cargo formatting
This commit is contained in:
+9
-7
@@ -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(),
|
||||
@@ -78,10 +80,10 @@ fn main() {
|
||||
chosen_act.print_action_and_flags();
|
||||
|
||||
let cmt_mgr = managers::commit_manager::CommitManager {
|
||||
// action: String::from(""),
|
||||
// flags: Vec::new(),
|
||||
// params: Vec::new(),
|
||||
// param_count: 1,
|
||||
// action: String::from(""),
|
||||
// flags: Vec::new(),
|
||||
// params: Vec::new(),
|
||||
// param_count: 1,
|
||||
ica_action: chosen_act,
|
||||
};
|
||||
|
||||
|
||||
@@ -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,16 +55,22 @@ 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();
|
||||
|
||||
if self.is_valid_flag(flag) && self.does_flag_have_value(flag) {
|
||||
println!("Flag has value");
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -35,19 +34,21 @@ impl Default for Album {
|
||||
album_artist: String::new(),
|
||||
genre: String::new(),
|
||||
year: 0,
|
||||
track_count: 0,
|
||||
track_count: 0,
|
||||
disc_count: 0,
|
||||
songs: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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,36 +112,42 @@ 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 {
|
||||
user: models::user::User {
|
||||
username: String::new(),
|
||||
password: String::new(),
|
||||
},
|
||||
ica_action: self.ica_action.clone(),
|
||||
};
|
||||
let mut usr_mgr: managers::user_manager::UserManager =
|
||||
managers::user_manager::UserManager {
|
||||
user: models::user::User {
|
||||
username: String::new(),
|
||||
password: String::new(),
|
||||
},
|
||||
ica_action: self.ica_action.clone(),
|
||||
};
|
||||
|
||||
let usr = usr_mgr.retrieve_user();
|
||||
let tok_mgr = managers::token_manager::TokenManager {
|
||||
@@ -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
@@ -1,4 +1,4 @@
|
||||
pub mod action_managers;
|
||||
pub mod commit_manager;
|
||||
pub mod user_manager;
|
||||
pub mod token_manager;
|
||||
pub mod user_manager;
|
||||
|
||||
@@ -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();
|
||||
@@ -29,4 +28,4 @@ impl TokenManager {
|
||||
|
||||
return endpoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models;
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct UserManager {
|
||||
pub user: models::user::User,
|
||||
|
||||
+1
-2
@@ -2,7 +2,6 @@ use std::default::Default;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct API {
|
||||
pub url: String,
|
||||
@@ -18,4 +17,4 @@ impl Default for API {
|
||||
version: String::from(""),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models;
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct IcarusAction {
|
||||
pub action: String,
|
||||
|
||||
+5
-4
@@ -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,16 +45,18 @@ 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();
|
||||
|
||||
if buffer.chars().nth(count-1) != Some('/') {
|
||||
if buffer.chars().nth(count - 1) != Some('/') {
|
||||
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;
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::default::Default;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Token {
|
||||
pub access_token: Option<String>,
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::default::Default;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct UploadForm {
|
||||
pub url: Option<String>,
|
||||
@@ -16,4 +15,4 @@ impl Default for UploadForm {
|
||||
filepath: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
use crate::models;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -36,4 +35,4 @@ impl APIParser {
|
||||
|
||||
self.api.version = "v1".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
pub mod api_parser;
|
||||
pub mod api_parser;
|
||||
|
||||
@@ -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) {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ pub mod delete;
|
||||
pub mod download;
|
||||
pub mod retrieve_records;
|
||||
pub mod syncer_base;
|
||||
pub mod upload;
|
||||
pub mod upload;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
@@ -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 {
|
||||
@@ -16,4 +14,4 @@ impl Syncer {
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
+16
-8
@@ -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() {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod checks;
|
||||
pub mod conversions;
|
||||
pub mod conversions;
|
||||
|
||||
Reference in New Issue
Block a user