Skip to content

Commit ef139a5

Browse files
committed
chore: fix clippy lints
1 parent 13f00d6 commit ef139a5

11 files changed

+67
-37
lines changed

flake.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
toolchain.channel = "stable"
1+
toolchain.channel = "1.86"
22
toolchain.components = ["rust-analyzer"]

src/cli/branch_fetch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl SubCommand for BranchFetch {
7373
return Err(CliParseError::EmptyArgument(format!(
7474
"commit is empty for {arg}"
7575
)));
76-
};
76+
}
7777
(branch_name, Some(commit))
7878
},
7979
None => (arg.as_str(), None),

src/cli/pr_fetch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl SubCommand for PrFetch {
8080
}
8181
if custom_repo_name.is_empty() {
8282
return Err(CliParseError::EmptyArgument(arg.clone()));
83-
};
83+
}
8484
repo_name = Some(custom_repo_name);
8585
},
8686
Some(LocalFlag::BranchName(custom_branch_name)) => {
@@ -104,7 +104,7 @@ impl SubCommand for PrFetch {
104104
Some((pr_number, commit)) => {
105105
if commit.is_empty() {
106106
return Err(CliParseError::EmptyCommitHash(arg.clone()));
107-
};
107+
}
108108
(parse_pr(pr_number)?, Some(commit))
109109
},
110110
None => (parse_pr(&arg)?, None),

src/commands/branch_fetch.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ pub async fn branch_fetch(args: BranchFetch) -> anyhow::Result<()> {
4545
},
4646
Err(err) => {
4747
fail!("{err}");
48-
continue;
4948
},
50-
};
49+
}
5150
}
5251

5352
Ok(())

src/commands/gen_patch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn gen_patch(args: GenPatch) -> anyhow::Result<()> {
5151
]) {
5252
fail!("Could not get patch output for patch {}\n{err}", commit);
5353
continue;
54-
};
54+
}
5555

5656
success!(
5757
"Created patch file at {}",

src/commands/pr_fetch.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn pr_fetch(mut args: PrFetch) -> anyhow::Result<()> {
2626
let start = GITHUB_REMOTE_PREFIX.len();
2727
let end = remote.len() - GITHUB_REMOTE_SUFFIX.len();
2828
args.remote_name = remote.get(start..end).map(Into::into);
29-
};
29+
}
3030
}
3131
let remote_name = args
3232
.remote_name
@@ -93,9 +93,8 @@ pub async fn pr_fetch(mut args: PrFetch) -> anyhow::Result<()> {
9393
},
9494
Err(err) => {
9595
fail!("{err}");
96-
continue;
9796
},
98-
};
97+
}
9998
}
10099

101100
Ok(())

src/commands/run.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub async fn run(args: Run) -> anyhow::Result<()> {
5959
if let Err(err) = commands::init() {
6060
fail!("{err}");
6161
process::exit(1);
62-
};
62+
}
6363
} else if args.yes {
6464
eprintln!(
6565
"You can create it with {} {}",
@@ -170,13 +170,11 @@ pub async fn run(args: Run) -> anyhow::Result<()> {
170170
},
171171
Err(err) => {
172172
fail!("{err}");
173-
continue;
174173
},
175-
};
174+
}
176175
},
177176
Err(err) => {
178177
fail!("Could not fetch branch from remote\n{err}");
179-
continue;
180178
},
181179
}
182180
}
@@ -194,7 +192,7 @@ pub async fn run(args: Run) -> anyhow::Result<()> {
194192
"Could not create directory {}\n{err}",
195193
CONFIG_ROOT.as_str()
196194
));
197-
};
195+
}
198196

199197
for (file_name, _file, contents) in &backed_up_files {
200198
restore(file_name, contents).map_err(|err| anyhow!("Could not restore backups:\n{err}"))?;
@@ -213,7 +211,7 @@ pub async fn run(args: Run) -> anyhow::Result<()> {
213211
if let Err(err) = GIT(&["am", "--keep-cr", "--signoff", &file_name.to_string_lossy()]) {
214212
GIT(&["am", "--abort"])?;
215213
return Err(anyhow!("Could not apply patch {patch}, skipping\n{err}"));
216-
};
214+
}
217215

218216
let last_commit_message = GIT(&["log", "-1", "--format=%B"])?;
219217
success!(

src/git_commands.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)]
1111
use std::path::{Path, PathBuf};
1212
use std::process::{self, Output};
13+
use std::sync::LazyLock;
1314
use std::{env, io};
1415

1516
use anyhow::{Result, anyhow};
@@ -88,13 +89,14 @@ pub fn get_git_root() -> anyhow::Result<PathBuf> {
8889
get_git_output(&root, &args).map(Into::into)
8990
}
9091

