mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 06:54:45 +03:00
split daemon options out of config/mod.rs
This commit is contained in:
parent
2960b9186c
commit
955361433d
58
src/config/daemon.rs
Normal file
58
src/config/daemon.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use crate::config::*;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
pub struct DaemonOptions {
|
||||
pub pid_file: Option<PathBuf>,
|
||||
pub stdout: Option<PathBuf>,
|
||||
pub stderr: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn open_log(path: PathBuf) -> Fallible<File> {
|
||||
create_user_owned_dirs(
|
||||
path.parent()
|
||||
.ok_or_else(|| format_err!("path {} has no parent dir!?", path.display()))?,
|
||||
)?;
|
||||
let mut options = OpenOptions::new();
|
||||
options.write(true).create(true).append(true);
|
||||
options
|
||||
.open(&path)
|
||||
.map_err(|e| format_err!("failed to open log stream: {}: {}", path.display(), e))
|
||||
}
|
||||
|
||||
impl DaemonOptions {
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn pid_file(&self) -> PathBuf {
|
||||
self.pid_file
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("pid"))
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn stdout(&self) -> PathBuf {
|
||||
self.stdout
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("log"))
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn stderr(&self) -> PathBuf {
|
||||
self.stderr
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("log"))
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn open_stdout(&self) -> Fallible<File> {
|
||||
open_log(self.stdout())
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn open_stderr(&self) -> Fallible<File> {
|
||||
open_log(self.stderr())
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fs;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use term;
|
||||
@ -23,7 +22,9 @@ use termwiz::hyperlink;
|
||||
use termwiz::input::{KeyCode, Modifiers};
|
||||
use toml;
|
||||
|
||||
mod daemon;
|
||||
mod keys;
|
||||
pub use daemon::*;
|
||||
pub use keys::*;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
@ -193,61 +194,6 @@ fn default_dpi() -> f64 {
|
||||
96.0
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
pub struct DaemonOptions {
|
||||
pub pid_file: Option<PathBuf>,
|
||||
pub stdout: Option<PathBuf>,
|
||||
pub stderr: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn open_log(path: PathBuf) -> Fallible<std::fs::File> {
|
||||
create_user_owned_dirs(
|
||||
path.parent()
|
||||
.ok_or_else(|| format_err!("path {} has no parent dir!?", path.display()))?,
|
||||
)?;
|
||||
let mut options = OpenOptions::new();
|
||||
options.write(true).create(true).append(true);
|
||||
options
|
||||
.open(&path)
|
||||
.map_err(|e| format_err!("failed to open log stream: {}: {}", path.display(), e))
|
||||
}
|
||||
|
||||
impl DaemonOptions {
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn pid_file(&self) -> PathBuf {
|
||||
self.pid_file
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("pid"))
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn stdout(&self) -> PathBuf {
|
||||
self.stdout
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("log"))
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn stderr(&self) -> PathBuf {
|
||||
self.stderr
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| RUNTIME_DIR.join("log"))
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn open_stdout(&self) -> Fallible<File> {
|
||||
open_log(self.stdout())
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, allow(dead_code))]
|
||||
pub fn open_stderr(&self) -> Fallible<File> {
|
||||
open_log(self.stderr())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize)]
|
||||
pub struct SshDomain {
|
||||
/// The name of this specific domain. Must be unique amongst
|
||||
|
Loading…
Reference in New Issue
Block a user