dampen_cli/commands/
release.rs1#![allow(clippy::print_stderr, clippy::print_stdout)]
2
3use std::path::Path;
9use std::process::Command;
10
11#[derive(clap::Args)]
13pub struct ReleaseArgs {
14 #[arg(short, long)]
16 package: Option<String>,
17
18 #[arg(long, value_delimiter = ',')]
20 features: Vec<String>,
21
22 #[arg(short, long)]
24 verbose: bool,
25
26 #[arg(long)]
28 target_dir: Option<String>,
29}
30
31pub fn execute(args: &ReleaseArgs) -> Result<(), String> {
58 if !Path::new("Cargo.toml").exists() {
60 return Err("Cargo.toml not found. Are you in a Rust project directory?".to_string());
61 }
62
63 if !Path::new("build.rs").exists() {
65 return Err(
66 "build.rs not found. This project may not be configured for production builds."
67 .to_string(),
68 );
69 }
70
71 if args.verbose {
72 eprintln!("Building for production (release mode with codegen)...");
73 }
74
75 let mut cmd = Command::new("cargo");
77 cmd.arg("build");
78 cmd.arg("--release");
79
80 if let Some(ref package) = args.package {
82 cmd.arg("-p").arg(package);
83 }
84
85 if let Some(ref target_dir) = args.target_dir {
87 cmd.arg("--target-dir").arg(target_dir);
88 }
89
90 if args.verbose {
91 cmd.arg("--verbose");
92 }
93
94 let mut all_features = vec!["codegen".to_string()];
96 all_features.extend(args.features.clone());
97
98 cmd.arg("--features").arg(all_features.join(","));
100
101 if args.verbose {
103 let features_str = all_features.join(",");
104 eprintln!(
105 "Executing: cargo build --release --features {}",
106 features_str
107 );
108 }
109
110 let status = cmd
111 .status()
112 .map_err(|e| format!("Failed to execute cargo: {}", e))?;
113
114 if !status.success() {
115 return Err("Release build failed".to_string());
116 }
117
118 if args.verbose {
119 eprintln!("Release build successful! Binary is in target/release/");
120 }
121
122 eprintln!("Production build completed successfully!");
123 Ok(())
124}