Lint the shit out of the project.
This commit is contained in:
1 parent
920ab5d188
commit
af11915a52
9 files changed
+92
-61
No files matched your search
+62
-33
@@ -1,7 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
||||
use clap::parser::ValuesRef;
|
||||
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
|
||||
use log::{debug, error, info};
|
||||
use rusqlite::Connection;
|
||||
use serde::Serialize;
|
||||
@@ -38,15 +38,29 @@ impl<T> Output<T> {
|
||||
}
|
||||
|
||||
trait CommandLineUserLogic {
|
||||
fn create_user(&mut self, conn: &mut Connection, name: &String, public_key: &String) -> CustomResult<()>;
|
||||
fn create_user(
|
||||
&mut self,
|
||||
conn: &mut Connection,
|
||||
name: &String,
|
||||
public_key: &String,
|
||||
) -> CustomResult<()>;
|
||||
|
||||
fn list_user(&mut self, conn: &Connection) -> CustomResult<()>;
|
||||
|
||||
fn list_securities(&mut self, conn: &Connection) -> CustomResult<()>;
|
||||
|
||||
fn process_events(&mut self, conn: &mut Connection, files: ValuesRef<PathBuf>) -> CustomResult<()>;
|
||||
fn process_events(
|
||||
&mut self,
|
||||
conn: &mut Connection,
|
||||
files: ValuesRef<PathBuf>,
|
||||
) -> CustomResult<()>;
|
||||
|
||||
fn run_webui(&mut self, conn: &mut Connection, port: u16, enable_template_autoreload: bool) -> CustomResult<()>;
|
||||
fn run_webui(
|
||||
&mut self,
|
||||
conn: &mut Connection,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool,
|
||||
) -> CustomResult<()>;
|
||||
}
|
||||
|
||||
fn verbosity_arg() -> Arg {
|
||||
@@ -190,7 +204,7 @@ fn process_list_user_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing list users command line {:?}.", m);
|
||||
logic.list_user(conn)
|
||||
}
|
||||
@@ -202,9 +216,7 @@ fn process_user_command_line(
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing user command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("new", new_user_match)) => {
|
||||
process_new_user_command_line(conn, new_user_match, logic)
|
||||
}
|
||||
Some(("new", new_user_match)) => process_new_user_command_line(conn, new_user_match, logic),
|
||||
Some(("ls", list_user_match)) => {
|
||||
process_list_user_command_line(conn, list_user_match, logic)
|
||||
}
|
||||
@@ -216,7 +228,7 @@ fn process_list_securities_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing list securities command line {:?}.", m);
|
||||
logic.list_securities(conn)
|
||||
}
|
||||
@@ -230,7 +242,9 @@ fn process_process_events_command_line(
|
||||
let mut files = m.get_many::<PathBuf>("PATH").unwrap();
|
||||
if files.any(|x| !x.exists()) {
|
||||
error!("Some passed files do not exists. Existing right now.");
|
||||
return Err(Error::UserInputError("Some passed files do not exists. Existing right now.".to_string()));
|
||||
return Err(Error::UserInputError(
|
||||
"Some passed files do not exists. Existing right now.".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
logic.process_events(conn, files)
|
||||
@@ -240,7 +254,7 @@ fn process_run_wui_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()> {
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing run wui command line {:?}.", m);
|
||||
let port = m.get_one::<u16>("port").unwrap_or(&2222);
|
||||
let enable_template_autoreload = m.get_flag("enable-template-autoreload");
|
||||
@@ -251,7 +265,7 @@ fn process_securities_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing securities command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("ls", list_securities_match)) => {
|
||||
@@ -265,7 +279,7 @@ fn process_events_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()>{
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing events command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("process", process_events_match)) => {
|
||||
@@ -279,12 +293,10 @@ fn process_wui_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) -> CustomResult<()> {
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing wui command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("run", run_wui_match)) => {
|
||||
process_run_wui_command_line(conn, run_wui_match, logic)
|
||||
}
|
||||
Some(("run", run_wui_match)) => process_run_wui_command_line(conn, run_wui_match, logic),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -296,18 +308,12 @@ fn process_command_line(
|
||||
) -> CustomResult<()> {
|
||||
debug!("Processing command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("users", user_match)) => {
|
||||
process_user_command_line(conn, user_match, logic)
|
||||
}
|
||||
Some(("users", user_match)) => process_user_command_line(conn, user_match, logic),
|
||||
Some(("securities", securities_match)) => {
|
||||
process_securities_command_line(conn, securities_match, logic)
|
||||
}
|
||||
Some(("events", events_match)) => {
|
||||
process_events_command_line(conn, events_match, logic)
|
||||
}
|
||||
Some(("wui", wui_match)) => {
|
||||
process_wui_command_line(conn, wui_match, logic)
|
||||
}
|
||||
Some(("events", events_match)) => process_events_command_line(conn, events_match, logic),
|
||||
Some(("wui", wui_match)) => process_wui_command_line(conn, wui_match, logic),
|
||||
_ => {
|
||||
println!("Received un parsable command. {:?}", m.subcommand());
|
||||
unreachable!();
|
||||
@@ -340,22 +346,31 @@ mod cli_test {
|
||||
}
|
||||
|
||||
impl CommandLineUserLogic for TestCommandLineLogic {
|
||||
fn create_user(&mut self, _conn: &mut Connection, _name: &String, _public_key: &String) -> CustomResult<()> {
|
||||
fn create_user(
|
||||
&mut self,
|
||||
_conn: &mut Connection,
|
||||
_name: &String,
|
||||
_public_key: &String,
|
||||
) -> CustomResult<()> {
|
||||
self.create_user_count += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_user(&mut self, _conn: &Connection) -> CustomResult<()>{
|
||||
fn list_user(&mut self, _conn: &Connection) -> CustomResult<()> {
|
||||
self.list_user_count += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_securities(&mut self, _conn: &Connection) -> CustomResult<()>{
|
||||
fn list_securities(&mut self, _conn: &Connection) -> CustomResult<()> {
|
||||
self.list_securities_count += 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_events(&mut self, _conn: &mut Connection, _files: ValuesRef<PathBuf>) -> CustomResult<()> {
|
||||
fn process_events(
|
||||
&mut self,
|
||||
_conn: &mut Connection,
|
||||
_files: ValuesRef<PathBuf>,
|
||||
) -> CustomResult<()> {
|
||||
self.process_events_count += 1;
|
||||
Ok(())
|
||||
}
|
||||
@@ -471,7 +486,12 @@ impl ProCommandLineLogic {
|
||||
}
|
||||
|
||||
impl CommandLineUserLogic for ProCommandLineLogic {
|
||||
fn create_user(&mut self, conn: &mut Connection, name: &String, public_key: &String) -> CustomResult<()> {
|
||||
fn create_user(
|
||||
&mut self,
|
||||
conn: &mut Connection,
|
||||
name: &String,
|
||||
public_key: &String,
|
||||
) -> CustomResult<()> {
|
||||
let tx = conn.transaction().map_err(Error::SqlError)?;
|
||||
create_user(&tx, name, public_key)?;
|
||||
tx.commit().map_err(Error::SqlError)
|
||||
@@ -491,11 +511,20 @@ impl CommandLineUserLogic for ProCommandLineLogic {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_events(&mut self, conn: &mut Connection, files: ValuesRef<PathBuf>) -> CustomResult<()> {
|
||||
fn process_events(
|
||||
&mut self,
|
||||
conn: &mut Connection,
|
||||
files: ValuesRef<PathBuf>,
|
||||
) -> CustomResult<()> {
|
||||
process_event_files(conn, files)
|
||||
}
|
||||
|
||||
fn run_webui(&mut self, _conn: &mut Connection, port: u16, enable_template_autoreload: bool) -> CustomResult<()> {
|
||||
fn run_webui(
|
||||
&mut self,
|
||||
_conn: &mut Connection,
|
||||
port: u16,
|
||||
enable_template_autoreload: bool,
|
||||
) -> CustomResult<()> {
|
||||
info!("Serving web-ui on port {:?}", port);
|
||||
web_ui_main(port, enable_template_autoreload)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user