aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/cli.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2023-11-08 05:19:11 +0100
committerChristian Duerr <contact@christianduerr.com>2023-11-11 20:33:06 +0100
commit683b5a2cb47579560ed272dc1a4818507dbd30c7 (patch)
tree226abbead70795e53b4c9162cb30609d7a1210af /alacritty/src/cli.rs
parent4a2666706062934c4830e73672e78fcde3210310 (diff)
downloadr-alacritty-683b5a2cb47579560ed272dc1a4818507dbd30c7.tar.gz
r-alacritty-683b5a2cb47579560ed272dc1a4818507dbd30c7.tar.bz2
r-alacritty-683b5a2cb47579560ed272dc1a4818507dbd30c7.zip
Unify CLI config override mechanisms
This patch changes the way the `-o` config option works when specified at startup to function the same way as the IPC mechanism. While this should technically perform the exact same way, it should hopefully make it a little easier to understand how CLI config replacement works.
Diffstat (limited to 'alacritty/src/cli.rs')
-rw-r--r--alacritty/src/cli.rs56
1 files changed, 26 insertions, 30 deletions
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index 4745ee8d..35d18fb2 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -4,13 +4,14 @@ use std::path::PathBuf;
use clap::{ArgAction, Args, Parser, Subcommand, ValueHint};
use log::{self, error, LevelFilter};
use serde::{Deserialize, Serialize};
-use toml::{Table, Value};
+use toml::Value;
+use crate::logging::LOG_TARGET_CONFIG;
use alacritty_terminal::tty::Options as PtyOptions;
use crate::config::ui_config::Program;
use crate::config::window::{Class, Identity};
-use crate::config::{serde_utils, UiConfig};
+use crate::config::UiConfig;
/// CLI options for the main Alacritty executable.
#[derive(Parser, Default, Debug)]
@@ -57,13 +58,9 @@ pub struct Options {
#[clap(short, conflicts_with("quiet"), action = ArgAction::Count)]
verbose: u8,
- /// Override configuration file options [example: cursor.style=Beam].
- #[clap(short = 'o', long, num_args = 1..)]
- option: Vec<String>,
-
/// CLI options for config overrides.
#[clap(skip)]
- pub config_options: TomlValue,
+ pub config_options: Vec<(String, Value)>,
/// Options which can be passed via IPC.
#[clap(flatten)]
@@ -78,8 +75,16 @@ impl Options {
pub fn new() -> Self {
let mut options = Self::parse();
- // Convert `--option` flags into serde `Value`.
- options.config_options = TomlValue(options_as_value(&options.option));
+ for option in options.window_options.option.drain(..) {
+ let parsed = match toml::from_str(&option) {
+ Ok(parsed) => parsed,
+ Err(err) => {
+ eprintln!("Ignoring invalid CLI option '{option}': {err}");
+ continue;
+ },
+ };
+ options.config_options.push((option, parsed));
+ }
options
}
@@ -100,6 +105,14 @@ impl Options {
if config.debug.print_events {
config.debug.log_level = max(config.debug.log_level, LevelFilter::Info);
}
+
+ // Replace CLI options.
+ use alacritty_config::SerdeReplace;
+ for (option, parsed) in &self.config_options {
+ if let Err(err) = config.replace(parsed.clone()) {
+ error!(target: LOG_TARGET_CONFIG, "Unable to set CLI option '{}': {}", option, err);
+ }
+ }
}
/// Logging filter level.
@@ -123,17 +136,6 @@ impl Options {
}
}
-/// Combine multiple options into a [`toml::Value`].
-pub fn options_as_value(options: &[String]) -> Value {
- options.iter().fold(Value::Table(Table::new()), |value, option| match toml::from_str(option) {
- Ok(new_value) => serde_utils::merge(value, new_value),
- Err(_) => {
- eprintln!("Ignoring invalid option: {:?}", option);
- value
- },
- })
-}
-
/// Parse the class CLI parameter.
fn parse_class(input: &str) -> Result<Class, String> {
let (general, instance) = match input.split_once(',') {
@@ -302,6 +304,10 @@ pub struct WindowOptions {
#[cfg(target_os = "macos")]
/// The window tabbing identifier to use when building a window.
pub window_tabbing_id: Option<String>,
+
+ /// Override configuration file options [example: cursor.style=Beam].
+ #[clap(short = 'o', long, num_args = 1..)]
+ option: Vec<String>,
}
/// Parameters to the `config` IPC subcommand.
@@ -323,16 +329,6 @@ pub struct IpcConfig {
pub reset: bool,
}
-/// Toml value with default implementation.
-#[derive(Debug)]
-pub struct TomlValue(pub Value);
-
-impl Default for TomlValue {
- fn default() -> Self {
- Self(Value::Table(Table::new()))
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;