Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to make safari work nicely, make clippy happy #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.tar.gz
/test-files/LIB_*
!/test-files/LIB_*.zip
git.txt
6 changes: 3 additions & 3 deletions ll-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> ll_core::Result<()> {
let app = clap::App::from(app_yaml)
.about(env!("CARGO_PKG_DESCRIPTION"))
.author(env!("CARGO_PKG_AUTHORS"))
.version(env!("CARGO_PKG_VERSION"))
.version(format!("{} ({})", env!("CARGO_PKG_VERSION"), ll_core::GIT_DESCRIBE).as_str())
.get_matches();

#[cfg(not(debug_assertions))]
Expand All @@ -32,7 +32,7 @@ fn main() -> ll_core::Result<()> {
Config::default_path()
} else {
app.value_of("config")
.map(|p| PathBuf::from(p))
.map(PathBuf::from)
.or(Config::get_path()?)
} {
Some(path) => path,
Expand All @@ -59,7 +59,7 @@ fn main() -> ll_core::Result<()> {
}

println!("Using config at {:?}", config_path);
let mut config = Config::read(Some(config_path.clone()))?;
let mut config = Config::read(Some(config_path))?;

if let Some(watch_path) = app.value_of("watch") {
config.settings.watch_path = watch_path.into();
Expand Down
1 change: 1 addition & 0 deletions ll-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.3.1"
authors = ["Edwin Svensson <[email protected]>"]
edition = "2021"
publish = false
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
11 changes: 11 additions & 0 deletions ll-core/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::{fs, process::Command};

fn main() {
// Git version
let git_desc = Command::new("git")
.args(&["describe", "--all", "--tags", "--dirty", "--long"])
.output()
.unwrap();

fs::write("git.txt", String::from_utf8_lossy(&git_desc.stdout).trim()).unwrap();
}
15 changes: 11 additions & 4 deletions ll-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Format {
pub struct Settings {
pub watch_path: String,
pub recursive: bool,
#[serde(default = "default_ignore_temp")]
pub ignore_temp: bool,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -42,15 +44,15 @@ impl Config {
}

pub fn save(&self, path: Option<PathBuf>) -> Result<()> {
let p = Self::path(path.or(self._self_path.clone()))?;
let p = Self::path(path.or_else(|| self._self_path.clone()))?;
let toml_str = toml::to_string_pretty(self)?;
fs::write(p, toml_str)?;
Ok(())
}

pub(crate) fn formats(&self) -> Result<Vec<format::Format>> {
let mut formats_vec = Vec::with_capacity(self.formats.len());
for (_, f) in &self.formats {
for f in self.formats.values() {
formats_vec.push(format::Format::from_ecad(
f.format.clone(),
PathBuf::from(shellexpand::full(&f.output_path)?.as_ref()),
Expand All @@ -60,8 +62,8 @@ impl Config {
}

fn path(path: Option<PathBuf>) -> Result<PathBuf> {
path.or(Self::default_path())
.ok_or(Error::Other("Could not find config dir".into()))
path.or_else(Self::default_path)
.ok_or(Error::Other("Could not find config dir"))
}

pub fn default_path() -> Option<PathBuf> {
Expand Down Expand Up @@ -94,6 +96,7 @@ impl Default for Config {
.to_string_lossy()
.to_string(),
recursive: false,
ignore_temp: default_ignore_temp(),
},
formats: HashMap::new(),
profile: Profile {
Expand All @@ -103,3 +106,7 @@ impl Default for Config {
}
}
}

const fn default_ignore_temp() -> bool {
true
}
1 change: 1 addition & 0 deletions ll-core/src/cse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {
mod result;
pub use result::Result;

#[allow(clippy::upper_case_acronyms)]
pub struct CSE {
auth: String,
formats: Arc<Vec<Format>>,
Expand Down
2 changes: 1 addition & 1 deletion ll-core/src/cse/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Result {
pub fn save(&self) -> error::Result<PathBuf> {
let save_dir = Path::new(&self.output_path);

if &self.files.len() > &0 {
if !self.files.is_empty() {
if !save_dir.exists() {
fs::create_dir_all(save_dir)?;
}
Expand Down
6 changes: 3 additions & 3 deletions ll-core/src/epw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ impl Epw {
};

for line in lines {
let line_parts: Vec<&str> = line.split("=").collect();
let line_parts: Vec<&str> = line.split('=').collect();

if line_parts.len() == 2 {
map.insert(line_parts[0], line_parts[1]);
}
}

Ok(Self {
id: id,
id,
mna: String::from(*map.get("mna").unwrap_or(&"")),
mpn: String::from(*map.get("mpn").unwrap_or(&"")),
pna: String::from(*map.get("pna").unwrap_or(&"")),
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Epw {
fn from_zip(raw_data: Vec<u8>) -> Result<Self> {
// The zip library crashes if the archive is empty,
// lets prevent that.
if raw_data.len() == 0 {
if raw_data.is_empty() {
return Err(Error::ZipArchiveEmpty);
}

Expand Down
10 changes: 5 additions & 5 deletions ll-core/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ impl Format {
pub fn extract(&self, files: &mut Files, file_path: String, item: &mut ZipFile) -> Result<()> {
match &self.ecad {
// * Keep these in alphabetical order
ECAD::D3 => extractors::d3::extract(&self, files, file_path, item)?,
ECAD::DesignSpark => extractors::designspark::extract(&self, files, file_path, item)?,
ECAD::Eagle => extractors::eagle::extract(&self, files, file_path, item)?,
ECAD::EasyEDA => extractors::easyeda::extract(&self, files, file_path, item)?,
ECAD::KiCad => extractors::kicad::extract(&self, files, file_path, item)?,
ECAD::D3 => extractors::d3::extract(self, files, file_path, item)?,
ECAD::DesignSpark => extractors::designspark::extract(self, files, file_path, item)?,
ECAD::Eagle => extractors::eagle::extract(self, files, file_path, item)?,
ECAD::EasyEDA => extractors::easyeda::extract(self, files, file_path, item)?,
ECAD::KiCad => extractors::kicad::extract(self, files, file_path, item)?,
ECAD::Zip => unreachable!("ZIP not handled!"),
// ! NOTE: DO NOT ADD A _ => {} CATCHER HERE!
};
Expand Down
3 changes: 3 additions & 0 deletions ll-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ mod updates;
mod utils;
mod watcher;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const GIT_DESCRIBE: &str = include_str!("../git.txt");

pub use {
config::{profile::Profile, Config, Format},
consts::LL_CONFIG,
Expand Down
17 changes: 9 additions & 8 deletions ll-core/src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,37 @@ pub trait Logger: Send + Sync {

#[macro_export]
macro_rules! log_trace {
($loggers:expr, $msg:expr) => {
($loggers:expr, $($arg:tt)*) => {
#[cfg(debug_assertions)]
for l in $loggers {
l.trace(format!("{}", $msg))
l.trace(format!($($arg)*))
}
};
}

#[macro_export]
macro_rules! log_info {
($loggers:expr, $msg:expr) => {
($loggers:expr, $($arg:tt)*) => {
for l in $loggers {
l.info(format!("{}", $msg))
l.info(format!($($arg)*))
}
};
}

#[macro_export]
macro_rules! log_warn {
($loggers:expr, $msg:expr) => {
($loggers:expr, $($arg:tt)*) => {
for l in $loggers {
l.warn(format!("{}", $msg))
l.warn(format!($($arg)*))
}
};
}

#[macro_export]
macro_rules! log_error {
($loggers:expr, $msg:expr) => {
($loggers:expr, $($arg:tt)*) => {
for l in $loggers {
l.error(format!("{}", $msg))
l.error(format!($($arg)*))
}
};
}
Expand Down
3 changes: 1 addition & 2 deletions ll-core/src/updates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
crate::{consts, error::Result},
reqwest,
serde::Deserialize,
};

Expand All @@ -24,7 +23,7 @@ pub struct UpdateInfo<'l, 'u> {
pub url: &'u str,
}

pub fn check<'l>(local_version: &'l str, kind: ClientKind) -> Result<Option<UpdateInfo>> {
pub fn check(local_version: &str, kind: ClientKind) -> Result<Option<UpdateInfo>> {
let url = format!(
"https://raw.githubusercontent.com/olback/library-loader/master/{kind}/Cargo.toml",
kind = kind
Expand Down
1 change: 1 addition & 0 deletions ll-core/src/watcher/event.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[derive(Debug)]
pub enum WatcherEvent {
NotifyResult(notify::Result<notify::Event>),
Stop,
Expand Down
Loading