watchexec_supervisor/command/
shell.rs

1use std::{borrow::Cow, ffi::OsStr, path::PathBuf};
2
3/// How to call the shell used to run shelled programs.
4#[derive(Clone, Debug, PartialEq, Eq, Hash)]
5pub struct Shell {
6	/// Path or name of the shell.
7	pub prog: PathBuf,
8
9	/// Additional options or arguments to pass to the shell.
10	///
11	/// These will be inserted before the `program_option` immediately preceding the program string.
12	pub options: Vec<String>,
13
14	/// The syntax of the option which precedes the program string.
15	///
16	/// For most shells, this is `-c`. On Windows, CMD.EXE prefers `/C`. If this is `None`, then no
17	/// option is prepended; this may be useful for non-shell or non-standard shell programs.
18	pub program_option: Option<Cow<'static, OsStr>>,
19}
20
21impl Shell {
22	/// Shorthand for most shells, using the `-c` convention.
23	pub fn new(name: impl Into<PathBuf>) -> Self {
24		Self {
25			prog: name.into(),
26			options: Vec::new(),
27			program_option: Some(Cow::Borrowed(OsStr::new("-c"))),
28		}
29	}
30
31	#[cfg(windows)]
32	#[must_use]
33	/// Shorthand for the CMD.EXE shell.
34	pub fn cmd() -> Self {
35		Self {
36			prog: "CMD.EXE".into(),
37			options: Vec::new(),
38			program_option: Some(Cow::Borrowed(OsStr::new("/C"))),
39		}
40	}
41}