Skip to content

Commit 50aea1e

Browse files
committed
style: Cargo fmt
1 parent 66be595 commit 50aea1e

4 files changed

Lines changed: 101 additions & 55 deletions

File tree

src/cli.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub const BANNER: &str = r#"______ _ _ ______ _
1515

1616
#[derive(Parser, Debug)]
1717
#[command(
18-
author,
19-
version,
18+
author,
19+
version,
2020
about = "A tool to automate version bumping across multiple file types in your project",
2121
long_about = "Patch Release Me automatically updates version numbers in your project files.\n\
2222
Run without a subcommand to enter interactive mode."
@@ -57,27 +57,44 @@ pub enum ArgumentCommands {
5757
version: Option<String>,
5858

5959
/// Programming languages/ecosystems to include (e.g., Rust, Python, Docker)
60-
#[clap(short, long, env, help = "Specify ecosystems: Rust, Python, Node, Docker, etc.")]
60+
#[clap(
61+
short,
62+
long,
63+
env,
64+
help = "Specify ecosystems: Rust, Python, Node, Docker, etc."
65+
)]
6166
language_ecosystems: Vec<String>,
6267

6368
/// Include default patterns for common files
64-
#[clap(short, long, env, default_value = "false", help = "Enable default file patterns")]
69+
#[clap(
70+
short,
71+
long,
72+
env,
73+
default_value = "false",
74+
help = "Enable default file patterns"
75+
)]
6576
defaults: Option<bool>,
6677
},
67-
78+
6879
/// Show what files and versions would be updated (dry-run)
6980
#[command(about = "Preview changes without modifying files")]
7081
Display,
71-
82+
7283
/// Sync all files to the current version in .release.yml
7384
#[command(about = "Apply current version to all tracked files")]
7485
Sync,
75-
86+
7687
/// Bump version and update all tracked files
7788
#[command(about = "Increment version and update files")]
7889
Bump {
7990
/// Manually set a specific version (e.g., 1.2.3)
80-
#[clap(short, long, env, default_value = "", help = "Specify exact version to set")]
91+
#[clap(
92+
short,
93+
long,
94+
env,
95+
default_value = "",
96+
help = "Specify exact version to set"
97+
)]
8198
set_version: String,
8299

83100
/// Bump mode: major, minor, or patch

src/interactive.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use log::debug;
88

