aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/server.rs25
-rw-r--r--src/main.rs2
-rw-r--r--src/remote/database.rs2
-rw-r--r--src/remote/server.rs9
-rw-r--r--src/settings.rs34
5 files changed, 46 insertions, 26 deletions
diff --git a/src/command/server.rs b/src/command/server.rs
index 9d9bcb3a..5156f409 100644
--- a/src/command/server.rs
+++ b/src/command/server.rs
@@ -6,13 +6,32 @@ use crate::settings::Settings;
#[derive(StructOpt)]
pub enum Cmd {
- Start { host: Vec<String> },
+ #[structopt(
+ about="starts the server",
+ aliases=&["s", "st", "sta", "star"],
+ )]
+ Start {
+ #[structopt(about = "specify the host address to bind", long, short)]
+ host: Option<String>,
+
+ #[structopt(about = "specify the port to bind", long, short)]
+ port: Option<u16>,
+ },
}
-#[allow(clippy::unused_self)] // I'll use it later
impl Cmd {
pub fn run(&self, settings: &Settings) -> Result<()> {
- server::launch(settings);
+ match self {
+ Self::Start { host, port } => {
+ let host = host.as_ref().map_or(
+ settings.remote.host.clone(),
+ std::string::ToString::to_string,
+ );
+ let port = port.map_or(settings.remote.port, |p| p);
+
+ server::launch(settings, host, port);
+ }
+ }
Ok(())
}
}
diff --git a/src/main.rs b/src/main.rs
index 3c4a05e4..bac75362 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -62,7 +62,7 @@ impl Atuin {
let path = shellexpand::full(path)?;
PathBuf::from(path.as_ref())
} else {
- PathBuf::from(settings.local.db.path.as_str())
+ PathBuf::from(settings.local.db_path.as_str())
};
let mut db = Sqlite::new(db_path)?;
diff --git a/src/remote/database.rs b/src/remote/database.rs
index 4f386def..fabd07de 100644
--- a/src/remote/database.rs
+++ b/src/remote/database.rs
@@ -8,7 +8,7 @@ pub struct AtuinDbConn(diesel::PgConnection);
// TODO: connection pooling
pub fn establish_connection(settings: &Settings) -> PgConnection {
- let database_url = &settings.remote.db.url;
+ let database_url = &settings.remote.db_uri;
PgConnection::establish(database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
diff --git a/src/remote/server.rs b/src/remote/server.rs
index 4409f646..cd2ca7b8 100644
--- a/src/remote/server.rs
+++ b/src/remote/server.rs
@@ -16,25 +16,26 @@ use super::auth::*;
embed_migrations!("migrations");
-pub fn launch(settings: &Settings) {
+pub fn launch(settings: &Settings, host: String, port: u16) {
let mut database_config = HashMap::new();
let mut databases = HashMap::new();
- database_config.insert("url", Value::from(settings.remote.db.url.clone()));
+ database_config.insert("url", Value::from(settings.remote.db_uri.clone()));
databases.insert("atuin", Value::from(database_config));
let connection = establish_connection(settings);
embedded_migrations::run(&connection).expect("failed to run migrations");
let config = Config::build(Environment::Production)
- .address("0.0.0.0")
+ .address(host)
.log_level(LoggingLevel::Normal)
- .port(8080)
+ .port(port)
.extra("databases", databases)
.finalize()
.unwrap();
let app = rocket::custom(config);
+
app.mount("/", routes![index, register, add_history, login])
.attach(AtuinDbConn::fairing())
.register(catchers![internal_error, bad_request])
diff --git a/src/settings.rs b/src/settings.rs
index 6f29afd2..0e554bed 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -6,25 +6,20 @@ use eyre::{eyre, Result};
use std::fs;
#[derive(Debug, Deserialize)]
-pub struct LocalDatabase {
- pub path: String,
-}
-
-#[derive(Debug, Deserialize)]
-pub struct RemoteDatabase {
- pub url: String,
-}
-
-#[derive(Debug, Deserialize)]
pub struct Local {
- pub server_address: String,
pub dialect: String,
- pub db: LocalDatabase,
+ pub sync: bool,
+ pub sync_address: String,
+ pub sync_frequency: String,
+ pub db_path: String,
}
#[derive(Debug, Deserialize)]
pub struct Remote {
- pub db: RemoteDatabase,
+ pub host: String,
+ pub port: u16,
+ pub db_uri: String,
+ pub open_registration: bool,
}
#[derive(Debug, Deserialize)]
@@ -56,18 +51,23 @@ impl Settings {
.data_dir()
.join("history.db");
- s.set_default("local.server_address", "https://atuin.elliehuxtable.com")?;
+ s.set_default("local.db_path", db_path.to_str())?;
s.set_default("local.dialect", "us")?;
- s.set_default("local.db.path", db_path.to_str())?;
+ s.set_default("local.sync", false)?;
+ s.set_default("local.sync_frequency", "5m")?;
+ s.set_default("local.sync_address", "https://atuin.ellie.wtf")?;
- s.set_default("remote.db.url", "please set a postgres url")?;
+ s.set_default("remote.host", "127.0.0.1")?;
+ s.set_default("remote.port", 8888)?;
+ s.set_default("remote.open_registration", false)?;
+ s.set_default("remote.db_uri", "please set a postgres url")?;
if config_file.exists() {
s.merge(File::with_name(config_file.to_str().unwrap()))?;
}
// all paths should be expanded
- let db_path = s.get_str("local.db.path")?;
+ let db_path = s.get_str("local.db_path")?;
let db_path = shellexpand::full(db_path.as_str())?;
s.set("local.db.path", db_path.to_string())?;