Add Dosh host workflows and reconnect QoL
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -54,10 +55,27 @@ pub struct ClientConfig {
|
||||
pub default_session: String,
|
||||
pub reconnect_timeout_secs: u64,
|
||||
pub view_only: bool,
|
||||
#[serde(default)]
|
||||
pub predict: bool,
|
||||
pub cache_attach_tickets: bool,
|
||||
pub credential_cache: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct HostConfig {
|
||||
pub ssh: Option<String>,
|
||||
pub dosh_host: Option<String>,
|
||||
pub port: Option<u16>,
|
||||
pub default_command: Option<String>,
|
||||
pub predict: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct HostsConfig {
|
||||
#[serde(flatten)]
|
||||
pub hosts: HashMap<String, HostConfig>,
|
||||
}
|
||||
|
||||
impl Default for ClientConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -71,6 +89,7 @@ impl Default for ClientConfig {
|
||||
default_session: "new".to_string(),
|
||||
reconnect_timeout_secs: 5,
|
||||
view_only: false,
|
||||
predict: false,
|
||||
cache_attach_tickets: true,
|
||||
credential_cache: "~/.local/share/dosh/credentials".to_string(),
|
||||
}
|
||||
@@ -95,6 +114,15 @@ pub fn load_client_config(path: Option<PathBuf>) -> Result<ClientConfig> {
|
||||
toml::from_str(&raw).with_context(|| format!("parse {}", path.display()))
|
||||
}
|
||||
|
||||
pub fn load_hosts_config(path: Option<PathBuf>) -> Result<HostsConfig> {
|
||||
let path = path.unwrap_or_else(|| expand_tilde("~/.config/dosh/hosts.toml"));
|
||||
if !path.exists() {
|
||||
return Ok(HostsConfig::default());
|
||||
}
|
||||
let raw = fs::read_to_string(&path).with_context(|| format!("read {}", path.display()))?;
|
||||
toml::from_str(&raw).with_context(|| format!("parse {}", path.display()))
|
||||
}
|
||||
|
||||
pub fn expand_tilde(path: &str) -> PathBuf {
|
||||
if let Some(rest) = path.strip_prefix("~/") {
|
||||
if let Some(home) = dirs::home_dir() {
|
||||
|
||||
Reference in New Issue
Block a user