No fuckin idea what.
This commit is contained in:
1 parent
d74d8b9d3e
commit
e1e5d5dbf3
4 files changed
+180
-48
No files matched your search
+76
-20
@@ -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;
|
||||
@@ -10,14 +10,14 @@ use simple_logger::SimpleLogger;
|
||||
use db::securities::list_securities;
|
||||
|
||||
use crate::db::users::{create_user, list_users};
|
||||
use crate::event_processor::process_event_files;
|
||||
use crate::event_processor::{process_event_files};
|
||||
use crate::migration::apply_migrations;
|
||||
|
||||
mod migration;
|
||||
mod db;
|
||||
mod event_processor;
|
||||
mod migration;
|
||||
mod services;
|
||||
mod util;
|
||||
mod event_processor;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Output<T> {
|
||||
@@ -27,7 +27,10 @@ struct Output<T> {
|
||||
|
||||
impl<T> Output<T> {
|
||||
fn success(shit: T) -> Output<T> {
|
||||
return Output { status: "success".to_string(), result: shit };
|
||||
return Output {
|
||||
status: "success".to_string(),
|
||||
result: shit,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +78,20 @@ fn new_user_command_line_parser() -> Command {
|
||||
return Command::new("new")
|
||||
.long_flag("new")
|
||||
.about("Create new user.")
|
||||
.arg(Arg::new("name").long("name").required(true).help("name of new user.").action(ArgAction::Set))
|
||||
.arg(Arg::new("public_key").required(true).long("public-key").help("public key of users.").action(ArgAction::Set));
|
||||
.arg(
|
||||
Arg::new("name")
|
||||
.long("name")
|
||||
.required(true)
|
||||
.help("name of new user.")
|
||||
.action(ArgAction::Set),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("public_key")
|
||||
.required(true)
|
||||
.long("public-key")
|
||||
.help("public key of users.")
|
||||
.action(ArgAction::Set),
|
||||
);
|
||||
}
|
||||
|
||||
fn ls_user_command_line_parser() -> Command {
|
||||
@@ -131,19 +146,31 @@ fn command_line_parser() -> Command {
|
||||
.arg_required_else_help(true);
|
||||
}
|
||||
|
||||
fn process_new_user_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_new_user_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing new user command line {:?}.", m);
|
||||
let name = m.get_one::<String>("name").unwrap();
|
||||
let pk = m.get_one::<String>("public_key").unwrap();
|
||||
logic.create_user(conn, name, pk);
|
||||
}
|
||||
|
||||
fn process_list_user_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_list_user_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing list users command line {:?}.", m);
|
||||
logic.list_user(conn);
|
||||
}
|
||||
|
||||
fn process_user_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_user_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing user command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("new", new_user_match)) => {
|
||||
@@ -156,12 +183,20 @@ fn process_user_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut
|
||||
}
|
||||
}
|
||||
|
||||
fn process_list_securities_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_list_securities_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing list securities command line {:?}.", m);
|
||||
logic.list_securities(conn);
|
||||
}
|
||||
|
||||
fn process_process_events_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_process_events_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing process event command line {:?}.", m);
|
||||
let mut files = m.get_many::<PathBuf>("PATH").unwrap();
|
||||
if files.any(|x| !x.exists()) {
|
||||
@@ -172,7 +207,11 @@ fn process_process_events_command_line(conn: &mut Connection, m: &ArgMatches, lo
|
||||
logic.process_events(conn, files);
|
||||
}
|
||||
|
||||
fn process_securities_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_securities_command_line(
|
||||
conn: &Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing securities command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("ls", list_securities_match)) => {
|
||||
@@ -182,7 +221,11 @@ fn process_securities_command_line(conn: &Connection, m: &ArgMatches, logic: &mu
|
||||
}
|
||||
}
|
||||
|
||||
fn process_events_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_events_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing events command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("process", process_events_match)) => {
|
||||
@@ -192,7 +235,11 @@ fn process_events_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mu
|
||||
}
|
||||
}
|
||||
|
||||
fn process_command_line(conn: &mut Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
fn process_command_line(
|
||||
conn: &mut Connection,
|
||||
m: &ArgMatches,
|
||||
logic: &mut dyn CommandLineUserLogic,
|
||||
) {
|
||||
debug!("Processing command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("users", user_match)) => {
|
||||
@@ -260,7 +307,6 @@ mod cli_test {
|
||||
assert_eq!(get_verbosity(&m), log::LevelFilter::Info);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
let cmd = Command::new("test").arg(verbosity_arg());
|
||||
let m = cmd.get_matches_from(vec!["test"]);
|
||||
@@ -288,7 +334,15 @@ mod cli_test {
|
||||
#[test]
|
||||
fn create_user() {
|
||||
let cmd = command_line_parser();
|
||||
let m = cmd.get_matches_from(vec!["test", "users", "new", "--name", "paul", "--public-key", "123abc"]);
|
||||
let m = cmd.get_matches_from(vec![
|
||||
"test",
|
||||
"users",
|
||||
"new",
|
||||
"--name",
|
||||
"paul",
|
||||
"--public-key",
|
||||
"123abc",
|
||||
]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&mut conn, &m, &mut logic);
|
||||
@@ -381,10 +435,12 @@ fn get_connection(m: &ArgMatches) -> Connection {
|
||||
}
|
||||
|
||||
fn set_logger(m: &ArgMatches) {
|
||||
SimpleLogger::new().with_level(get_verbosity(&m)).init().unwrap();
|
||||
SimpleLogger::new()
|
||||
.with_level(get_verbosity(&m))
|
||||
.init()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let command = command_line_parser();
|
||||
let m = command.get_matches();
|
||||
@@ -395,4 +451,4 @@ fn main() {
|
||||
apply_migrations(&mut conn).unwrap();
|
||||
let mut logic = ProCommandLineLogic::new();
|
||||
process_command_line(&mut conn, &m, &mut logic);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user