Skip to content

Commit

Permalink
Merge pull request #251 from xrelkd/release/0.16.1
Browse files Browse the repository at this point in the history
Release `0.16.1`
  • Loading branch information
xrelkd authored Jan 8, 2024
2 parents 7070fef + b60b68e commit 45e1d44
Show file tree
Hide file tree
Showing 21 changed files with 951 additions and 694 deletions.
468 changes: 291 additions & 177 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.16.0"
version = "0.16.1"
authors = ["xrelkd <46590321+xrelkd@users.noreply.github.com>"]
homepage = "https://github.com/xrelkd/clipcat"
repository = "https://github.com/xrelkd/clipcat"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ cd ~/bin

# download and extract clipcat to ~/bin/
# NOTE: replace the version with the version you want to install
export CLIPCAT_VERSION=v0.16.0
export CLIPCAT_VERSION=v0.16.1

# NOTE: the architecture of your machine,
# available value is `x86_64-unknown-linux-musl`
Expand Down
1 change: 1 addition & 0 deletions clipcat-menu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tokio = { version = "1", features = ["rt-multi-thread", "sync"] }
clap = { version = "4", features = ["derive", "env"] }
clap_complete = "4"
http = "1"
resolve-path = "0.1"
shadow-rs = "0.26"
skim = "0.10"
snafu = "0.8"
Expand Down
36 changes: 29 additions & 7 deletions clipcat-menu/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};

use resolve_path::PathResolveExt;
use serde::{Deserialize, Serialize};
use snafu::{ResultExt, Snafu};

Expand Down Expand Up @@ -43,13 +44,31 @@ impl Config {

#[inline]
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let data = std::fs::read_to_string(&path)
.context(OpenConfigSnafu { filename: path.as_ref().to_path_buf() })?;

let mut config: Self = toml::from_str(&data)
.context(ParseConfigSnafu { filename: path.as_ref().to_path_buf() })?;
let mut config: Self = {
let path =
path.as_ref().try_resolve().map(|path| path.to_path_buf()).with_context(|_| {
ResolveFilePathSnafu { file_path: path.as_ref().to_path_buf() }
})?;
let data = std::fs::read_to_string(&path)
.context(OpenConfigSnafu { filename: path.clone() })?;
toml::from_str(&data).context(ParseConfigSnafu { filename: path })?
};

config.log.file_path = match config.log.file_path.map(|path| {
path.try_resolve()
.map(|path| path.to_path_buf())
.with_context(|_| ResolveFilePathSnafu { file_path: path.clone() })
}) {
Some(Ok(path)) => Some(path),
Some(Err(err)) => return Err(err),
None => None,
};

if let Some(ref file_path) = config.access_token_file_path {
let file_path = file_path
.try_resolve()
.with_context(|_| ResolveFilePathSnafu { file_path: file_path.clone() })?;

if let Ok(token) = std::fs::read_to_string(file_path) {
config.access_token = Some(token.trim_end().to_string());
}
Expand Down Expand Up @@ -162,9 +181,12 @@ const fn default_line_length() -> usize { 100 }

#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Could not open config from {}: {source}", filename.display()))]
#[snafu(display("Could not open config from {}, error: {source}", filename.display()))]
OpenConfig { filename: PathBuf, source: std::io::Error },

#[snafu(display("Count not parse config from {}: {source}", filename.display()))]
#[snafu(display("Count not parse config from {}, error: {source}", filename.display()))]
ParseConfig { filename: PathBuf, source: toml::de::Error },

#[snafu(display("Could not resolve file path {}, error: {source}", file_path.display()))]
ResolveFilePath { file_path: PathBuf, source: std::io::Error },
}
1 change: 1 addition & 0 deletions clipcatctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ clap_complete = "4"
directories = "5"
http = "1"
mime = "0.3"
resolve-path = "0.1"
shadow-rs = "0.26"
simdutf8 = "0.1"
snafu = "0.8"
Expand Down
34 changes: 28 additions & 6 deletions clipcatctl/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};

use resolve_path::PathResolveExt;
use serde::{Deserialize, Serialize};
use snafu::{ResultExt, Snafu};

Expand Down Expand Up @@ -40,13 +41,31 @@ impl Config {

#[inline]
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let data = std::fs::read_to_string(&path)
.context(OpenConfigSnafu { filename: path.as_ref().to_path_buf() })?;
let mut config: Self = {
let path =
path.as_ref().try_resolve().map(|path| path.to_path_buf()).with_context(|_| {
ResolveFilePathSnafu { file_path: path.as_ref().to_path_buf() }
})?;
let data = std::fs::read_to_string(&path)
.context(OpenConfigSnafu { filename: path.clone() })?;
toml::from_str(&data).context(ParseConfigSnafu { filename: path })?
};

let mut config: Self = toml::from_str(&data)
.context(ParseConfigSnafu { filename: path.as_ref().to_path_buf() })?;
config.log.file_path = match config.log.file_path.map(|path| {
path.try_resolve()
.map(|path| path.to_path_buf())
.with_context(|_| ResolveFilePathSnafu { file_path: path.clone() })
}) {
Some(Ok(path)) => Some(path),
Some(Err(err)) => return Err(err),
None => None,
};

if let Some(ref file_path) = config.access_token_file_path {
let file_path = file_path
.try_resolve()
.with_context(|_| ResolveFilePathSnafu { file_path: file_path.clone() })?;

if let Ok(token) = std::fs::read_to_string(file_path) {
config.access_token = Some(token.trim_end().to_string());
}
Expand All @@ -63,9 +82,12 @@ impl Config {

#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Could not open config from {}: {source}", filename.display()))]
#[snafu(display("Could not open config from {}, error: {source}", filename.display()))]
OpenConfig { filename: PathBuf, source: std::io::Error },

#[snafu(display("Count not parse config from {}: {source}", filename.display()))]
#[snafu(display("Count not parse config from {}, error: {source}", filename.display()))]
ParseConfig { filename: PathBuf, source: toml::de::Error },

#[snafu(display("Could not resolve file path {}, error: {source}", file_path.display()))]
ResolveFilePath { file_path: PathBuf, source: std::io::Error },
}
1 change: 1 addition & 0 deletions clipcatd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exitcode = "1"
libc = "0.2"
linicon = "2"
mime = "0.3"
resolve-path = "0.1"
shadow-rs = "0.26"
simdutf8 = "0.1"
snafu = "0.8"
Expand Down
Loading

0 comments on commit 45e1d44

Please sign in to comment.