diff --git a/Cargo.toml b/Cargo.toml index d9948bd..67c4480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" [profile.release] lto = true opt-level = "z" +panic = "abort" +strip = "symbols" [dependencies] diff --git a/src/db.rs b/src/db.rs index e1beb21..3a1d1ed 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,7 +1,7 @@ +use crate::Result; use dirs::data_dir; use rusqlite::{params, Connection}; use std::{fs::create_dir, path::PathBuf}; -use crate::Result; pub fn connect() -> Result { let conn = Connection::open(path()?).map_err(|e| { @@ -17,10 +17,10 @@ pub fn insert_settings_string(name: &str, value: &str, conn: &Connection) -> Res &format!("UPDATE settings SET json = json_set(json, '$.{name}', ?1);"), params![value], ) - .map_err(|e| { - eprintln!("failed to set {name} to {value}: {e}"); - e - })?; + .map_err(|e| { + eprintln!("failed to set {name} to {value}: {e}"); + e + })?; Ok(()) } @@ -37,13 +37,15 @@ pub fn query_settings_string(name: &str, conn: &Connection) -> Result { eprintln!("failed to query {name} from settings"); e })?; - Ok(match rows.next().map_err(|e| { - eprintln!("failed to query {name} from settings"); - e - })? { - Some(first_row) => first_row.get(0).unwrap_or("".into()), - None => "".into(), - }) + Ok( + match rows.next().map_err(|e| { + eprintln!("failed to query {name} from settings"); + e + })? { + Some(first_row) => first_row.get(0).unwrap_or("".into()), + None => "".into(), + }, + ) } fn path() -> Result { @@ -63,10 +65,10 @@ fn init(conn: &Connection) -> Result<()> { "CREATE TABLE IF NOT EXISTS settings (json TEXT NOT NULL);", (), ) - .map_err(|e| { - eprintln!("failed to create settings table: {e}"); - e - })?; + .map_err(|e| { + eprintln!("failed to create settings table: {e}"); + e + })?; let mut stmt = conn .prepare("SELECT COUNT (*) FROM settings;") .map_err(|e| { diff --git a/src/main.rs b/src/main.rs index 311dcd2..bc525e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,7 @@ type Result = std::result::Result>; fn main() -> Result<()> { let args: Vec = env::args().collect(); if args.len() < 2 { - Err( - "you need to provide an action, run btcmap-cli help to see all supported actions" - )?; + Err("you need to provide an action, run btcmap-cli help to see all supported actions")?; } let action = args[1].as_str(); let password = db::query_settings_string("password", &db::connect()?)?; @@ -101,7 +99,9 @@ fn main() -> Result<()> { json!({"period_start":period_start,"period_end":period_end}), )?; } - "generate-element-issues" => rpc::call_remote_procedure("generateelementissues", json!({}))?, + "generate-element-issues" => { + rpc::call_remote_procedure("generateelementissues", json!({}))? + } "sync-elements" => rpc::call_remote_procedure("syncelements", json!({}))?, "get-most-commented-countries" => { let period_start = args[2].clone(); diff --git a/src/rpc.rs b/src/rpc.rs index b13b601..c6eb094 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -1,24 +1,22 @@ use crate::db; +use crate::Result; use colored_json::ToColoredJson; use reqwest::blocking::ClientBuilder; use reqwest::blocking::Response; use serde_json::{json, Map, Value}; -use crate::Result; pub fn call_remote_procedure(name: &str, mut params: Value) -> Result<()> { - let params = params.as_object_mut() + let params = params + .as_object_mut() .ok_or("params value is not a valid JSON object")?; params.insert( "password".into(), db::query_settings_string("password", &db::connect()?)?.into(), ); - let http_client = ClientBuilder::new() - .timeout(None) - .build() - .map_err(|e| { - eprintln!("failed to initialize HTTP client: {e}"); - e - })?; + let http_client = ClientBuilder::new().timeout(None).build().map_err(|e| { + eprintln!("failed to initialize HTTP client: {e}"); + e + })?; let args = json!( {"jsonrpc": "2.0", "method": name, "params": params, "id": 1} );