use crate::chunk::Chunk;
use crate::value::Value;
pub trait ShellHost: Send {
fn glob(&mut self, pattern: &str, recursive: bool) -> Vec<String> {
let _ = recursive;
glob::glob(pattern)
.into_iter()
.flat_map(|paths| paths.filter_map(|p| p.ok()))
.map(|p| p.to_string_lossy().into_owned())
.collect()
}
fn tilde_expand(&mut self, s: &str) -> String {
s.to_string()
}
fn brace_expand(&mut self, s: &str) -> Vec<String> {
vec![s.to_string()]
}
fn word_split(&mut self, s: &str) -> Vec<String> {
s.split_whitespace().map(|w| w.to_string()).collect()
}
fn expand_param(&mut self, name: &str, modifier: u8, args: &[Value]) -> Value {
let _ = (name, modifier, args);
Value::str("")
}
fn array_index(&mut self, name: &str, index: &Value) -> Value {
let _ = (name, index);
Value::Undef
}
fn cmd_subst(&mut self, sub: &Chunk) -> String {
let _ = sub;
String::new()
}
fn process_sub_in(&mut self, sub: &Chunk) -> String {
let _ = sub;
String::new()
}
fn process_sub_out(&mut self, sub: &Chunk) -> String {
let _ = sub;
String::new()
}
fn redirect(&mut self, fd: u8, op: u8, target: &str) {
let _ = (fd, op, target);
}
fn heredoc(&mut self, content: &str) {
let _ = content;
}
fn herestring(&mut self, content: &str) {
let _ = content;
}
fn pipeline_begin(&mut self, n: u8) {
let _ = n;
}
fn pipeline_stage(&mut self) {}
fn pipeline_end(&mut self) -> i32 {
0
}
fn subshell_begin(&mut self) {}
fn subshell_end(&mut self) {}
fn trap_set(&mut self, sig: &str, handler: &Chunk) {
let _ = (sig, handler);
}
fn trap_check(&mut self) {}
fn with_redirects_begin(&mut self, count: u8) {
let _ = count;
}
fn with_redirects_end(&mut self) {}
fn call_function(&mut self, name: &str, args: Vec<String>) -> Option<i32> {
let _ = (name, args);
None
}
fn exec(&mut self, args: Vec<String>) -> i32 {
use std::process::{Command, Stdio};
let cmd = match args.first() {
Some(c) => c,
None => return 0,
};
Command::new(cmd)
.args(&args[1..])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.map(|s| s.code().unwrap_or(1))
.unwrap_or(127)
}
fn str_match(&mut self, s: &str, pat: &str) -> bool {
s == pat
}
fn regex_match(&mut self, s: &str, regex: &str) -> bool {
let _ = (s, regex);
false
}
}
pub struct DefaultHost;
impl ShellHost for DefaultHost {}