1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use {
crate::*,
serde::Deserialize,
std::collections::HashMap,
};
/// One of the possible job that bacon can run
#[derive(Debug, Clone, Deserialize)]
pub struct Job {
/// The tokens making the command to execute (first one
/// is the executable).
/// This vector is guaranteed not empty
/// by the PackageConfig::from_path loader
pub command: Vec<String>,
/// Whether to apply the default watch list, which is
/// `["src", "tests", "benches", "examples"]`
///
/// This is true by default. Set it to false if you want
/// to watch nothing, or only the directories you set in
/// `watch`.
#[serde(default = "default_true")]
pub default_watch: bool,
/// A list of directories that will be watched if the job
/// is run on a package.
/// src, examples, tests, and benches are implicitly included
/// unless you `set default_watch` to false.
#[serde(default)]
pub watch: Vec<String>,
/// Whether we need to capture stdout too (stderr is
/// always captured)
#[serde(default)]
pub need_stdout: bool,
/// The optional action to run when there's no
/// error, warning or test failures
#[serde(default)]
pub on_success: Option<Action>,
/// Whether to consider that we can have a success
/// when we have warnings. This is especially useful
/// for "cargo run" jobs
#[serde(default)]
pub allow_warnings: bool,
/// Whether to consider that we can have a success
/// when we have test failures
#[serde(default)]
pub allow_failures: bool,
/// Whether gitignore rules must be applied
pub apply_gitignore: Option<bool>,
/// Env vars to set for this job execution
#[serde(default)]
pub env: HashMap<String, String>,
}
static DEFAULT_ARGS: &[&str] = &["--color", "always"];
// waiting for https://github.com/serde-rs/serde/issues/368
fn default_true() -> bool {
true
}
impl Job {
/// Build a `Job` for a cargo alias
pub fn from_alias(
alias_name: &str,
settings: &Settings,
) -> Self {
let mut command = vec!["cargo".to_string(), alias_name.to_string()];
if let Some(additional_args) = settings.additional_alias_args.as_ref() {
for arg in additional_args {
command.push(arg.to_string())
}
} else {
for arg in DEFAULT_ARGS {
command.push(arg.to_string())
}
}
Self {
command,
default_watch: true,
watch: Vec::new(),
need_stdout: false,
on_success: None,
allow_warnings: false,
allow_failures: false,
apply_gitignore: None,
env: Default::default(),
}
}
}