Going somewhere.
This commit is contained in:
1 parent
ded31da7a3
commit
fc13cf7f99
6 files changed
+244
-26
No files matched your search
+57
-4
@@ -12,6 +12,7 @@ use crate::migration::migrate;
|
||||
|
||||
mod migration;
|
||||
mod users;
|
||||
mod securities;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Output<T> {
|
||||
@@ -31,7 +32,7 @@ trait CommandLineUserLogic {
|
||||
|
||||
fn list_user(&mut self, conn: &Connection);
|
||||
|
||||
// fn list_securities(&mut self, conn: &Connection);
|
||||
fn list_securities(&mut self, conn: &Connection);
|
||||
}
|
||||
|
||||
fn verbosity_arg() -> Arg {
|
||||
@@ -84,11 +85,23 @@ fn user_command_line_parser() -> Command {
|
||||
.subcommand(ls_user_command_line_parser());
|
||||
}
|
||||
|
||||
fn ls_securities_command_line_parser() -> Command {
|
||||
return Command::new("ls")
|
||||
.long_flag("ls")
|
||||
.about("List all securities.");
|
||||
}
|
||||
|
||||
fn securities_command_line_parser() -> Command {
|
||||
return Command::new("securities")
|
||||
.subcommand(ls_securities_command_line_parser());
|
||||
}
|
||||
|
||||
fn command_line_parser() -> Command {
|
||||
return Command::new("prog")
|
||||
.arg(verbosity_arg())
|
||||
.arg(db_path_arg())
|
||||
.subcommand(user_command_line_parser());
|
||||
.subcommand(user_command_line_parser())
|
||||
.subcommand(securities_command_line_parser());
|
||||
}
|
||||
|
||||
fn process_new_user_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
@@ -116,12 +129,33 @@ fn process_user_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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_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)) => {
|
||||
process_list_securities_command_line(conn, list_securities_match, logic);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn process_command_line(conn: &Connection, m: &ArgMatches, logic: &mut dyn CommandLineUserLogic) {
|
||||
debug!("Processing command line {:?}.", m);
|
||||
match m.subcommand() {
|
||||
Some(("users", user_match)) => {
|
||||
process_user_command_line(conn, user_match, logic);
|
||||
}
|
||||
|
||||
Some(("securities", securities_match)) => {
|
||||
process_securities_command_line(conn, securities_match, logic);
|
||||
}
|
||||
_ => {
|
||||
println!("Received unparsable command. {:?}", m.subcommand());
|
||||
unreachable!();
|
||||
@@ -136,7 +170,7 @@ mod test {
|
||||
struct TestCommandLineLogic {
|
||||
list_user_count: usize,
|
||||
create_user_count: usize,
|
||||
|
||||
list_securities_count: usize,
|
||||
}
|
||||
|
||||
impl TestCommandLineLogic {
|
||||
@@ -144,6 +178,7 @@ mod test {
|
||||
return TestCommandLineLogic {
|
||||
list_user_count: 0,
|
||||
create_user_count: 0,
|
||||
list_securities_count: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -156,6 +191,10 @@ mod test {
|
||||
fn list_user(&mut self, conn: &Connection) {
|
||||
self.list_user_count += 1;
|
||||
}
|
||||
|
||||
fn list_securities(&mut self, conn: &Connection) {
|
||||
self.list_securities_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -210,6 +249,16 @@ mod test {
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
assert_eq!(logic.list_user_count, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_securities() {
|
||||
let cmd = command_line_parser();
|
||||
let m = cmd.get_matches_from(vec!["test", "securities", "ls"]);
|
||||
let mut logic = TestCommandLineLogic::new();
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
assert_eq!(logic.list_securities_count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
struct ProCommandLineLogic {}
|
||||
@@ -243,6 +292,10 @@ impl CommandLineUserLogic for ProCommandLineLogic {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn list_securities(&mut self, conn: &Connection) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +315,7 @@ fn main() {
|
||||
|
||||
set_logger(&m);
|
||||
let conn = get_connection(&m);
|
||||
migrate(&conn);
|
||||
// migrate(&conn);
|
||||
let mut logic = ProCommandLineLogic::new();
|
||||
process_command_line(&conn, &m, &mut logic);
|
||||
}
|
||||
Reference in new issue
Block a user