Skip to content

Commit

Permalink
Allow user to specify JGRAB_HOME.
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoathaydes committed Apr 26, 2024
1 parent a4f5cc9 commit 3e2501f
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 11 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- name: Smoke Test
shell: bash
run: |
mkdir .jgrab
cp ./jgrab-runner/build/libs/jgrab.jar ./.jgrab/jgrab.jar
export JGRAB_HOME="$(pwd)/.jgrab"
mkdir $JGRAB_HOME
cp ./jgrab-runner/build/libs/jgrab.jar $JGRAB_HOME/jgrab.jar
ls -al $JGRAB_HOME
./jgrab-client/target/debug/jgrab-client -e "2 + 2"
203 changes: 201 additions & 2 deletions jgrab-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion jgrab-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ version = "0.6.0"
authors = [ "Renato Athaydes" ]

[dependencies]
dirs = "5.0.1"
wait-timeout = "0.1.5"

[profile.release]

lto = true
panic = 'abort'
panic = 'abort'
27 changes: 21 additions & 6 deletions jgrab-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use dirs::home_dir;
use std::env;
use std::fs::File;
use std::io::{stdin, stdout, Cursor, Error, Read, Result, Stdin, Write};
Expand All @@ -12,6 +13,7 @@ use std::time::Duration;
use wait_timeout::ChildExt;
use Input::*;

extern crate dirs;
extern crate wait_timeout;

const MAX_RETRIES: usize = 5;
Expand Down Expand Up @@ -213,15 +215,24 @@ fn send_message<R: Read>(reader: &mut R, is_retry: bool) -> Option<Error> {
}
}

fn find_jgrab_jar() -> PathBuf {
let jgrab_home = env::var("JGRAB_HOME");
let mut path: PathBuf = if let Ok(home) = jgrab_home {
home.into()
} else {
let mut path = home_dir()
.unwrap_or_else(|| env::current_dir().expect("must be able to access current dir!"));
path.push(".jgrab");
path
};
path.push("jgrab.jar");
path
}

fn start_daemon() -> Child {
log("Starting daemon");

let user_home = env::home_dir()
.unwrap_or_else(|| env::current_dir().expect("must be able to access current dir!"));
let mut jgrab_jar: PathBuf = user_home;
jgrab_jar.push(".jgrab");
jgrab_jar.push("jgrab.jar");

let jgrab_jar: PathBuf = find_jgrab_jar();
if jgrab_jar.as_path().is_file() {
let cmd = Command::new("java")
.arg("-jar")
Expand All @@ -237,6 +248,10 @@ fn start_daemon() -> Child {
Err(err) => error(&err.to_string()),
}
} else {
log(&format!(
"JGrab jar does not exist: {}",
jgrab_jar.as_path().display()
));
error(
"The JGrab jar is not installed! Please install it as explained \
in https://github.com/renatoathaydes/jgrab",
Expand Down

0 comments on commit 3e2501f

Please sign in to comment.