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