99
pub fn select_mode(config: &Config) -> Result<WorkflowMode> {
1010
println!("\n🚀 Welcome to Patch Release Me - Interactive Mode\n");
11-
11+
1212
let mut modes = Vec::new();
1313
let mut descriptions = Vec::new();
14-
14+
1515
if !config.version.is_some() {
1616
modes.push("Init");
1717
descriptions.push("Initialize new .release.yml configuration");
@@ -24,7 +24,8 @@ pub fn select_mode(config: &Config) -> Result<WorkflowMode> {
2424
descriptions.push("Apply current version to all files");
2525

2626
// Format items with descriptions
27-
let items: Vec<String> = modes.iter()
27+
let items: Vec<String> = modes
28+
.iter()
2829
.zip(descriptions.iter())
2930
.map(|(mode, desc)| format!("{:<10} - {}", mode, desc))
3031
.collect();
@@ -62,7 +63,7 @@ pub fn select_mode(config: &Config) -> Result<WorkflowMode> {
6263
pub fn interactive_init() -> Result<WorkflowMode> {
6364
println!("\n📝 Configuration Setup\n");
6465
println!("Let's create your .release.yml configuration file.\n");
65-
66+
6667
let name = dialoguer::Input::<String>::new()
6768
.with_prompt("Project name")
6869
.with_initial_text(find_project_name()?)
@@ -91,8 +92,10 @@ pub fn interactive_init() -> Result<WorkflowMode> {
9192
.interact()?;
9293

9394
let language_ecosystems = if defaults {
94-
println!("\n🔧 Select your project's ecosystems (use Space to select, Enter to confirm):\n");
95-
95+
println!(
96+
"\n🔧 Select your project's ecosystems (use Space to select, Enter to confirm):\n"
97+
);
98+
9699
let defaults = Defaults::load()?;
97100
let mut lang_list = defaults.get_languages();
98101
lang_list.sort();
@@ -113,13 +116,13 @@ pub fn interactive_init() -> Result<WorkflowMode> {
113116
}
114117
})
115118
.collect();
116-
119+
117120
if selected.is_empty() {
118121
println!("⚠️ No ecosystems selected. You can manually configure patterns later.");
119122
} else {
120123
println!("✓ Selected: {}", selected.join(", "));
121124
}
122-
125+
123126
selected
124127
} else {
125128
vec![]
@@ -153,7 +156,7 @@ pub fn interactive_init() -> Result<WorkflowMode> {
153156
None
154157
}
155158
};
156-
159+
157160
println!("\n✅ Configuration complete! Creating .release.yml...\n");
158161

159162
Ok(WorkflowMode::Init {
@@ -167,14 +170,14 @@ pub fn interactive_init() -> Result<WorkflowMode> {
167170

168171
pub fn select_bump_mode() -> Result<BumpMode> {
169172
println!("\n📦 Version Bump Strategy\n");
170-
173+
171174
let items = vec![
172175
"Patch (x.x.N+1) - Bug fixes, small changes",
173176
"Minor (x.N+1.0) - New features, backward compatible",
174177
"Major (N+1.0.0) - Breaking changes",
175178
"Custom - Manually set version",
176179
];
177-
180+
178181
let selection = Select::new()
179182
.with_prompt("How would you like to bump the version?")
180183
.default(0)
@@ -185,15 +188,15 @@ pub fn select_bump_mode() -> Result<BumpMode> {
185188
0 => {
186189
println!("✓ Patch version will be incremented");
187190
Ok(BumpMode::Patch)
188-
},
191+
}
189192
1 => {
190193
println!("✓ Minor version will be incremented");
191194
Ok(BumpMode::Minor)
192-
},
195+
}
193196
2 => {
194197
println!("✓ Major version will be incremented");
195198
Ok(BumpMode::Major)
196-
},
199+
}
197200
3 => {
198201
let version = dialoguer::Input::<String>::new()
199202
.with_prompt("Enter custom version (semver format)")

src/main.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ fn detect_current_version(root: &std::path::Path) -> Result<semver::Version> {
2525
if cargo_toml.exists() {
2626
let content = std::fs::read_to_string(&cargo_toml)?;
2727
// Match version only in [package] section, before any other section
28-
let version_regex = regex::Regex::new(r#"(?m)^\[package\][^\[]*?^version\s*=\s*"([^"]+)""#)?;
28+
let version_regex =
29+
regex::Regex::new(r#"(?m)^\[package\][^\[]*?^version\s*=\s*"([^"]+)""#)?;
2930
if let Some(cap) = version_regex.captures(&content) {
3031
if let Some(version_str) = cap.get(1) {
31-
return semver::Version::parse(version_str.as_str())
32-
.map_err(|e| anyhow::anyhow!("Failed to parse version from Cargo.toml: {}", e));
32+
return semver::Version::parse(version_str.as_str()).map_err(|e| {
33+
anyhow::anyhow!("Failed to parse version from Cargo.toml: {}", e)
34+
});
3335
}
3436
}
3537
}
36-
anyhow::bail!("Could not detect version from Cargo.toml. Please ensure it exists and has a valid version field.")
38+
anyhow::bail!(
39+
"Could not detect version from Cargo.toml. Please ensure it exists and has a valid version field."
40+
)
3741
}
3842

3943
#[tokio::main]
@@ -153,26 +157,41 @@ async fn main() -> Result<()> {
153157
config.write(&arguments.root.join(&arguments.config))?;
154158

155159
println!("\n{}", style("━".repeat(60)).dim());
156-
println!("{} Configuration saved successfully!", style("✓").green().bold());
157-
println!("{} File: {}", style("→").dim(), style(&arguments.config.display()).cyan());
160+
println!(
161+
"{} Configuration saved successfully!",
162+
style("✓").green().bold()
163+
);
164+
println!(
165+
"{} File: {}",
166+
style("→").dim(),
167+
style(&arguments.config.display()).cyan()
168+
);
158169
println!("{}", style("━".repeat(60)).dim());
159170
println!("\nNext steps:");
160-
println!(" {} Run 'patch-release-me display' to preview changes", style("1.").bold());
161-
println!(" {} Run 'patch-release-me bump' to update versions", style("2.").bold());
171+
println!(
172+
" {} Run 'patch-release-me display' to preview changes",
173+
style("1.").bold()
174+
);
175+
println!(
176+
" {} Run 'patch-release-me bump' to update versions",
177+
style("2.").bold()
178+
);
162179
println!();
163180
}
164181
WorkflowMode::Display => {
165182
println!();
166-
let version_text = config.version.as_ref()
183+
let version_text = config
184+
.version
185+
.as_ref()
167186
.map(|v| format!("{}", style(v).green().bold()))
168187
.unwrap_or_else(|| style("Not set").yellow().to_string());
169-
188+
170189
println!("{} Current version: {}", style("ℹ").blue(), version_text);
171190
println!("{}", style("─".repeat(60)).dim());
172191
println!();
173192

174193
workflow.display()?;
175-
194+
176195
println!();
177196
println!("{}", style("Note:").bold());
178197
println!(" This is a dry-run. No files were modified.");
@@ -182,12 +201,15 @@ async fn main() -> Result<()> {
182201
WorkflowMode::Bump { mode, .. } => {
183202
println!("\n{} Bumping version: {:?}", style("→").cyan(), mode);
184203
println!("{}", style("─".repeat(60)).dim());
185-
204+
186205
workflow.patch().await?;
187-
206+
188207
println!();
189208
println!("{}", style("━".repeat(60)).dim());
190-
println!("{} Version bump completed successfully!", style("✓").green().bold());
209+
println!(
210+
"{} Version bump completed successfully!",
211+
style("✓").green().bold()
212+
);
191213
println!("{}", style("━".repeat(60)).dim());
192214
println!();
193215
}

src/workflows.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ impl Workflow {
4242
use std::sync::{Arc, Mutex};
4343
let file_count = Arc::new(Mutex::new(0));
4444
let match_count = Arc::new(Mutex::new(0));
45-
45+
4646
let fc = file_count.clone();
4747
let mc = match_count.clone();
48-
48+
4949
self.process(move |path, captures| {
5050
if !captures.is_empty() {
5151
*fc.lock().unwrap() += 1;
52-
52+
5353
// Print file header
5454
println!(" {} {}", style("📄").dim(), style(path.display()).cyan());
55-
55+
5656
for capture in captures {
5757
*mc.lock().unwrap() += 1;
5858
let data = capture.get(1).unwrap();
@@ -83,15 +83,17 @@ impl Workflow {
8383
}
8484
Ok(())
8585
})?;
86-
86+
8787
let files = *file_count.lock().unwrap();
8888
let matches = *match_count.lock().unwrap();
89-
89+
9090
println!("{}", style("─".repeat(60)).dim());
91-
println!(" {} files with {} version references",
92-
style(files).cyan().bold(),
93-
style(matches).cyan().bold());
94-
91+
println!(
92+
" {} files with {} version references",
93+
style(files).cyan().bold(),
94+
style(matches).cyan().bold()
95+
);
96+
9597
Ok(())
9698
}
9799

@@ -100,10 +102,10 @@ impl Workflow {
100102
use std::sync::{Arc, Mutex};
101103
let file_count = Arc::new(Mutex::new(0));
102104
let update_count = Arc::new(Mutex::new(0));
103-
105+
104106
let fc = file_count.clone();
105107
let uc = update_count.clone();
106-
108+
107109
self.process(move |path, captures| {
108110
let mut content = std::fs::read_to_string(&path)?;
109111
let mut file_updated = false;
@@ -119,7 +121,7 @@ impl Workflow {
119121
file_updated = true;
120122
*fc.lock().unwrap() += 1;
121123
}
122-
124+
123125
println!(
124126
" {} {} {} {}",
125127
style("✓").green(),
@@ -141,15 +143,17 @@ impl Workflow {
141143

142144
Ok(())
143145
})?;
144-
146+
145147
let files = *file_count.lock().unwrap();
146148
let updates = *update_count.lock().unwrap();
147-
149+
148150
println!("{}", style("─".repeat(60)).dim());
149-
println!(" {} files updated with {} changes",
150-
style(files).cyan().bold(),
151-
style(updates).cyan().bold());
152-
151+
println!(
152+
" {} files updated with {} changes",
153+
style(files).cyan().bold(),
154+
style(updates).cyan().bold()
155+
);
156+
153157
Ok(())
154158
}
155159

0 commit comments

Comments
 (0)