Skip to content

Commit

Permalink
Clippy lint (#35)
Browse files Browse the repository at this point in the history
* Improve cargo metadata

* Cargo clippy lint fixes

* Apply lint fix

* Update README
  • Loading branch information
camchenry authored Jan 7, 2024
1 parent 63f8d08 commit bfccffa
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 69 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name = "boon"
version = "0.3.0"
authors = ["Cameron McHenry <[email protected]>"]
edition = "2021"
license = "MIT"
description = "A cross-platform build tool for LÖVE"
repository = "https://github.com/camchenry/boon"
keywords = ["love2d", "love"]
categories = ["command-line-utilities"]

[dependencies]
zip = "0.6.6"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ If you don't initialize boon, you can still build your project normally, but the
In order to build your project, you first need to download the versionof LÖVE that you are using for it.

```bash
# Will download LÖVE 11.4 for building
$ boon love download 11.4
# Will download LÖVE 11.5 for building
$ boon love download 11.5
```

### Building your project
Expand Down
35 changes: 12 additions & 23 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ pub fn get_zip_output_filename(project: &Project, platform: Platform, bitness: B
}

pub fn get_boon_data_path() -> Result<PathBuf> {
if let Some(project_dirs) = ProjectDirs::from("", "", "boon") {
Ok(project_dirs.data_local_dir().to_path_buf())
} else {
Err(anyhow::anyhow!("Could not get app data directory"))
}
ProjectDirs::from("", "", "boon").map_or_else(
|| Err(anyhow::anyhow!("Could not get app data directory")),
|project_dirs| Ok(project_dirs.data_local_dir().to_path_buf()),
)
}

/// Get a platform-specific path to the app cache directory where LÖVE is stored.
Expand All @@ -95,12 +94,8 @@ pub fn get_love_version_path(
bitness: Bitness,
) -> Result<PathBuf> {
let filename = get_love_version_file_name(version, platform, bitness);
let boon_path = get_boon_data_path().with_context(|| {
format!(
"Could not get version directory for LÖVE version {}",
version.to_string()
)
})?;
let boon_path = get_boon_data_path()
.with_context(|| format!("Could not get version directory for LÖVE version {version}"))?;
Ok(boon_path.join(version.to_string()).join(filename))
}

Expand Down Expand Up @@ -155,19 +150,13 @@ pub fn create_love(project: &Project, build_settings: &BuildSettings) -> Result<
let dst_file = love_path
.to_str()
.context("Could not do string conversion")?;
println!("Outputting LÖVE as {}", dst_file);
println!("Outputting LÖVE as {dst_file}");

collect_zip_directory(src_dir, dst_file, method, &build_settings.ignore_list).with_context(
|| {
format!(
"Error while zipping files from `{}` to `{}`",
src_dir, dst_file
)
},
)??;
collect_zip_directory(src_dir, dst_file, method, &build_settings.ignore_list)
.with_context(|| format!("Error while zipping files from `{src_dir}` to `{dst_file}`"))??;

let build_metadata = std::fs::metadata(dst_file)
.with_context(|| format!("Failed to read file metadata for '{}'", dst_file))?;
.with_context(|| format!("Failed to read file metadata for '{dst_file}'"))?;

Ok(BuildStatistics {
name: String::from("LÖVE"),
Expand Down Expand Up @@ -225,7 +214,7 @@ where
let mut f = File::open(path)?;

f.read_to_end(&mut buffer)?;
zip.write_all(&*buffer)?;
zip.write_all(&buffer)?;
buffer.clear();
}
}
Expand All @@ -244,7 +233,7 @@ fn collect_zip_directory(
}

let path = Path::new(dst_file);
let file = File::create(&path)
let file = File::create(path)
.with_context(|| format!("Could not create file path: '{}'", path.display()))?;

let walkdir = WalkDir::new(src_dir);
Expand Down
7 changes: 3 additions & 4 deletions src/build/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,18 @@ pub fn create_exe(
)
.with_context(|| {
format!(
"Error while zipping files from `{}` to `{}`",
src_dir, dst_file
"Error while zipping files from `{src_dir}` to `{dst_file}`"
)
})??;
let path = PathBuf::new().join(src_dir);
println!("Removing {}", path.display());
remove_dir_all(&path)?;

let build_metadata = std::fs::metadata(dst_file)
.with_context(|| format!("Failed to read file metadata for '{}'", dst_file))?;
.with_context(|| format!("Failed to read file metadata for '{dst_file}'"))?;

Ok(BuildStatistics {
name: format!("Windows {}", bitness.to_string()),
name: format!("Windows {bitness}"),
// @TODO: There is probably a better way here
file_name: dst_file_path
.file_name()
Expand Down
12 changes: 5 additions & 7 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::io::Write;
pub fn download_love(version: LoveVersion, platform: Platform, bitness: Bitness) -> Result<()> {
let file_info = get_love_download_location(version, platform, bitness).with_context(|| {
format!(
"Could not get download location for LÖVE {} on {} {}",
version, platform, bitness
"Could not get download location for LÖVE {version} on {platform} {bitness}"
)
})?;

Expand All @@ -37,7 +36,7 @@ pub fn download_love(version: LoveVersion, platform: Platform, bitness: Bitness)
let prefix = output_file_path
.parent()
.expect("Could not get parent directory");
std::fs::create_dir_all(&prefix)
std::fs::create_dir_all(prefix)
.with_context(|| format!("Could not create directory `{}`", prefix.display()))?;

let file = File::create(&output_file_path)
Expand Down Expand Up @@ -71,7 +70,7 @@ pub fn download_love(version: LoveVersion, platform: Platform, bitness: Bitness)
for i in 0..archive.len() {
let mut file = archive
.by_index(i)
.unwrap_or_else(|_| panic!("Could not get archive file by index '{}'", i));
.unwrap_or_else(|_| panic!("Could not get archive file by index '{i}'"));
let mut outpath = output_file_path.clone();
outpath.pop();
outpath.push(
Expand All @@ -84,7 +83,7 @@ pub fn download_love(version: LoveVersion, platform: Platform, bitness: Bitness)
} else {
if let Some(p) = outpath.parent() {
if !p.exists() {
std::fs::create_dir_all(&p)
std::fs::create_dir_all(p)
.expect("Could not create output directory path");
}
}
Expand Down Expand Up @@ -160,8 +159,7 @@ fn get_love_download_location(
};

let url = format!(
"{}/{}/{}",
release_location, version_string, release_file_name
"{release_location}/{version_string}/{release_file_name}"
);
Ok(LoveDownloadLocation {
filename: release_file_name.to_string(),
Expand Down
44 changes: 17 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mod types;
use crate::build::get_boon_data_path;
use crate::types::{
Bitness, BuildSettings, BuildStatistics, LoveVersion, Platform, Project, Target, LOVE_VERSIONS
Bitness, BuildSettings, BuildStatistics, LoveVersion, Platform, Project, Target, LOVE_VERSIONS,
};

mod build;
Expand All @@ -19,7 +19,7 @@ mod download;
use anyhow::{bail, Context, Result};
use config::Config;
use humansize::{file_size_opts, FileSize};
use prettytable::{cell, row, Table};
use prettytable::{row, Table};
use remove_dir_all::remove_dir_all;
use std::collections::HashSet;
use std::fs::File;
Expand Down Expand Up @@ -110,7 +110,7 @@ fn main() -> Result<()> {

println!("Installed versions:");
for version in installed_versions {
println!("* {}", version);
println!("* {version}");
}
}
}
Expand All @@ -127,8 +127,7 @@ fn get_settings() -> Result<(Config, BuildSettings)> {
let mut settings = config::Config::new();
let default_config = config::File::from_str(DEFAULT_CONFIG, config::FileFormat::Toml);
settings.merge(default_config).context(format!(
"Could not set default configuration `{}`",
BOON_CONFIG_FILE_NAME
"Could not set default configuration `{BOON_CONFIG_FILE_NAME}`"
))?;

let mut ignore_list: HashSet<String> = settings.get("build.ignore_list").unwrap();
Expand All @@ -137,8 +136,7 @@ fn get_settings() -> Result<(Config, BuildSettings)> {
settings
.merge(config::File::with_name(BOON_CONFIG_FILE_NAME))
.context(format!(
"Error while reading config file `{}`.",
BOON_CONFIG_FILE_NAME
"Error while reading config file `{BOON_CONFIG_FILE_NAME}`."
))?;

let project_ignore_list: HashSet<String> = settings.get("build.ignore_list").unwrap();
Expand Down Expand Up @@ -219,9 +217,9 @@ fn love_remove(version: LoveVersion) -> Result<()> {
path.display()
)
})?;
println!("Removed LÖVE version {}.", version);
println!("Removed LÖVE version {version}.");
} else {
println!("LÖVE version '{}' is not installed.", version);
println!("LÖVE version '{version}' is not installed.");
}

Ok(())
Expand All @@ -230,21 +228,17 @@ fn love_remove(version: LoveVersion) -> Result<()> {
/// `boon love download` subcommand
fn love_download(version: LoveVersion) -> Result<()> {
download::download_love(version, Platform::Windows, Bitness::X86).context(format!(
"Could not download LÖVE {} for Windows (32-bit)",
version.to_string()
"Could not download LÖVE {version} for Windows (32-bit)"
))?;
download::download_love(version, Platform::Windows, Bitness::X64).context(format!(
"Could not download LÖVE {} for Windows (64-bit)",
version.to_string()
"Could not download LÖVE {version} for Windows (64-bit)"
))?;
download::download_love(version, Platform::MacOs, Bitness::X64).context(format!(
"Could not download LÖVE {} for macOS",
version.to_string()
"Could not download LÖVE {version} for macOS"
))?;

println!(
"\nLÖVE {} is now available for building.",
version.to_string()
"\nLÖVE {version} is now available for building."
);

Ok(())
Expand All @@ -256,12 +250,10 @@ fn init() -> Result<()> {
println!("Project already initialized.");
} else {
File::create(BOON_CONFIG_FILE_NAME).context(format!(
"Failed to create config file `{}`.",
BOON_CONFIG_FILE_NAME
"Failed to create config file `{BOON_CONFIG_FILE_NAME}`."
))?;
std::fs::write(BOON_CONFIG_FILE_NAME, DEFAULT_CONFIG).context(format!(
"Failed to write default configuration to `{}`.",
BOON_CONFIG_FILE_NAME
"Failed to write default configuration to `{BOON_CONFIG_FILE_NAME}`."
))?;
}

Expand All @@ -283,11 +275,10 @@ fn build(
}

if targets.contains(&Target::all) {
println!("Building all targets from directory `{}`", directory);
println!("Building all targets from directory `{directory}`");
} else {
println!(
"Building targets `{:?}` from directory `{}`",
targets, directory
"Building targets `{targets:?}` from directory `{directory}`"
);
}

Expand Down Expand Up @@ -321,8 +312,7 @@ fn build(

build::init(&project, build_settings).with_context(|| {
format!(
"Failed to initialize the build process using build settings: {}",
build_settings
"Failed to initialize the build process using build settings: {build_settings}"
)
})?;

Expand Down Expand Up @@ -421,7 +411,7 @@ fn get_installed_love_versions() -> Result<Vec<String>> {
let file_name = entry
.file_name()
.to_str()
.with_context(|| format!("Could not parse file name `{:?}` to str", entry))?;
.with_context(|| format!("Could not parse file name `{entry:?}` to str"))?;

// Exclude directories that do not parse to a love
// version, just in case some bogus directories
Expand Down
11 changes: 5 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ impl FromStr for LoveVersion {
.iter()
.enumerate()
.find(|(_, v)| s == **v)
.map(|(i, _)| Self::from_usize(i))
.flatten()
.ok_or(format!("{} is not a valid love version.", s))
.and_then(|(i, _)| Self::from_usize(i))
.ok_or(format!("{s} is not a valid love version."))
}
}

Expand All @@ -102,7 +101,7 @@ impl Display for Bitness {
X86 => "x86",
X64 => "x64",
};
write!(f, "{}", str)
write!(f, "{str}")
}
}

Expand All @@ -114,7 +113,7 @@ impl Display for Platform {
Windows => "Windows",
MacOs => "macOS",
};
write!(f, "{}", str)
write!(f, "{str}")
}
}

Expand All @@ -133,7 +132,7 @@ impl Display for BuildSettings {
}

arg_enum! {
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub enum Target {
love,
Expand Down

0 comments on commit bfccffa

Please sign in to comment.