1use crate::profile::Profile;
2#[cfg(feature = "clap")]
3use clap::Parser;
4use std::path::PathBuf;
5use std::process::Command;
6
7#[derive(Clone, Debug, Eq, PartialEq)]
8#[cfg_attr(feature = "clap", derive(Parser))]
9pub struct Args {
10 #[cfg_attr(feature = "clap", clap(long, short))]
12 pub quiet: bool,
13
14 #[cfg_attr(feature = "clap", clap(long, short))]
16 pub package: Vec<String>,
17 #[cfg_attr(feature = "clap", clap(long, visible_alias = "all"))]
19 pub workspace: bool,
20 #[cfg_attr(feature = "clap", clap(long))]
22 pub exclude: Vec<String>,
23
24 #[cfg_attr(feature = "clap", clap(long))]
26 pub lib: bool,
27 #[cfg_attr(feature = "clap", clap(long))]
29 pub bin: Vec<String>,
30 #[cfg_attr(feature = "clap", clap(long, conflicts_with = "bin"))]
32 pub bins: bool,
33 #[cfg_attr(feature = "clap", clap(long))]
35 pub example: Vec<String>,
36 #[cfg_attr(feature = "clap", clap(long, conflicts_with = "example"))]
38 pub examples: bool,
39
40 #[cfg_attr(feature = "clap", clap(long, short))]
42 pub release: bool,
43 #[cfg_attr(feature = "clap", clap(long, conflicts_with = "release"))]
45 pub profile: Option<Profile>,
46 #[cfg_attr(feature = "clap", clap(long, short = 'F'))]
48 pub features: Vec<String>,
49 #[cfg_attr(feature = "clap", clap(long))]
51 pub all_features: bool,
52 #[cfg_attr(feature = "clap", clap(long))]
54 pub no_default_features: bool,
55 #[cfg_attr(feature = "clap", clap(long))]
57 pub target: Option<String>,
58 #[cfg_attr(feature = "clap", clap(long))]
60 pub target_dir: Option<PathBuf>,
61 #[cfg_attr(feature = "clap", clap(long))]
63 pub manifest_path: Option<PathBuf>,
64}
65
66impl Args {
67 pub fn apply(&self, cmd: &mut Command) {
68 if self.quiet {
69 cmd.arg("--quiet");
70 }
71
72 for package in &self.package {
73 cmd.arg("--package").arg(package);
74 }
75 if self.workspace {
76 cmd.arg("--workspace");
77 }
78 for exclude in &self.exclude {
79 cmd.arg("--exclude").arg(exclude);
80 }
81
82 if self.lib {
83 cmd.arg("--lib");
84 }
85 for bin in &self.bin {
86 cmd.arg("--bin").arg(bin);
87 }
88 if self.bins {
89 cmd.arg("--bins");
90 }
91 for example in &self.example {
92 cmd.arg("--example").arg(example);
93 }
94 if self.examples {
95 cmd.arg("--examples");
96 }
97
98 if self.release {
99 cmd.arg("--release");
100 }
101 if let Some(profile) = self.profile.as_ref() {
102 cmd.arg("--profile").arg(profile.to_string());
103 }
104 for features in &self.features {
105 cmd.arg("--features").arg(features);
106 }
107 if self.all_features {
108 cmd.arg("--all-features");
109 }
110 if self.no_default_features {
111 cmd.arg("--no-default-features");
112 }
113 if let Some(target) = self.target.as_ref() {
114 cmd.arg("--target").arg(target);
115 }
116 if let Some(target_dir) = self.target_dir.as_ref() {
117 cmd.arg("--target-dir").arg(target_dir);
118 }
119 if let Some(manifest_path) = self.manifest_path.as_ref() {
120 cmd.arg("--manifest-path").arg(manifest_path);
121 }
122 }
123
124 pub fn profile(&self) -> Profile {
125 if let Some(profile) = self.profile.as_ref() {
126 profile.clone()
127 } else if self.release {
128 Profile::Release
129 } else {
130 Profile::Dev
131 }
132 }
133
134 pub fn specific_target_selected(&self) -> bool {
140 self.lib || self.bins || self.examples || !self.bin.is_empty() || !self.example.is_empty()
141 }
142}