Refactoring code
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
|
||||||
|
pub fn print_help() {
|
||||||
|
let msg: String = String::from(
|
||||||
|
r#"icd [Action] [flag]
|
||||||
|
|
||||||
|
Actions
|
||||||
|
download
|
||||||
|
upload-meta
|
||||||
|
retrieve
|
||||||
|
delete
|
||||||
|
|
||||||
|
Flags
|
||||||
|
Required for all actions
|
||||||
|
-u username
|
||||||
|
-p password
|
||||||
|
-h host
|
||||||
|
|
||||||
|
Required for upload with metadata
|
||||||
|
-s path of song
|
||||||
|
-t track number
|
||||||
|
-m metadata filepath
|
||||||
|
-ca coverart filepath
|
||||||
|
-scma directory where songs, metadata, and cover art exists and will be uploaded (Optional)
|
||||||
|
|
||||||
|
Required for download
|
||||||
|
-b song id
|
||||||
|
-d path to download song (Optional)
|
||||||
|
|
||||||
|
Required for retrieving records
|
||||||
|
-rt retrieve type (songs is only accepted)
|
||||||
|
|
||||||
|
Required for deleting a song
|
||||||
|
-D song id"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{}", msg);
|
||||||
|
}
|
||||||
+13
-14
@@ -1,4 +1,5 @@
|
|||||||
mod constants;
|
mod constants;
|
||||||
|
mod help;
|
||||||
mod managers;
|
mod managers;
|
||||||
mod models;
|
mod models;
|
||||||
mod parsers;
|
mod parsers;
|
||||||
@@ -6,12 +7,15 @@ mod syncers;
|
|||||||
mod utilities;
|
mod utilities;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process;
|
// use std::process;
|
||||||
|
|
||||||
|
/*
|
||||||
fn exit_program(code: i32) {
|
fn exit_program(code: i32) {
|
||||||
process::exit(code);
|
process::exit(code);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
fn print_help() {
|
fn print_help() {
|
||||||
let msg: String = String::from(
|
let msg: String = String::from(
|
||||||
r#"icd [Action] [flag]
|
r#"icd [Action] [flag]
|
||||||
@@ -48,29 +52,24 @@ fn print_help() {
|
|||||||
|
|
||||||
println!("{}", msg);
|
println!("{}", msg);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
if args.len() == 1 {
|
|
||||||
print_help();
|
|
||||||
exit_program(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let args_len = args.len() as i32;
|
let args_len = args.len() as i32;
|
||||||
|
|
||||||
|
if args_len == 1 {
|
||||||
|
help::print_help();
|
||||||
|
utilities::checks::exit_program(-1);
|
||||||
|
}
|
||||||
|
|
||||||
println!("Argument count: {}", args_len);
|
println!("Argument count: {}", args_len);
|
||||||
|
|
||||||
let mut act_mgr = managers::action_managers::ActionManager {
|
let mut act_mgr = managers::action_managers::ActionManager::default();
|
||||||
action: String::new(),
|
act_mgr.set_params(&args);
|
||||||
flags: Vec::new(),
|
|
||||||
params: args,
|
|
||||||
param_count: args_len,
|
|
||||||
};
|
|
||||||
act_mgr.initialize();
|
act_mgr.initialize();
|
||||||
|
|
||||||
let chosen_act = act_mgr.retrieve_icarus_action();
|
let chosen_act = act_mgr.retrieve_icarus_action();
|
||||||
|
|
||||||
chosen_act.print_action_and_flags();
|
chosen_act.print_action_and_flags();
|
||||||
|
|
||||||
let mut cmt_mgr = managers::commit_manager::CommitManager {
|
let mut cmt_mgr = managers::commit_manager::CommitManager {
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ pub struct ActionManager {
|
|||||||
pub param_count: i32,
|
pub param_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ActionManager {
|
||||||
|
fn default() -> Self {
|
||||||
|
ActionManager {
|
||||||
|
action: String::new(),
|
||||||
|
flags: Vec::new(),
|
||||||
|
params: Vec::new(),
|
||||||
|
param_count: -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActionManager {
|
impl ActionManager {
|
||||||
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
|
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
|
||||||
return models::icarus_action::IcarusAction {
|
return models::icarus_action::IcarusAction {
|
||||||
@@ -45,6 +56,11 @@ impl ActionManager {
|
|||||||
self.action = self.action.to_lowercase();
|
self.action = self.action.to_lowercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_params(&mut self, args: &Vec<String>) {
|
||||||
|
self.params = args.clone();
|
||||||
|
self.param_count = self.params.len() as i32;
|
||||||
|
}
|
||||||
|
|
||||||
fn validate_flags(&mut self) {
|
fn validate_flags(&mut self) {
|
||||||
println!("Validating flags");
|
println!("Validating flags");
|
||||||
|
|
||||||
@@ -102,7 +118,6 @@ impl ActionManager {
|
|||||||
|
|
||||||
fn does_flag_have_value(&self, flag: &String) -> bool {
|
fn does_flag_have_value(&self, flag: &String) -> bool {
|
||||||
let flags_tmp = self.parsed_flags();
|
let flags_tmp = self.parsed_flags();
|
||||||
|
|
||||||
let mut i_found: i32 = -1;
|
let mut i_found: i32 = -1;
|
||||||
|
|
||||||
for i in 0..flags_tmp.len() {
|
for i in 0..flags_tmp.len() {
|
||||||
|
|||||||
@@ -26,3 +26,8 @@ impl Checks {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn exit_program(code: i32) {
|
||||||
|
std::process::exit(code);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user