91-
pub static GIT_ROOT: Lazy<PathBuf> = Lazy::new(|| match get_git_root() {
92-
Ok(root) => root,
93-
Err(err) => {
94-
fail!("Failed to determine Git root directory.\n{err}");
95-
process::exit(1)
96-
},
97-
});
92+
pub static GIT_ROOT: std::sync::LazyLock<PathBuf> =
93+
std::sync::LazyLock::new(|| match get_git_root() {
94+
Ok(root) => root,
95+
Err(err) => {
96+
fail!("Failed to determine Git root directory.\n{err}");
97+
process::exit(1)
98+
},
99+
});
98100

99101
type Git = Lazy<Box<dyn Fn(&[&str]) -> Result<String> + Send + Sync>>;
100102

@@ -105,7 +107,7 @@ pub static GIT: Git = Lazy::new(|| {
105107
})
106108
});
107109

108-
pub static CLIENT: Lazy<Client> = Lazy::new(|| *Box::new(reqwest::Client::new()));
110+
pub static CLIENT: LazyLock<Client> = LazyLock::new(|| *Box::new(reqwest::Client::new()));
109111

110112
/// Fetches a branch of a remote into local. Optionally accepts a commit hash
111113
/// for versioning.
@@ -167,7 +169,7 @@ pub fn add_remote_branch(
167169
})?;
168170

169171
log::trace!("...and did a hard reset to commit {}", commit_hash.as_ref());
170-
};
172+
}
171173

172174
Ok(())
173175
}
@@ -195,7 +197,7 @@ pub fn checkout_from_remote(branch: &str, remote: &str) -> anyhow::Result<String
195197
return Err(anyhow!(
196198
"Could not checkout branch: {branch}, which belongs to remote {remote}\n{err}"
197199
));
198-
};
200+
}
199201

200202
Ok(current_branch)
201203
}
@@ -210,7 +212,7 @@ pub fn merge_into_main(
210212
// nukes the worktree
211213
GIT(&["reset", "--hard"])?;
212214
return Err(anyhow!("Could not merge {remote_branch}\n{err}"));
213-
};
215+
}
214216

215217
// --squash will NOT commit anything. So we need to make it manually
216218
GIT(&[

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#![cfg_attr(doc, doc = include_str!("../docs/README.md"))]
22
use core::fmt;
3-
use std::env;
3+
use std::{env, sync::LazyLock};
44

55
use cli::CliParseError;
66
use colored::Colorize as _;
7-
use once_cell::sync::Lazy;
87

98
pub mod backup;
109
pub mod cli;
@@ -33,7 +32,7 @@ impl fmt::Display for PatchyError {
3332

3433
impl std::error::Error for PatchyError {}
3534

36-
pub static CONFIG_ROOT: Lazy<String> =
37-
Lazy::new(|| env::var("PATCHY_CONFIG_ROOT").unwrap_or_else(|_| ".patchy".into()));
35+
pub static CONFIG_ROOT: LazyLock<String> =
36+
LazyLock::new(|| env::var("PATCHY_CONFIG_ROOT").unwrap_or_else(|_| ".patchy".into()));
3837
pub const CONFIG_FILE: &str = "config.toml";
3938
pub const APP_NAME: &str = "patchy";

src/main.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::error;
22
use std::env;
3+
use std::process::ExitCode;
34

45
use patchy::cli::flags::HelpOrVersion;
56
use patchy::cli::{Cli, Subcommand};
@@ -15,7 +16,12 @@ async fn main_impl() -> Result<Option<String>, Box<dyn error::Error>> {
1516
HelpOrVersion::Version => {
1617
return Ok(Some(env!("CARGO_PKG_VERSION").to_owned()));
1718
},
18-
HelpOrVersion::None => args.subcommand.unwrap(),
19+
HelpOrVersion::None if args.subcommand.is_none() => {
20+
return Ok(Some(commands::help(args.subcommand)));
21+
},
22+
HelpOrVersion::None => args
23+
.subcommand
24+
.expect("checked that we DO have a subcommand in an earlier branch"),
1925
};
2026

2127
match subcommand {
@@ -32,15 +38,15 @@ async fn main_impl() -> Result<Option<String>, Box<dyn error::Error>> {
3238
}
3339

3440
#[tokio::main]
35-
async fn main() {
41+
async fn main() -> ExitCode {
3642
match main_impl().await {
37-
Ok(ok) => {
38-
println!("{}", ok.unwrap_or_default());
39-
std::process::exit(0);
43+
Ok(msg) => {
44+
println!("{}", msg.unwrap_or_default());
45+
ExitCode::SUCCESS
4046
},
4147
Err(err) => {
4248
eprintln!("{err}");
43-
std::process::exit(1);
49+
ExitCode::FAILURE
4450
},
4551
}
4652
}

0 commit comments

Comments
 (0)