Skip to content

Commit

Permalink
Fix pedantic clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpdp7 committed Mar 4, 2024
1 parent 490e0d0 commit 063d2bf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn base(builder: &mut GlobalsBuilder) {
dest.push("bin");
dest.push(name);
let dest = dest.as_path();
std::fs::write(dest, contents.contents.clone()).unwrap();
std::fs::write(dest, contents.contents.clone())?;
let mut perms = std::fs::metadata(dest).unwrap().permissions();
perms.set_mode(perms.mode() | 0o100);

Check failure on line 40 in src/base.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

no method named `set_mode` found for struct `Permissions` in the current scope

Check failure on line 40 in src/base.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

no method named `mode` found for struct `Permissions` in the current scope
std::fs::set_permissions(dest, perms).unwrap();
Expand Down
15 changes: 7 additions & 8 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum GitError {
pub enum Error {
#[error("Error executing git (maybe git is not installed?)")]
GitExecution(#[from] std::io::Error),
#[error("Return code {0} when executing {1}")]
GitUnsuccessful(std::process::ExitStatus, String),
}

pub fn get_repo_sorted_versions(url: String) -> Result<Vec<String>, GitError> {
#[allow(clippy::missing_panics_doc)]
pub fn get_repo_sorted_versions(url: String) -> Result<Vec<String>, Error> {
let mut binding = std::process::Command::new("git");
let command = binding
.arg("ls-remote")
Expand All @@ -19,16 +20,13 @@ pub fn get_repo_sorted_versions(url: String) -> Result<Vec<String>, GitError> {
let refs = command.output()?;

if !refs.status.success() {
return Err(GitError::GitUnsuccessful(
refs.status,
format!("{command:?}"),
));
return Err(Error::GitUnsuccessful(refs.status, format!("{command:?}")));
}

let output = String::from_utf8(refs.stdout).unwrap();
let mut versions = output
.split('\n')
.flat_map(|l| l.split_once('\t')) // the last line is blank :(
.filter_map(|l| l.split_once('\t')) // the last line is blank :(
.map(|(_hash, id)| id)
.map(|id| id.strip_prefix("refs/tags/").unwrap().to_string())
.collect::<Vec<String>>();
Expand All @@ -37,6 +35,7 @@ pub fn get_repo_sorted_versions(url: String) -> Result<Vec<String>, GitError> {
Ok(versions)
}

pub fn get_repo_latest_version(url: String) -> Result<String, GitError> {
#[allow(clippy::missing_panics_doc)]
pub fn get_repo_latest_version(url: String) -> Result<String, Error> {
Ok(get_repo_sorted_versions(url)?.last().unwrap().to_string())
}
2 changes: 2 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_lifetimes, clippy::unnecessary_wraps)] // starlark weirdness

use allocative::Allocative;
use starlark::environment::{GlobalsBuilder, Methods, MethodsBuilder, MethodsStatic};
use starlark::values::{
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::missing_errors_doc)]

#[macro_use]
extern crate starlark;

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct Args {
fn main() -> Result<()> {
color_eyre::install()?;
let args = Args::parse();
for package in args.packages.iter() {
let manifest = repo::load_manifest_from_repo(package.to_string())?;
for package in &args.packages {
let manifest = repo::load_manifest_from_repo(package)?;
runner::run_manifest(manifest)?;
}
Ok(())
Expand Down
11 changes: 6 additions & 5 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use thiserror::Error;
pub const REPO: Dir = include_dir!("repo");

#[derive(Error, Debug)]
pub enum RepoError {
pub enum Error {
#[error("Manifest {0:?} not found")]
NotFound(String),
#[error("Malformed UTF8 in manifest {0:?}")]
Expand All @@ -16,15 +16,16 @@ pub struct Manifest {
pub content: String,
}

pub fn load_manifest_from_repo(package: String) -> Result<Manifest, RepoError> {
let manifest_name = format!("{}.ubpkg.sky", package);
#[allow(clippy::module_name_repetitions)]
pub fn load_manifest_from_repo(package: &str) -> Result<Manifest, Error> {
let manifest_name = format!("{package}.ubpkg.sky");
Ok(Manifest {
name: manifest_name.clone(),
content: REPO
.get_file(&manifest_name)
.ok_or_else(|| RepoError::NotFound(manifest_name.clone()))?
.ok_or_else(|| Error::NotFound(manifest_name.clone()))?
.contents_utf8()
.ok_or_else(|| RepoError::MalformedUTF8(manifest_name.clone()))?
.ok_or_else(|| Error::MalformedUTF8(manifest_name.clone()))?
.to_string(),
})
}

0 comments on commit 063d2bf

Please sign in to comment.