Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f690959f0d | |||
| f9eeb4b6bc | |||
| 70de97d761 |
@@ -1,10 +1,13 @@
|
||||
[package]
|
||||
name = "advotrackerd"
|
||||
version = "0.1.0"
|
||||
version = "0.1.0-alpha1"
|
||||
authors = ["Ralf Zerres <ralf.zerres@networkx.de>"]
|
||||
description = "Supports lawyers to capture relevant data encountered during an online legal advice\n"
|
||||
repository = "https://gitea.networkx.de:50443/rzerres/advotrackerd"
|
||||
homepage = "https://gitea.networkx.de:50443/rzerres/advotrackerd"
|
||||
readme = "README.md"
|
||||
license = "(0BSD OR MIT)"
|
||||
keywords = ["backend", "daemon"]
|
||||
edition = "2018"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
@@ -12,7 +15,7 @@ winapi = { version = "0.3", features = ["winuser"] }
|
||||
#diesel = { version = "1.4", features = [ "msql", "postgres", "sqlite" ] }
|
||||
|
||||
[dependencies]
|
||||
advotracker_db = { path = "../advotracker-db" }
|
||||
advotrackerdb = { path = "../advotracker_db" }
|
||||
|
||||
clap = { version = "~2.33", features = [ "suggestions", "color" ] }
|
||||
dotenv = { version = "~0.15.0" }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: 0BSD, MIT
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
// module: db
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: 0BSD, MIT
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: 0BSD, MIT
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
#![warn(missing_docs, rust_2018_idioms, rust_2018_compatibility)]
|
||||
@@ -38,6 +38,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn internal_test() {
|
||||
assert_eq!(8, internal_adder(4, 4));
|
||||
assert_eq!(8, internal_adder(4, 4));
|
||||
}
|
||||
}
|
||||
|
||||
203
src/main.rs
203
src/main.rs
@@ -1,7 +1,8 @@
|
||||
/* advotracker infrastructure.
|
||||
// SPDX-License-Identifier: 0BSD, MIT
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
// Rust nightly supports procedural macros!
|
||||
@@ -51,9 +52,9 @@ impl AdvoTrackerSubscriber {
|
||||
fn run_subcommand(matches: &ArgMatches) -> Result<(), String> {
|
||||
//info!("inside run_subcommand");
|
||||
match matches.subcommand() {
|
||||
("config", Some(cmd)) => run_config(cmd),
|
||||
("test", Some(cmd)) => run_test(cmd),
|
||||
_ => Ok(()),
|
||||
("config", Some(cmd)) => run_config(cmd),
|
||||
("test", Some(cmd)) => run_test(cmd),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +69,11 @@ fn run_test(matches: &ArgMatches) -> Result<(), String> {
|
||||
//info!("inside run_test");
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("test") {
|
||||
if matches.is_present("debug") {
|
||||
println!("test: Printing debug info...");
|
||||
} else {
|
||||
println!("test: Printing normally...");
|
||||
}
|
||||
if matches.is_present("debug") {
|
||||
println!("test: Printing debug info...");
|
||||
} else {
|
||||
println!("test: Printing normally...");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -95,8 +96,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let span = tracing::span!(Level::TRACE, "advotracker_main");
|
||||
let _enter = span.enter();
|
||||
let subscriber = fmt::Subscriber::builder()
|
||||
.with_env_filter("advotracker=trace")
|
||||
.finish();
|
||||
.with_env_filter("advotracker=trace")
|
||||
.finish();
|
||||
|
||||
// initialize logger
|
||||
// TODO: exchange with tracing!
|
||||
@@ -104,109 +105,109 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
//info!("Commencing the proxy!");
|
||||
|
||||
tracing::subscriber::with_default(subscriber, || {
|
||||
// get system environment
|
||||
let mut lang = env::var("LANG").unwrap_or("en".to_string());
|
||||
let mut res = t!("parse.environment", lang);
|
||||
let mut state = t!("state.started", lang);
|
||||
trace!(target: "advotracker", message = ?res, state = ?state);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
trace!(target: "advotracker", environment = "system", lang = ?lang);
|
||||
// get system environment
|
||||
let mut lang = env::var("LANG").unwrap_or("en".to_string());
|
||||
let mut res = t!("parse.environment", lang);
|
||||
let mut state = t!("state.started", lang);
|
||||
trace!(target: "advotracker", message = ?res, state = ?state);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
trace!(target: "advotracker", environment = "system", lang = ?lang);
|
||||
|
||||
// get testing environment (.env)
|
||||
dotenv().ok();
|
||||
match envy::from_env::<Environment>() {
|
||||
Ok(environment) => {
|
||||
if environment.test_lang != lang { lang = environment.test_lang; }
|
||||
},
|
||||
Err(e) => { debug!(target: "advotracker", "{}", e); }
|
||||
}
|
||||
res = t!("parse.environment", lang);
|
||||
trace!(target: "advotracker", environment = "envy", lang = ?lang);
|
||||
state = t!("state.finished", lang);
|
||||
trace!(target: "advotracker", message = ?res, state = ?state);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
// get testing environment (.env)
|
||||
dotenv().ok();
|
||||
match envy::from_env::<Environment>() {
|
||||
Ok(environment) => {
|
||||
if environment.test_lang != lang { lang = environment.test_lang; }
|
||||
},
|
||||
Err(e) => { debug!(target: "advotracker", "{}", e); }
|
||||
}
|
||||
res = t!("parse.environment", lang);
|
||||
trace!(target: "advotracker", environment = "envy", lang = ?lang);
|
||||
state = t!("state.finished", lang);
|
||||
trace!(target: "advotracker", message = ?res, state = ?state);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
|
||||
// initialize viperus structure
|
||||
let mut v = Viperus::new();
|
||||
// initialize viperus structure
|
||||
let mut v = Viperus::new();
|
||||
|
||||
// parse commandline arguments
|
||||
res = t!("parse.arguments", lang);
|
||||
state = t!("state.started", lang);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
//info!(target: "advotracker", "{}", res);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
//info!(target: "advotracker", "parsing commandline args");
|
||||
let _ = parse_args(&mut v);
|
||||
state = t!("state.finished", lang);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
//trace!(target: "Viperus", "Config results: {:?}", v);
|
||||
// parse commandline arguments
|
||||
res = t!("parse.arguments", lang);
|
||||
state = t!("state.started", lang);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
//info!(target: "advotracker", "{}", res);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
//info!(target: "advotracker", "parsing commandline args");
|
||||
let _ = parse_args(&mut v);
|
||||
state = t!("state.finished", lang);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
//trace!(target: "Viperus", "Config results: {:?}", v);
|
||||
|
||||
/*
|
||||
if verbose > 1 {
|
||||
for (key, value) in env::vars() {
|
||||
println!("{}={}", key, value);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if verbose > 1 {
|
||||
for (key, value) in env::vars() {
|
||||
println!("{}={}", key, value);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//state = t!("state.finished", lang);
|
||||
//trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
//state = t!("state.finished", lang);
|
||||
//trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
//debug!(message = ?res, state = ?state);
|
||||
|
||||
/*
|
||||
// handle subcommands
|
||||
if let Err(e) = run_subcommand(&matches) {
|
||||
println!("Subcommand error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
// handle subcommands
|
||||
if let Err(e) = run_subcommand(&matches) {
|
||||
println!("Subcommand error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
*/
|
||||
|
||||
// Starting the program logic
|
||||
res = t!("main.started", lang);
|
||||
state = t!("state.started", lang);
|
||||
//info!(target: "advotracker", "{}", res);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
// Starting the program logic
|
||||
res = t!("main.started", lang);
|
||||
state = t!("state.started", lang);
|
||||
//info!(target: "advotracker", "{}", res);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
|
||||
//use advotracker_backend::*;
|
||||
//use advotracker_backend::schema::users::dsl::*;
|
||||
//use advotracker_backend::*;
|
||||
//use advotracker_backend::schema::users::dsl::*;
|
||||
|
||||
/*
|
||||
let connection = establish_connection();
|
||||
/*
|
||||
let connection = establish_connection();
|
||||
|
||||
trace!(
|
||||
target: "advotracker",
|
||||
process = "Sqlite3",
|
||||
status = "connected",
|
||||
);
|
||||
*/
|
||||
trace!(
|
||||
target: "advotracker",
|
||||
process = "Sqlite3",
|
||||
status = "connected",
|
||||
);
|
||||
*/
|
||||
|
||||
/*
|
||||
//User::table.load(&connection);
|
||||
//user::belonging_to(users).load(&connection);
|
||||
use advotracker_backend::models::*;
|
||||
/*
|
||||
//User::table.load(&connection);
|
||||
//user::belonging_to(users).load(&connection);
|
||||
use advotracker_backend::models::*;
|
||||
|
||||
|
||||
let results = users
|
||||
//.filter(published.eq(true))
|
||||
.limit(5)
|
||||
.load::<User>(&connection)
|
||||
.expect("Error loading users");
|
||||
let results = users
|
||||
//.filter(published.eq(true))
|
||||
.limit(5)
|
||||
.load::<User>(&connection)
|
||||
.expect("Error loading users");
|
||||
|
||||
println!("Displaying {} users", results.len());
|
||||
for user in results {
|
||||
println!("{}", user.user_id);
|
||||
println!("----------\n");
|
||||
println!("{}", user.first_name);
|
||||
println!("{}", user.last_name);
|
||||
println!("{}", user.alias);
|
||||
println!("{}", user.email);
|
||||
}
|
||||
*/
|
||||
println!("Displaying {} users", results.len());
|
||||
for user in results {
|
||||
println!("{}", user.user_id);
|
||||
println!("----------\n");
|
||||
println!("{}", user.first_name);
|
||||
println!("{}", user.last_name);
|
||||
println!("{}", user.alias);
|
||||
println!("{}", user.email);
|
||||
}
|
||||
*/
|
||||
|
||||
state = t!("state.finished", lang);
|
||||
res = t!("main.finished", lang);
|
||||
//info!(target: "advotracker", "{}", res);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
state = t!("state.finished", lang);
|
||||
res = t!("main.finished", lang);
|
||||
//info!(target: "advotracker", "{}", res);
|
||||
trace!(target: "advotracker", process = ?res, state = ?state);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* advotracker infrastructure.
|
||||
// SPDX-License-Identifier: 0BSD, MIT
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use viperus::Viperus;
|
||||
@@ -9,18 +10,16 @@ use viperus::Viperus;
|
||||
/// The given Viperus structure will be muted according to the
|
||||
/// processed default, environment and commandline arguments
|
||||
pub fn parse_args(v: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||
//use log::{debug, info, trace, warn};
|
||||
//use log::trace;
|
||||
use tracing::{trace, Level};
|
||||
use tracing::trace;
|
||||
use std::env;
|
||||
|
||||
if cfg!(feature = "yaml") {
|
||||
trace!(target:"feature", "Clap feature 'yaml' enabled.");
|
||||
println!("Using feature yaml.");
|
||||
trace!(target:"feature", "Clap feature 'yaml' enabled.");
|
||||
println!("Using feature yaml.");
|
||||
}
|
||||
if cfg!(feature = "fmt-clap") {
|
||||
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
|
||||
println!("Using feature fmt-clap");
|
||||
trace!(target: "Viperus", "Viperus feature 'fmt-clap' enabled.");
|
||||
println!("Using feature fmt-clap");
|
||||
}
|
||||
|
||||
// preset default key/value pairs (lowest priority)
|
||||
@@ -36,51 +35,51 @@ pub fn parse_args(v: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// CLI arguments are defined inline
|
||||
let matches = App::new("advotrackerd")
|
||||
.name(crate_name!())
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!())
|
||||
.about(crate_description!())
|
||||
.after_help("in Zusammenarbeit mit Hiedemann Rechtsanwälte <info@hiedemann.de>")
|
||||
.template(
|
||||
"\
|
||||
{bin} v{version}
|
||||
.name(crate_name!())
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!())
|
||||
.about(crate_description!())
|
||||
.after_help("in Zusammenarbeit mit Hiedemann Rechtsanwälte <info@hiedemann.de>")
|
||||
.template(
|
||||
"\
|
||||
{bin} v{version}
|
||||
{about}
|
||||
|
||||
{all-args}
|
||||
|
||||
(C) 2020 {author}
|
||||
{after_help}",
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("configFile")
|
||||
.short("c")
|
||||
.long("configFile")
|
||||
.value_name("FILE")
|
||||
.help("Sets a custom config file")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("dbdriver")
|
||||
.short("d")
|
||||
.long("dbdriver")
|
||||
.value_name("DatabaseDriver")
|
||||
.help("Driver used to connect to database")
|
||||
.possible_values(&["mysql", "postgres", "sqlite"])
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("verbose")
|
||||
.short("v")
|
||||
.long("verbose")
|
||||
.help("Sets verbosity level")
|
||||
.multiple(true),
|
||||
)
|
||||
.get_matches();
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("configFile")
|
||||
.short("c")
|
||||
.long("configFile")
|
||||
.value_name("FILE")
|
||||
.help("Sets a custom config file")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("dbdriver")
|
||||
.short("d")
|
||||
.long("dbdriver")
|
||||
.value_name("DatabaseDriver")
|
||||
.help("Driver used to connect to database")
|
||||
.possible_values(&["mysql", "postgres", "sqlite"])
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("verbose")
|
||||
.short("v")
|
||||
.long("verbose")
|
||||
.help("Sets verbosity level")
|
||||
.multiple(true),
|
||||
)
|
||||
.get_matches();
|
||||
//}
|
||||
if matches.occurrences_of("verbose") > 0 {
|
||||
// clap is using i64, viperus i32
|
||||
let n = matches.occurrences_of("verbose") as i32;
|
||||
v.add("verbose", n);
|
||||
// clap is using i64, viperus i32
|
||||
let n = matches.occurrences_of("verbose") as i32;
|
||||
v.add("verbose", n);
|
||||
}
|
||||
//}
|
||||
|
||||
@@ -94,17 +93,17 @@ pub fn parse_args(v: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// respect dotenv environment (e.g for testing)
|
||||
// -> overwrites the preset default values
|
||||
println!(
|
||||
"RUST_LOG={}",
|
||||
dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"))
|
||||
"RUST_LOG={}",
|
||||
dotenv::var("RUST_LOG").unwrap_or_else(|_| String::from("None"))
|
||||
);
|
||||
//v.load_file(".env", v.Format::ENV).unwrap();
|
||||
|
||||
// enable caching and automatic update of environment values
|
||||
if cfg!(feature = "fmt-cache") {
|
||||
v.cache(true);
|
||||
v.cache(true);
|
||||
}
|
||||
if cfg!(feature = "fmt-env") {
|
||||
v.automatic_env(true);
|
||||
v.automatic_env(true);
|
||||
}
|
||||
|
||||
//if cfg!(feature = "fmt-clap") {
|
||||
@@ -120,25 +119,25 @@ pub fn parse_args(v: &mut Viperus) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
trace!("verbose {:?}", v.get::<i32>("verbose").unwrap());
|
||||
if v.get::<i32>("verbose").unwrap() > 0 {
|
||||
println!(
|
||||
"config_file: {:?}",
|
||||
v.get::<String>("config_file").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"db_driver: {:?}",
|
||||
v.get::<String>("db_driver").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"verbosity level: {:?}",
|
||||
v.get::<i32>("verbose").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"config_file: {:?}",
|
||||
v.get::<String>("config_file").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"db_driver: {:?}",
|
||||
v.get::<String>("db_driver").unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"verbosity level: {:?}",
|
||||
v.get::<i32>("verbose").unwrap_or_default()
|
||||
);
|
||||
}
|
||||
|
||||
if v.get::<i32>("verbose").unwrap() > 1 {
|
||||
println!("\nEnvironment:");
|
||||
for (key, value) in env::vars() {
|
||||
println!("{}={}", key, value);
|
||||
}
|
||||
println!("\nEnvironment:");
|
||||
for (key, value) in env::vars() {
|
||||
println!("{}={}", key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
// SPDX-License-Identifier: 0BSD, MIT
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
//use advotracker;
|
||||
|
||||
#[test]
|
||||
fn integration_add_two() {
|
||||
assert_eq!(4, advotracker_backend::add_two(2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user