license=('MIT' 'custom')
url="https://github.com/moogoesmeow0/dibble"
+prepare() {
+ cd "$srcdir/$pkgname-$pkgver"
+ export RUSTUP_TOOLCHAIN=stable
+ cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
+}
+
+build() {
+ cd "$srcdir/$pkgname-$pkgver"
+ export RUSTUP_TOOLCHAIN=stable
+ export CARGO_TARGET_DIR=target
+ cargo build --frozen --release --all-features
+}
+
+package() {
+ cd "$srcdir/$pkgname-$pkgver"
+
+ install -Dm755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
+
+ # install dict files
+ install -dm755 "$pkgdir/usr/share/dibble/dict"
+ cp -r dict/* "$pkgdir/usr/share/dibble/dict/"
+
+}
fn read_data(path: PathBuf) -> Result<String> {
let dirs: ProjectDirs = ProjectDirs::from("com.taranathan.dibble", "taran", "dibble").unwrap();
- // let mut file = File::open(dirs.data_dir())?;
- // let mut contents = String::new();
- // file.read_to_string(&mut contents)?;
-
- let mut target = dirs.data_dir().to_path_buf();
- target.push(Path::new("dict"));
- target.push(path);
- target.set_extension("json");
- dbg!(&target);
+ let mut user_target = dirs.data_dir().to_path_buf();
+ user_target.push(Path::new("dict"));
+ user_target.push(&path);
+ user_target.set_extension("json");
+
+ let mut system_target = PathBuf::from("/usr/share/dibble/dict");
+ system_target.push(&path);
+ system_target.set_extension("json");
+
+ if let Ok(mut file) = File::open(&user_target) {
+ let mut contents = String::new();
+ file.read_to_string(&mut contents)?;
+ return Ok(contents);
+ }
- let mut file = File::open(target)?;
- let mut contents = String::new();
- file.read_to_string(&mut contents)?;
+ // system installation fallback
+ if let Ok(mut file) = File::open(&system_target) {
+ let mut contents = String::new();
+ file.read_to_string(&mut contents)?;
+ return Ok(contents);
+ }
- return Ok(contents);
+ // If both failed, return a helpful error
+ anyhow::bail!(
+ "Dictionary file not found. Searched:\n - {}\n - {}",
+ user_target.display(),
+ system_target.display()
+ )
}
pub type DictionaryFile = HashMap<String, Definition>;