-
Notifications
You must be signed in to change notification settings - Fork 6
/
args.rs
133 lines (124 loc) · 4.04 KB
/
args.rs
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use crate::profile::Profile;
#[cfg(feature = "clap")]
use clap::Parser;
use std::path::PathBuf;
use std::process::Command;
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "clap", derive(Parser))]
pub struct Args {
/// No output printed to stdout
#[cfg_attr(feature = "clap", clap(long, short))]
pub quiet: bool,
/// Package to build
#[cfg_attr(feature = "clap", clap(long, short))]
pub package: Vec<String>,
/// Build all packages in the workspace
#[cfg_attr(feature = "clap", clap(long))]
pub workspace: bool,
/// Exclude packages from the build
#[cfg_attr(feature = "clap", clap(long))]
pub exclude: Vec<String>,
/// Build only this package's library
#[cfg_attr(feature = "clap", clap(long))]
pub lib: bool,
/// Build only the specified binary
#[cfg_attr(feature = "clap", clap(long))]
pub bin: Vec<String>,
/// Build all binaries
#[cfg_attr(feature = "clap", clap(long, conflicts_with = "bin"))]
pub bins: bool,
/// Build only the specified example
#[cfg_attr(feature = "clap", clap(long))]
pub example: Vec<String>,
/// Build all examples
#[cfg_attr(feature = "clap", clap(long, conflicts_with = "example"))]
pub examples: bool,
/// Build artifacts in release mode, with optimizations
#[cfg_attr(feature = "clap", clap(long))]
pub release: bool,
/// Build artifacts with the specified profile
#[cfg_attr(feature = "clap", clap(long, conflicts_with = "release"))]
pub profile: Option<Profile>,
/// Space or comma separated list of features to activate
#[cfg_attr(feature = "clap", clap(long))]
pub features: Vec<String>,
/// Activate all available features
#[cfg_attr(feature = "clap", clap(long))]
pub all_features: bool,
/// Do not activate the `default` feature
#[cfg_attr(feature = "clap", clap(long))]
pub no_default_features: bool,
/// Build for the target triple
#[cfg_attr(feature = "clap", clap(long))]
pub target: Option<String>,
/// Directory for all generated artifacts
#[cfg_attr(feature = "clap", clap(long))]
pub target_dir: Option<PathBuf>,
/// Path to Cargo.toml
#[cfg_attr(feature = "clap", clap(long))]
pub manifest_path: Option<PathBuf>,
}
impl Args {
pub fn apply(&self, cmd: &mut Command) {
if self.quiet {
cmd.arg("--quiet");
}
for package in &self.package {
cmd.arg("--package").arg(package);
}
if self.workspace {
cmd.arg("--workspace");
}
for exclude in &self.exclude {
cmd.arg("--exclude").arg(exclude);
}
if self.lib {
cmd.arg("--lib");
}
for bin in &self.bin {
cmd.arg("--bin").arg(bin);
}
if self.bins {
cmd.arg("--bins");
}
for example in &self.example {
cmd.arg("--example").arg(example);
}
if self.examples {
cmd.arg("--examples");
}
if self.release {
cmd.arg("--release");
}
if let Some(profile) = self.profile.as_ref() {
cmd.arg("--profile").arg(profile.to_string());
}
for features in &self.features {
cmd.arg("--features").arg(features);
}
if self.all_features {
cmd.arg("--all-features");
}
if self.no_default_features {
cmd.arg("--no-default-features");
}
if let Some(target) = self.target.as_ref() {
cmd.arg("--target").arg(target);
}
if let Some(target_dir) = self.target_dir.as_ref() {
cmd.arg("--target-dir").arg(target_dir);
}
if let Some(manifest_path) = self.manifest_path.as_ref() {
cmd.arg("--manifest-path").arg(manifest_path);
}
}
pub fn profile(&self) -> Profile {
if let Some(profile) = self.profile.as_ref() {
profile.clone()
} else if self.release {
Profile::Release
} else {
Profile::Dev
}
}
}