watchexec_supervisor/command.rs
1//! Command construction and configuration.
2
3#[doc(inline)]
4pub use self::{program::Program, shell::Shell};
5
6mod conversions;
7mod program;
8mod shell;
9
10/// A command to execute.
11///
12/// # Example
13///
14/// ```
15/// # use watchexec_supervisor::command::{Command, Program};
16/// Command {
17/// program: Program::Exec {
18/// prog: "make".into(),
19/// args: vec!["check".into()],
20/// },
21/// options: Default::default(),
22/// };
23/// ```
24#[derive(Clone, Debug, PartialEq, Eq, Hash)]
25pub struct Command {
26 /// Program to execute for this command.
27 pub program: Program,
28
29 /// Options for spawning the program.
30 pub options: SpawnOptions,
31}
32
33/// Options set when constructing or spawning a command.
34///
35/// It's recommended to use the [`Default`] implementation for this struct, and only set the options
36/// you need to change, to proof against new options being added in future.
37///
38/// # Examples
39///
40/// ```
41/// # use watchexec_supervisor::command::{Command, Program, SpawnOptions};
42/// Command {
43/// program: Program::Exec {
44/// prog: "make".into(),
45/// args: vec!["check".into()],
46/// },
47/// options: SpawnOptions {
48/// grouped: true,
49/// ..Default::default()
50/// },
51/// };
52/// ```
53#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
54pub struct SpawnOptions {
55 /// Run the program in a new process group.
56 ///
57 /// This will use either of Unix [process groups] or Windows [Job Objects] via the
58 /// [`process-wrap`](process_wrap) crate.
59 ///
60 /// [process groups]: https://en.wikipedia.org/wiki/Process_group
61 /// [Job Objects]: https://en.wikipedia.org/wiki/Object_Manager_(Windows)
62 pub grouped: bool,
63
64 /// Run the program in a new session.
65 ///
66 /// This will use Unix [sessions]. On Windows, this is not supported. This
67 /// implies `grouped: true`.
68 ///
69 /// [sessions]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsid.html
70 pub session: bool,
71
72 /// Reset the signal mask of the process before we spawn it.
73 ///
74 /// By default, the signal mask of the process is inherited from the parent process. This means
75 /// that if the parent process has blocked any signals, the child process will also block those
76 /// signals. This can cause problems if the child process is expecting to receive those signals.
77 ///
78 /// This is only supported on Unix systems.
79 pub reset_sigmask: bool,
80}