Add commands to print the default configuration (#1241)
* Add commands to print the default configuration When updating a software I often want to compare my configuration with the configuration of the new version. To make this possible atuin can now print the default configuration. This also updates the example files with the actual values used as default in the settings.rs files. * Changed command name to 'default-config' * Fixed merge
This commit is contained in:
parent
14bef9c4a4
commit
20afcd2b63
9 changed files with 74 additions and 8 deletions
|
@ -71,6 +71,7 @@ Satyarth Sampath <satyarth.23@gmail.com>
|
||||||
Simon Elsbrock <simon@iodev.org>
|
Simon Elsbrock <simon@iodev.org>
|
||||||
Steve Kemp <steve@steve.org.uk>
|
Steve Kemp <steve@steve.org.uk>
|
||||||
Steven Xu
|
Steven Xu
|
||||||
|
Tobias Genannt <tobias.genannt@gmail.com>
|
||||||
Tobias Hunger <tobias.hunger@gmail.com>
|
Tobias Hunger <tobias.hunger@gmail.com>
|
||||||
Tom Cammann <cammann.tom@gmail.com>
|
Tom Cammann <cammann.tom@gmail.com>
|
||||||
Trygve Aaberge <trygveaa@gmail.com>
|
Trygve Aaberge <trygveaa@gmail.com>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
## how often to sync history. note that this is only triggered when a command
|
## how often to sync history. note that this is only triggered when a command
|
||||||
## is ran, so sync intervals may well be longer
|
## is ran, so sync intervals may well be longer
|
||||||
## set it to 0 to sync after every command
|
## set it to 0 to sync after every command
|
||||||
# sync_frequency = "1h"
|
# sync_frequency = "10m"
|
||||||
|
|
||||||
## which search mode to use
|
## which search mode to use
|
||||||
## possible values: prefix, fulltext, fuzzy, skim
|
## possible values: prefix, fulltext, fuzzy, skim
|
||||||
|
@ -102,3 +102,24 @@
|
||||||
# cwd_filter = [
|
# cwd_filter = [
|
||||||
# "^/very/secret/area"
|
# "^/very/secret/area"
|
||||||
# ]
|
# ]
|
||||||
|
|
||||||
|
## Configure the maximum height of the preview to show.
|
||||||
|
## Useful when you have long scripts in your history that you want to distinguish
|
||||||
|
## by more than the first few lines.
|
||||||
|
# max_preview_height = 4
|
||||||
|
|
||||||
|
## Configure whether or not to show the help row, which includes the current Atuin
|
||||||
|
## version (and whether an update is available), a keymap hint, and the total
|
||||||
|
## amount of commands in your history.
|
||||||
|
# show_help = true
|
||||||
|
|
||||||
|
## Invert the UI - put the search bar at the top
|
||||||
|
# invert = false
|
||||||
|
|
||||||
|
## Defaults to true. This matches history against a set of default regex, and will not save it if we get a match. Defaults include
|
||||||
|
## 1. AWS key id
|
||||||
|
## 2. Github pat (old and new)
|
||||||
|
## 3. Slack oauth tokens (bot, user)
|
||||||
|
## 4. Slack webhooks
|
||||||
|
## 5. Stripe live/test keys
|
||||||
|
# secrets_filter = true
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub const LAST_SYNC_FILENAME: &str = "last_sync_time";
|
||||||
pub const LAST_VERSION_CHECK_FILENAME: &str = "last_version_check_time";
|
pub const LAST_VERSION_CHECK_FILENAME: &str = "last_version_check_time";
|
||||||
pub const LATEST_VERSION_FILENAME: &str = "latest_version";
|
pub const LATEST_VERSION_FILENAME: &str = "latest_version";
|
||||||
pub const HOST_ID_FILENAME: &str = "host_id";
|
pub const HOST_ID_FILENAME: &str = "host_id";
|
||||||
|
static EXAMPLE_CONFIG: &str = include_str!("../config.toml");
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Copy, ValueEnum, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Copy, ValueEnum, PartialEq)]
|
||||||
pub enum SearchMode {
|
pub enum SearchMode {
|
||||||
|
@ -410,9 +411,8 @@ impl Settings {
|
||||||
FileFormat::Toml,
|
FileFormat::Toml,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let example_config = include_bytes!("../config.toml");
|
|
||||||
let mut file = File::create(config_file).wrap_err("could not create config file")?;
|
let mut file = File::create(config_file).wrap_err("could not create config file")?;
|
||||||
file.write_all(example_config)
|
file.write_all(EXAMPLE_CONFIG.as_bytes())
|
||||||
.wrap_err("could not write default config file")?;
|
.wrap_err("could not write default config file")?;
|
||||||
|
|
||||||
config_builder
|
config_builder
|
||||||
|
@ -446,6 +446,10 @@ impl Settings {
|
||||||
|
|
||||||
Ok(settings)
|
Ok(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn example_config() -> &'static str {
|
||||||
|
EXAMPLE_CONFIG
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
|
|
|
@ -9,3 +9,16 @@
|
||||||
|
|
||||||
## URI for postgres (using development creds here)
|
## URI for postgres (using development creds here)
|
||||||
# db_uri="postgres://username:password@localhost/atuin"
|
# db_uri="postgres://username:password@localhost/atuin"
|
||||||
|
|
||||||
|
## Maximum size for one history entry
|
||||||
|
# max_history_length = 8192
|
||||||
|
|
||||||
|
## Maximum size for one record entry
|
||||||
|
## 1024 * 1024 * 1024
|
||||||
|
# max_record_size = 1073741824
|
||||||
|
|
||||||
|
## Webhook to be called when user registers on the servers
|
||||||
|
# register_webhook_username = ""
|
||||||
|
|
||||||
|
## Default page size for requests
|
||||||
|
# page_size = 1100
|
||||||
|
|
|
@ -14,6 +14,7 @@ mod router;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
pub use settings::example_config;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
use tokio::signal;
|
use tokio::signal;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ use eyre::{eyre, Result};
|
||||||
use fs_err::{create_dir_all, File};
|
use fs_err::{create_dir_all, File};
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
|
||||||
|
static EXAMPLE_CONFIG: &str = include_str!("../server.toml");
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Settings<DbSettings> {
|
pub struct Settings<DbSettings> {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
|
@ -56,10 +58,9 @@ impl<DbSettings: DeserializeOwned> Settings<DbSettings> {
|
||||||
FileFormat::Toml,
|
FileFormat::Toml,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let example_config = include_bytes!("../server.toml");
|
|
||||||
create_dir_all(config_file.parent().unwrap())?;
|
create_dir_all(config_file.parent().unwrap())?;
|
||||||
let mut file = File::create(config_file)?;
|
let mut file = File::create(config_file)?;
|
||||||
file.write_all(example_config)?;
|
file.write_all(EXAMPLE_CONFIG.as_bytes())?;
|
||||||
|
|
||||||
config_builder
|
config_builder
|
||||||
};
|
};
|
||||||
|
@ -71,3 +72,7 @@ impl<DbSettings: DeserializeOwned> Settings<DbSettings> {
|
||||||
.map_err(|e| eyre!("failed to deserialize: {}", e))
|
.map_err(|e| eyre!("failed to deserialize: {}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn example_config() -> &'static str {
|
||||||
|
EXAMPLE_CONFIG
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ mod sync;
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
mod account;
|
mod account;
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod history;
|
mod history;
|
||||||
mod import;
|
mod import;
|
||||||
mod kv;
|
mod kv;
|
||||||
|
@ -44,6 +45,10 @@ pub enum Cmd {
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
Kv(kv::Cmd),
|
Kv(kv::Cmd),
|
||||||
|
|
||||||
|
/// Print example configuration
|
||||||
|
#[command()]
|
||||||
|
DefaultConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cmd {
|
impl Cmd {
|
||||||
|
@ -77,6 +82,11 @@ impl Cmd {
|
||||||
Self::Account(account) => account.run(settings).await,
|
Self::Account(account) => account.run(settings).await,
|
||||||
|
|
||||||
Self::Kv(kv) => kv.run(&settings, &mut store).await,
|
Self::Kv(kv) => kv.run(&settings, &mut store).await,
|
||||||
|
|
||||||
|
Self::DefaultConfig => {
|
||||||
|
config::run();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
atuin/src/command/client/config.rs
Normal file
5
atuin/src/command/client/config.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use atuin_client::settings::Settings;
|
||||||
|
|
||||||
|
pub fn run() {
|
||||||
|
println!("{}", Settings::example_config());
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use eyre::{Context, Result};
|
use eyre::{Context, Result};
|
||||||
|
|
||||||
use atuin_server::{launch, Settings};
|
use atuin_server::{example_config, launch, Settings};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(infer_subcommands = true)]
|
#[clap(infer_subcommands = true)]
|
||||||
|
@ -19,6 +19,9 @@ pub enum Cmd {
|
||||||
#[clap(long, short)]
|
#[clap(long, short)]
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Print server example configuration
|
||||||
|
DefaultConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cmd {
|
impl Cmd {
|
||||||
|
@ -31,10 +34,9 @@ impl Cmd {
|
||||||
|
|
||||||
tracing::trace!(command = ?self, "server command");
|
tracing::trace!(command = ?self, "server command");
|
||||||
|
|
||||||
let settings = Settings::new().wrap_err("could not load server settings")?;
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Self::Start { host, port } => {
|
Self::Start { host, port } => {
|
||||||
|
let settings = Settings::new().wrap_err("could not load server settings")?;
|
||||||
let host = host
|
let host = host
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(settings.host.clone(), std::string::ToString::to_string);
|
.map_or(settings.host.clone(), std::string::ToString::to_string);
|
||||||
|
@ -42,6 +44,10 @@ impl Cmd {
|
||||||
|
|
||||||
launch::<Postgres>(settings, host, port).await
|
launch::<Postgres>(settings, host, port).await
|
||||||
}
|
}
|
||||||
|
Self::DefaultConfig => {
|
||||||
|
println!("{}", example_config());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue