diff options
Diffstat (limited to 'src/env.rs')
-rw-r--r-- | src/env.rs | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -1,12 +1,12 @@ use serde::Deserialize as _; use std::os::unix::process::ExitStatusExt as _; -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum Env { V0(V0), } -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct V0 { pipeline: Option<String>, idx: usize, @@ -15,14 +15,16 @@ pub struct V0 { deserialize_with = "deserialize_status" )] latest_status: async_std::process::ExitStatus, + pwd: std::path::PathBuf, } impl Env { - pub fn new(idx: usize) -> Self { + pub fn new() -> Self { Self::V0(V0 { pipeline: None, - idx, + idx: 0, latest_status: std::process::ExitStatus::from_raw(0), + pwd: std::env::current_dir().unwrap(), }) } @@ -40,6 +42,12 @@ impl Env { } } + pub fn set_idx(&mut self, idx: usize) { + match self { + Self::V0(env) => env.idx = idx, + } + } + pub fn set_status(&mut self, status: async_std::process::ExitStatus) { match self { Self::V0(env) => { @@ -48,6 +56,20 @@ impl Env { } } + pub fn set_current_dir(&mut self, pwd: std::path::PathBuf) { + match self { + Self::V0(env) => { + env.pwd = pwd; + } + } + } + + pub fn current_dir(&self) -> &std::path::Path { + match self { + Self::V0(env) => &env.pwd, + } + } + pub fn pipeline(&self) -> Option<&str> { match self { Self::V0(env) => env.pipeline.as_deref(), @@ -60,6 +82,14 @@ impl Env { } } + pub fn apply(&self, cmd: &mut pty_process::Command) { + match self { + Self::V0(env) => { + cmd.current_dir(&env.pwd); + } + } + } + pub fn as_bytes(&self) -> Vec<u8> { bincode::serialize(self).unwrap() } |