Skip to content

Commit

Permalink
feat: read from git config instead of yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrutchf committed Nov 28, 2024
1 parent 35999e1 commit 46cd4e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ anyhow = "1.0.93"
app_dirs2 = "2.5.5"
clap = "4.5.21"
futures-macro = "0.3.31"
gitoxide = "0.39.0"
gix-config = "0.42.0"
keyring = { version = "3.6.1", features = ["apple-native", "windows-native", "sync-secret-service"] }
num-derive = "0.4.2"
num-traits = "0.2.19"
Expand All @@ -19,9 +19,9 @@ rpassword = "7.3.1"
rusqlite = { version = "0.32.1", features = ["bundled"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
serde_yml = "0.0.12"
thiserror = "2.0.3"
tokio = { version = "1.41.1", features = ["macros", "rt", "rt-multi-thread"] }
tracing = "0.1.40"
tracing-appender = "0.2.3"
tracing-subscriber = "0.3.18"
url = "2.5.4"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Development Dependencies
```bash
brew install cmake
```

## Setup a Repository

```bash
brew install git-lfs
```
32 changes: 28 additions & 4 deletions src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{fs::read_to_string, path::PathBuf};

use anyhow::Result;
use anyhow::{anyhow, bail, Context, Ok, Result};
use gix_config::File;
use serde::{Deserialize, Serialize};
use url::Url;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Configuration {
Expand All @@ -14,10 +16,32 @@ impl Configuration {
pub fn load() -> Result<Configuration> {
let mut path = PathBuf::new();
path.push("./");
path.push(".git-lfs-synology.yaml");
path.push(".lfsconfig");

let yaml_string = read_to_string(path)?;
let config = File::from_path_no_includes(path, gix_config::Source::Local)?;
let section = config.section("lfs", None)?;

Ok(serde_yml::from_str::<Configuration>(yaml_string.as_str())?)
let url = section.value("url").context("Url should be set.")?.to_string();
let url = if url.starts_with("filestation-secure://") {
Ok(url.replace("filestation-secure", "https"))
}
else if url.starts_with("filestation://") {
Ok(url.replace("filestation", "http"))
}
else {
Err(anyhow!("Url is not set incorrectly."))
}?;

let url_parsed = Url::parse(url.as_str())?;

let path = url_parsed.path();
let nas_url = url.replace(path, "");

Ok(
Configuration {
nas_url: nas_url.to_string(),
path: path.to_string()
}
)
}
}

0 comments on commit 46cd4e1

Please sign in to comment.