-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'config-updates' into optimization
Revert handling find_command_name in state.rs Add options for skip_confirmation, size_bypass
- Loading branch information
Showing
6 changed files
with
65 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
skip_confirmation = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,59 @@ | ||
use crate::{ListNode, TabList}; | ||
use serde::Deserialize; | ||
use std::{path::Path, process}; | ||
use std::{fs, path::Path, process, rc::Rc}; | ||
|
||
// Struct that defines what values can be used in the toml file | ||
#[derive(Deserialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Config { | ||
pub auto_execute: Vec<String>, | ||
#[serde(default)] | ||
auto_execute: Option<Vec<String>>, | ||
#[serde(default)] | ||
skip_confirmation: Option<bool>, | ||
#[serde(default)] | ||
size_bypass: Option<bool>, | ||
} | ||
|
||
// Struct that holds the parsed values from the toml so that it can be applied in the AppState | ||
pub struct ConfigValues { | ||
pub auto_execute_commands: Vec<Rc<ListNode>>, | ||
pub skip_confirmation: bool, | ||
pub size_bypass: bool, | ||
} | ||
|
||
impl Config { | ||
pub fn from_file(path: &Path) -> Self { | ||
let content = match std::fs::read_to_string(path) { | ||
pub fn new(path: &Path, tabs: &TabList) -> ConfigValues { | ||
let content = match fs::read_to_string(path) { | ||
Ok(content) => content, | ||
Err(e) => { | ||
eprintln!("Failed to read config file {}: {}", path.display(), e); | ||
process::exit(1); | ||
} | ||
}; | ||
|
||
match toml::from_str(&content) { | ||
let config: Config = match toml::from_str(&content) { | ||
Ok(config) => config, | ||
Err(e) => { | ||
eprintln!("Failed to parse config file: {}", e); | ||
process::exit(1); | ||
} | ||
}; | ||
|
||
ConfigValues { | ||
auto_execute_commands: config.auto_execute_commands(tabs), | ||
skip_confirmation: config.skip_confirmation.unwrap_or(false), | ||
size_bypass: config.size_bypass.unwrap_or(false), | ||
} | ||
} | ||
|
||
fn auto_execute_commands(&self, tabs: &TabList) -> Vec<Rc<ListNode>> { | ||
self.auto_execute | ||
.as_ref() | ||
.map_or_else(Vec::new, |commands| { | ||
commands | ||
.iter() | ||
.filter_map(|name| tabs.iter().find_map(|tab| tab.find_command_by_name(name))) | ||
.collect() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters