error handling improved, start with env
parent
441ce5c630
commit
42aa8228b8
|
@ -35,11 +35,15 @@ pub enum Commands {
|
|||
},
|
||||
Page {
|
||||
// #[arg(short, long)]
|
||||
page_id: usize
|
||||
page_id: usize,
|
||||
},
|
||||
Job {
|
||||
job_id: usize,
|
||||
#[arg(short, long)]
|
||||
log: bool,
|
||||
}
|
||||
},
|
||||
Env {
|
||||
env: Option<String>,
|
||||
target: Option<String>,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::{
|
|||
container,
|
||||
database::db::Db,
|
||||
service::{
|
||||
file_service::FileService, filter_service::FilterService, job_service::JobService,
|
||||
merchant_service::MerchantService, schema_service::SchemaService,
|
||||
env_service::EnvService, file_service::FileService, filter_service::FilterService,
|
||||
job_service::JobService, merchant_service::MerchantService, schema_service::SchemaService,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -21,11 +21,11 @@ pub fn process_args(args: Cli, db: Db) -> Result<(), Box<dyn std::error::Error>>
|
|||
match args.mode {
|
||||
Commands::Merch { search } => {
|
||||
let mut merchant_service: MerchantService = container::get_merchant_service(db);
|
||||
merchant_service.get_merchant(&search.ok_or(CommandError::EmptySearch())?);
|
||||
merchant_service.get_merchant(&search.ok_or(CommandError::EmptySearch())?)?;
|
||||
}
|
||||
Commands::Schema { search } => {
|
||||
let mut schema_service: SchemaService = container::get_schema_service(db);
|
||||
schema_service.get_columns(&search.ok_or(CommandError::EmptySearch())?)
|
||||
schema_service.get_columns(&search.ok_or(CommandError::EmptySearch())?)?;
|
||||
}
|
||||
Commands::Filter {
|
||||
filter_id,
|
||||
|
@ -35,25 +35,30 @@ pub fn process_args(args: Cli, db: Db) -> Result<(), Box<dyn std::error::Error>>
|
|||
} => {
|
||||
let mut filter_service: FilterService = container::get_filter_service(db);
|
||||
if config {
|
||||
filter_service.get_filter_configs(&filter_id)
|
||||
filter_service.get_filter_configs(&filter_id)?;
|
||||
} else if log {
|
||||
filter_service.get_filter_log(&filter_id, all)
|
||||
filter_service.get_filter_log(&filter_id, all)?;
|
||||
} else {
|
||||
filter_service.get_filter(&filter_id, all)
|
||||
filter_service.get_filter(&filter_id, all)?;
|
||||
}
|
||||
}
|
||||
Commands::Page { page_id } => {
|
||||
let mut file_service: FileService = container::get_page_service(db);
|
||||
file_service.get_page(&page_id);
|
||||
file_service.get_page(&page_id)?;
|
||||
}
|
||||
Commands::Job { job_id, log } => {
|
||||
let mut job_service: JobService = container::get_job_service(db);
|
||||
if log {
|
||||
job_service.get_job_log(&job_id);
|
||||
job_service.get_job_log(&job_id)?;
|
||||
} else {
|
||||
job_service.get_job_by_id(&job_id);
|
||||
job_service.get_job_by_id(&job_id)?;
|
||||
}
|
||||
}
|
||||
Commands::Env { env, target } => {
|
||||
EnvService::set_environment()?;
|
||||
|
||||
println!("{:?}, {:?}", env, target);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -12,25 +12,25 @@ use crate::{
|
|||
|
||||
pub fn get_filter_service(pool: Db) -> FilterService {
|
||||
let repo = FilterRepo::new(pool);
|
||||
return FilterService::new(repo);
|
||||
FilterService::new(repo)
|
||||
}
|
||||
|
||||
pub fn get_merchant_service(pool: Db) -> MerchantService {
|
||||
let repo = MerchantRepo::new(pool);
|
||||
return MerchantService::new(repo);
|
||||
MerchantService::new(repo)
|
||||
}
|
||||
|
||||
pub fn get_schema_service(pool: Db) -> SchemaService {
|
||||
let repo = SchemaRepo::new(pool);
|
||||
return SchemaService::new(repo);
|
||||
SchemaService::new(repo)
|
||||
}
|
||||
|
||||
pub fn get_page_service(pool: Db) -> FileService {
|
||||
let repo = FileRepo::new(pool);
|
||||
return FileService::new(repo);
|
||||
FileService::new(repo)
|
||||
}
|
||||
|
||||
pub(crate) fn get_job_service(pool: Db) -> JobService {
|
||||
let repo = JobRepo::new(pool);
|
||||
return JobService::new(repo);
|
||||
JobService::new(repo)
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@ impl FileService {
|
|||
Self { repo }
|
||||
}
|
||||
|
||||
pub fn get_page(&mut self, page_id: &usize) {
|
||||
let result = self.repo.find_page(page_id);
|
||||
pub fn get_page(&mut self, page_id: &usize) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let page = self.repo.find_page(page_id)?;
|
||||
|
||||
match result {
|
||||
Ok(page) => {
|
||||
if page.is_empty() {
|
||||
println!("No page found.");
|
||||
} else {
|
||||
|
@ -29,8 +27,6 @@ impl FileService {
|
|||
});
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,13 @@ impl FilterService {
|
|||
Self { repo }
|
||||
}
|
||||
|
||||
pub fn get_filter(&mut self, filter_id: &usize, all: bool) {
|
||||
let result = self.repo.find_by_id(filter_id);
|
||||
pub fn get_filter(
|
||||
&mut self,
|
||||
filter_id: &usize,
|
||||
all: bool,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let filters = self.repo.find_by_id(filter_id)?;
|
||||
|
||||
match result {
|
||||
Ok(filters) => {
|
||||
if filters.is_empty() {
|
||||
println!("Filter not found!");
|
||||
} else {
|
||||
|
@ -35,21 +37,21 @@ impl FilterService {
|
|||
});
|
||||
|
||||
if all {
|
||||
self.get_filter_configs(filter_id)
|
||||
self.get_filter_configs(filter_id)?
|
||||
} else {
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_filter_configs(&mut self, filter_id: &usize) {
|
||||
let result = self.repo.find_filter_configs(filter_id);
|
||||
pub fn get_filter_configs(
|
||||
&mut self,
|
||||
filter_id: &usize,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let filter_configs = self.repo.find_filter_configs(filter_id)?;
|
||||
|
||||
match result {
|
||||
Ok(filter_configs) => {
|
||||
if filter_configs.is_empty() {
|
||||
println!("No filter configs found!");
|
||||
} else {
|
||||
|
@ -67,16 +69,17 @@ impl FilterService {
|
|||
);
|
||||
});
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_filter_log(&mut self, filter_id: &usize, all: bool) {
|
||||
let result = self.repo.find_filter_log(filter_id);
|
||||
match result {
|
||||
Ok(filter_log) => {
|
||||
pub fn get_filter_log(
|
||||
&mut self,
|
||||
filter_id: &usize,
|
||||
all: bool,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let filter_log = self.repo.find_filter_log(filter_id)?;
|
||||
if filter_log.is_empty() {
|
||||
println!("No filter log found!");
|
||||
} else {
|
||||
|
@ -113,8 +116,7 @@ impl FilterService {
|
|||
println!("{}", "-".repeat(self.get_width()));
|
||||
})
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,13 @@ impl JobService {
|
|||
Self { repo }
|
||||
}
|
||||
|
||||
pub fn get_job_by_id(&mut self, job_id: &usize) {
|
||||
let result = self.repo.find_by_id(job_id);
|
||||
pub fn get_job_by_id(&mut self, job_id: &usize) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let result = self.repo.find_by_id(job_id)?;
|
||||
|
||||
match result {
|
||||
Ok(job) => {
|
||||
if job.is_empty() {
|
||||
if result.is_empty() {
|
||||
println!("Job not found!");
|
||||
} else {
|
||||
job.into_iter().for_each(|job: Job| {
|
||||
result.into_iter().for_each(|job: Job| {
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
println!("FileName: {}", job.file_name);
|
||||
println!("Description: {}", job.description);
|
||||
|
@ -32,27 +30,23 @@ impl JobService {
|
|||
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_job_log(&mut self, job_id: &usize) {
|
||||
let result = self.repo.find_log(job_id);
|
||||
pub fn get_job_log(&mut self, job_id: &usize) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let result = self.repo.find_log(job_id)?;
|
||||
|
||||
match result {
|
||||
Ok(joblog) => {
|
||||
if joblog.is_empty() {
|
||||
if result.is_empty() {
|
||||
println!("Job log not found!");
|
||||
} else {
|
||||
joblog.into_iter().for_each(|joblog: JobLog| {
|
||||
result.into_iter().for_each(|joblog: JobLog| {
|
||||
println!("{0: <25} | {1: <20} ", joblog.upd_ts, joblog.content,);
|
||||
});
|
||||
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@ impl MerchantService {
|
|||
Self { repo }
|
||||
}
|
||||
|
||||
pub fn get_merchant(&mut self, search: &str) {
|
||||
let merchants = self.repo.find_by_name_or_id(search);
|
||||
pub fn get_merchant(&mut self, search: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let merchants = self.repo.find_by_name_or_id(search)?;
|
||||
|
||||
match merchants {
|
||||
Ok(merchants) => {
|
||||
if merchants.is_empty() {
|
||||
println!("Merchant not found!");
|
||||
}
|
||||
|
@ -28,8 +26,7 @@ impl MerchantService {
|
|||
});
|
||||
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod env_service;
|
||||
pub mod file_service;
|
||||
pub mod filter_service;
|
||||
pub mod job_service;
|
||||
pub mod merchant_service;
|
||||
pub mod schema_service;
|
||||
pub mod filter_service;
|
||||
pub mod file_service;
|
||||
pub mod job_service;
|
||||
|
|
|
@ -12,11 +12,9 @@ impl SchemaService {
|
|||
pub fn new(repo: SchemaRepo) -> Self {
|
||||
Self { repo }
|
||||
}
|
||||
pub fn get_columns(&mut self, column: &str) {
|
||||
let columns = self.repo.find_by_column(column);
|
||||
pub fn get_columns(&mut self, column: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let columns = self.repo.find_by_column(column)?;
|
||||
|
||||
match columns {
|
||||
Ok(columns) => {
|
||||
if columns.is_empty() {
|
||||
println!("No column found!");
|
||||
} else {
|
||||
|
@ -28,8 +26,7 @@ impl SchemaService {
|
|||
});
|
||||
println!("{}", "-".repeat(self.get_width()));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{err}"),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue